Creating Multiple Orders
austenc opened this issue · 5 comments
Hey there, firstly, thanks for making this, it's been very useful to me so far!
I have been trying to get the "Create / Update Multiple Orders" endpoint working and can't seem to figure it out... I'm close... but apparently something is still formatted incorrectly? I was hoping you might have an idea of what else I could try, or show me an example of using that endpoint correctly?
Here's a snippet of what I was trying:
// An array to keep our orders to be sent
$toSend = [];
foreach ($orders as $o) {
// Build items array
$items = [];
foreach ($o->items as $item) {
$i = new OrderItem();
$i->lineItemKey = $item->id;
$i->name = $item->title;
$i->quantity = $item->quantity;
$i->sku = $item->sku;
$items[] = $i;
}
// Shipping Address
$shipTo = new Address();
$shipTo->name = $o->ship_name;
$shipTo->company = $o->ship_company;
$shipTo->street1 = $o->ship_street;
$shipTo->street2 = $o->ship_street2;
$shipTo->city = $o->ship_city;
$shipTo->state = $o->ship_statecode;
$shipTo->postalCode = $o->ship_zip;
$shipTo->country = $o->ship_countrycode;
$shipTo->phone = $o->ship_phone;
// Billing Address
$billTo = new Address();
$billTo->name = $o->bill_name;
$billTo->company = $o->bill_company;
$billTo->street1 = $o->bill_street;
$billTo->street2 = $o->bill_street2;
$billTo->city = $o->bill_city;
$billTo->state = $o->bill_statecode;
$billTo->postalCode = $o->bill_zip;
$billTo->country = $o->bill_countrycode;
$billTo->phone = $o->bill_phone;
$new = new Order();
$new->orderNumber = $o->orderId;
$new->orderDate = $o->order_date;
$new->orderStatus = 'awaiting_shipment';
$new->billTo = $billTo;
$new->shipTo = $shipTo;
$new->items = $items;
$toSend[] = $new;
}
$response = $this->ss->orders->post($toSend, 'createorders');
dd($response);
I've verified that if I use the single (createorder
) endpoint, it works fine. Here's the error I'm getting when I use the multiple order endpoint with the above code:
[GuzzleHttp\Exception\ServerException]
Server error: `POST https://ssapi.shipstation.com/orders/createorders` resulted in a `500 Internal Server Error` response:
{"Message":"An error has occurred.","ExceptionMessage":"orders are required","ExceptionType":"System.ArgumentException", (truncated...)
The orders are required
error is what I get no matter how I try to format the main array, so thanks in advance if you have any ideas as to what to try!
No problem @austenc also - make sure you specify the unitPrice property for the OrderItem model (as it's required by ShipStation).
@joecampo I face the exact same issues. I see it is resolved but, couldn't find the solution could you help me on this.
Thanks a Bunch
MHK
Hey MHK - Are you use the latest version 3.1.1?
Hey joe,
Thanks a ton , I could resolve the issue