We had some difficulty with the authorization as the examples/docs on shipstation site aren’t quite clear. Finally got it to work! I’m posting this working example api call to create an order on shipstation api in case it helps other devs in the future. Replace YOUR_API_KEY and YOUR_API_SECRET with yours.
<?php
// Set the API endpoint URL
$url = "https://ssapi.shipstation.com/orders/createorder";
// Set the API key and secret
$api_key = "YOUR_API_KEY";
$api_secret = "YOUR_API_SECRET";
// Set the order details
$order_data = array(
"orderNumber" => "12345",
"orderDate" => "2022-05-01T10:00:00",
"orderStatus" => "awaiting_shipment",
"shippingAmount" => 5.99,
"taxAmount" => 1.23,
"orderTotal" => 25.99,
"customerUsername" => "johndoe",
"customerEmail" => "johndoe@example.com",
"billTo" => array(
"name" => "John Doe",
"company" => "Acme Inc.",
"street1" => "123 Main St.",
"street2" => "Suite 100",
"city" => "Austin",
"state" => "TX",
"postalCode" => "78701",
"country" => "US",
"phone" => "555-123-4567"
),
"shipTo" => array(
"name" => "Jane Doe",
"company" => "Acme Inc.",
"street1" => "456 Elm St.",
"city" => "Austin",
"state" => "TX",
"postalCode" => "78701",
"country" => "US",
"phone" => "555-987-6543"
),
"items" => array(
array(
"sku" => "SKU123",
"name" => "Product 1",
"quantity" => 2,
"unitPrice" => 10.99,
"warehouseLocation" => "A1"
),
array(
"sku" => "SKU456",
"name" => "Product 2",
"quantity" => 1,
"unitPrice" => 3.99,
"warehouseLocation" => "B2"
)
)
);
// Convert the order data to JSON
$order_json = json_encode($order_data);
// Create a cURL handle
$ch = curl_init();
// Set the cURL options
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $order_json,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Basic " . base64_encode($api_key . ":" . $api_secret)
)
));
// Execute the cURL request
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
echo $response;
}
// Close the cURL handle
curl_close($ch);
?>