Discussing APIs and development related to customers, discounts, and order management.
Hi there,
I am using Osiset's github for laravel + shopify: https://github.com/osiset/laravel-shopify
But I don't seem the get the POST request going, tried all kinds of variantions already hope one of you'll see my mistake!
Code:
$order_array = [
'order' => [
'email' => "foo@example.com",
'line_items' => [
'variant_id' => 6103067132088,
'quantity' => 1
]
]
];
$order_array = json_encode($order_array);
$shop = User::first();
$request = $shop->api()->rest('POST', '/admin/orders.json', ['body' => $order_array]);
dd($request['body']);
if I do a dd() on order_array after the encode it shows:
{"order":{"email":"foo@example.com","line_items":{"variant_id":6103067132088,"quantity":1}}}
And then it returns
array:1 [
"order" => "Required parameter missing or invalid"
]
I've also tried to make 'body' to 'query'...
I fixed it I had to replace
$request = $shop->api()->rest('POST', '/admin/orders.json', ['body' => $order_array]);
with
$request = $shop->api()->request('POST', '/admin/orders.json', $order_array);
And I had to add one more pair of [] inside the line items!
'line_items' => [
['variant_id' => 6103067132088, 'name' => 'blabla', 'title' => 'blabla', 'quantity' => 1, 'price' => 1]
]
But now I am trying to add shipping & billing address but it doens't seem to work, everything else is doing fine but the shipping address nor the billing address are showing up while there is no error from the request..
Request array:
$order_array = [
'order' => [
'billing_address' => [
'first_name' => $order->customerDetails->shipmentDetails->firstName, 'last_name' => $order->customerDetails->shipmentDetails->surName, 'address1' => $customer_adress, 'city' => $order->customerDetails->shipmentDetails->city, 'zip' => $order->customerDetails->shipmentDetails->zipCode
],
'shipping_address' => [
'first_name' => $order->customerDetails->shipmentDetails->firstName, 'last_name' => $order->customerDetails->shipmentDetails->surName, 'address1' => $customer_adress, 'city' => $order->customerDetails->shipmentDetails->city, 'zip' => $order->customerDetails->shipmentDetails->zipCode
],
'email' => $order->customerDetails->shipmentDetails->email,
'financial_status' => 'paid',
'customer' => [
'first_name' => $order->customerDetails->billingDetails->firstName, 'last_name' => $order->customerDetails->billingDetails->surName, 'email' => $order->customerDetails->billingDetails->email
],
'line_items' => [
['variant_id' => 6103067132088, 'name' => 'blabla', 'title' => 'blabla', 'quantity' => 1, 'price' => 1]
]
]
];