1

I recently got a new job. They need me to get information from ShipStation through the API using PHP. I'm fairly new to PHP and even newer to ShipStation. I copied the code from the API documentation and attempted to add the code for authorization. This is what I've got:

<?php

    $apiKey = "my_api_key";
    $apiSecret = "my_api_secret";

    $auth = base64_encode($apiKey . ":" . $apiSecret);

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "https://ssapi.shipstation.com/orders");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: Basic " . $auth
    ));

    $response = curl_exec($ch);
    curl_close($ch);

    var_dump($response);
?>

Instead of giving me order information it's just returning bool(false).

I guess I'm just not seeing what I'm doing wrong. Any help would be greatly appreciated. Thanks!

HoggDogg
  • 11
  • 2

2 Answers2

1

This is coming up in searches for the query "Shipstation API PHP" so I wanted to point to this answer How do I make a request using HTTP basic authentication with PHP curl? and reiterate that it's a basic auth so you just need to do

curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":" . $apiSecret);

I'd also recommend sending it over a secure connection to avoid man in the middle reading your API credentials.

Milo LaMar
  • 2,146
  • 2
  • 14
  • 25
0

I connect with CURL this way:

    $url = 'https://ssapi.shipstation.com/orders';
    $ShpStnAuth = 'Authorization: basic '.base64_encode('key:pair');

    $curl = curl_init();
    curl_setopt_array(
            $curl, array(
                CURLOPT_URL => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'GET',
                CURLOPT_HTTPHEADER => array(
                'Host: ssapi.shipstation.com',
                $this->ShpStnAuth,
            ),
        )
    );
    $response = curl_exec($curl);
    curl_close($curl);
    print_r($response);
James Valeii
  • 472
  • 1
  • 4
  • 14