Open mathieu-coingt opened 1 year ago
Hey Mathieu, I am on the same page as you are Are you sure this is deprecated? The reason I ask this is because of the below suggestion I got from the Shopify community https://community.shopify.com/c/payments-shipping-and/using-fulfillment-orders-api-instead-of-fulfilment-api/m-p/1852743#M67304 The suggested solution was this "You can use the POST /admin/api/2022-01/orders/#{id}/fulfillments.json endpoint to update the fulfillment status of an order"
$shopify->Order($orderID)->Fulfillment->post uses the below POST link https://XXXXXXX/admin/api/2021-01/orders/11111111/fulfillments.json Which is the solution they are suggesting. Please do correct me if I am wrong!
I've been using the code below. It took me a while to get the permissions right on the API user, it needed all of the permissions for managing tracking including third party tracking and also reading/writing orders.
If you you need to get the fulfillment ID from the order and then use the fulfillment id to update the tracking info.
$shopify->Fulfillment($fulfillment['id'])->update_tracking([
"tracking_number" => 'XXXXXXX'
"tracking_urls" => 'https://tracking_url...',
"notify_customer" => true,
"location_id" => 'location_id,
]);
@tonytoms this is deprecated since Shopify API 2022-07. It's respond with a 404 error.
Hey Mathieu, I am on the same page as you are Are you sure this is deprecated? The reason I ask this is because of the below suggestion I got from the Shopify community https://community.shopify.com/c/payments-shipping-and/using-fulfillment-orders-api-instead-of-fulfilment-api/m-p/1852743#M67304 The suggested solution was this "You can use the POST /admin/api/2022-01/orders/#{id}/fulfillments.json endpoint to update the fulfillment status of an order"
$shopify->Order($orderID)->Fulfillment->post uses the below POST link https://XXXXXXX/admin/api/2021-01/orders/11111111/fulfillments.json Which is the solution they are suggesting. Please do correct me if I am wrong!
Thank you @d3v1 this is probably the solution. Since my message I tried with the official Shopify SDK, and it's the way to do.
I've been using the code below. It took me a while to get the permissions right on the API user, it needed all of the permissions for managing tracking including third party tracking and also reading/writing orders.
If you you need to get the fulfillment ID from the order and then use the fulfillment id to update the tracking info.
$shopify->Fulfillment($fulfillment['id'])->update_tracking([ "tracking_number" => 'XXXXXXX' "tracking_urls" => 'https://tracking_url...', "notify_customer" => true, "location_id" => 'location_id, ]);
@d3v1 Where did you get the Fulfilment ID from? Did you get it from the 'GET fulfillment_orders endpoint?'. If yes , could you give me an example if possible
Hey @tonytoms
I got the fulfillment ID from the order. In this case we're using the Fulfillment
object. It's different to the FulfillmentOrder
object. I believe the FulfillmentOrder
object will replace the Fulfillment
object in a future release, I couldn't see any FulfillmentOrder
s on our transactions.
Here's an example bit of code you can start with:
$config = array(
'ShopUrl' => 'your-shop-name-here.myshopify.com',
'AccessToken' => YOUR_API_KEY_GOES_HERE,
'ApiVersion' => '2022-10',
);
PHPShopify\ShopifySDK::config($config);
$shopify = new PHPShopify\ShopifySDK;
// get the order
$order = $shopify->Order($theOrderIdHere)->get();
$fulfillments = $order['fulfillments'];
foreach ($fulfillments as $fulfillment) {
// fulfillment id is below, we don't need to assing it to a variable, I thought it'd help make it clearer
$fulfillmentId = $fulfillment['id'];
// build your payload here
$payload = [
'fulfillment' => [
'notify_customer' => true, // you may want to make this false if you're correcting a tracking issue
"tracking_info" => [
'number' => 'NEW_TRACKING_NUMBER_HERE',
'company' => 'SHIPPING_COMPANY_HERE',
'url' => 'https://the-full-tracking-url-here.com/with/path?and=THE_QUERY_STRING'
]
]
];
// submit it to shopify
$result = $shopify->Fulfillment($fulfillmentId)->update_tracking($payload);
// the result is the new fulfillment data in case you want to store it somewhere or check the update worked
// print_r($result);
}
Hey @tonytoms
I got the fulfillment ID from the order. In this case we're using the
Fulfillment
object. It's different to theFulfillmentOrder
object. I believe theFulfillmentOrder
object will replace theFulfillment
object in a future release, I couldn't see anyFulfillmentOrder
s on our transactions.Here's an example bit of code you can start with:
$config = array( 'ShopUrl' => 'your-shop-name-here.myshopify.com', 'AccessToken' => YOUR_API_KEY_GOES_HERE, 'ApiVersion' => '2022-10', ); PHPShopify\ShopifySDK::config($config); $shopify = new PHPShopify\ShopifySDK; // get the order $order = $shopify->Order($theOrderIdHere)->get(); $fulfillments = $order['fulfillments']; foreach ($fulfillments as $fulfillment) { // fulfillment id is below, we don't need to assing it to a variable, I thought it'd help make it clearer $fulfillmentId = $fulfillment['id']; // build your payload here $payload = [ 'fulfillment' => [ 'notify_customer' => true, // you may want to make this false if you're correcting a tracking issue "tracking_info" => [ 'number' => 'NEW_TRACKING_NUMBER_HERE', 'company' => 'SHIPPING_COMPANY_HERE', 'url' => 'https://the-full-tracking-url-here.com/with/path?and=THE_QUERY_STRING' ] ] ]; // submit it to shopify $result = $shopify->Fulfillment($fulfillmentId)->update_tracking($payload); // the result is the new fulfillment data in case you want to store it somewhere or check the update worked // print_r($result); }
Perfection. Thank you so much. Appreciate it
So the solution is to use the Shopify PHP SDK ? No updates on this package ?
I echo @t-prod question as the FulfillmentOrder API is important for order fulfillment in later versions of the Shopify REST API. There is a lot of new functionality too for applying, retrieving and releasing fulfillment holds
@williamoconnorme I think we should use the Shopify PHP SDK now for this feature I don't believe there's a planified development for this feature cause the deadline is in April.
Please check the latest release
What do you do if you don't have any fulfillment_id's tied to the order. When I query an order for fulfillments, I receive an empty array. Clearly I need to create a fulfillment but I can't find any documentation on this that doesn't include the newer FulfillmentOrder API. Could someone point me in the right direction for creating the request?
What do you do if you don't have any fulfillment_id's tied to the order. When I query an order for fulfillments, I receive an empty array. Clearly I need to create a fulfillment but I can't find any documentation on this that doesn't include the newer FulfillmentOrder API. Could someone point me in the right direction for creating the request?
I am facing the same issue. From the official website I can see that we need to grand some permissions to the app. I haven't tried it but I hope that's why the array is null. There is also a clause that says Fulfillment orders are created automatically when an order is created. Let me know if anyone else think the issue is because of that? I will try it in a few days time anyways. You can see the permissions in the below migration document .
I had the same problem, I needed to add the additional scopes and then the array wasn't empty. If you don't have the correct scopes, it doesn't throw any error, it just returns empty
I have the additional scopes set and I still get an empty array, unless the order has already shipped.
I have the additional scopes set and I still get an empty array unless the order has already shipped.
I just tried the same and am also getting no fulfillments inside the object of the order. The endpoint I am using is https://myshopify.com/admin/api/2023-01/orders.json?fulfillment_status=unfulfilled However, I am getting the fulfilment order IDs when calling the Fulfillment get api separately . @end2endi , try it and I think you will get the values.
https://myshopify.com/admin/api/2023-01/orders/4779611111/fulfillment_orders.json
Does anyone have any luck in getting the fulfillment orders by calling the order.json endpoint like below?
$order = $shopify->Order($theOrderIdHere)->get();
$fulfillments = $order['fulfillments']
As was stated by Ismail Patel - if you don't have the right access scopes defined, you can't see fulfillment orders, but you just get a blank array rather than an error message!
I was trying to read / write merchant managed fulfillment orders but didn't have these scopes enabled so was getting a blank array as others have:
write_merchant_managed_fulfillment_orders, read_merchant_managed_fulfillment_orders
Once I enabled them I could get the fulfillment orders correctly using the following curl:
curl -X GET "https://{my_store}}. myshopify.com/admin/api/2023-01/orders/{order_id}/fulfillment_orders.json" -H "X-Shopify-Access-Token:{my_access_token}"
Tony, note also that in your code you're using the endpoint "2022-01" in your 2nd request for fulfillment orders. Can't remember if fulfillment orders were implemented back in that version, anyhow it works with "2023-01"...
Having got the request working with curl, it also then worked with the library:
$order_id="1234567890";
$shop=new PHPShopify\ShopifySDK($store_config);
$fo=$shop->Order($order_id)->FulfillmentOrder()->get();
print_r($fo);
I hope that helps someone!
Tim
On Thu, Feb 23, 2023 at 1:15 AM Tony Toms @.***> wrote:
I have the additional scopes set and I still get an empty array unless the order has already shipped.
I just tried the same and am also getting no fulfillments inside the object of the order. The endpoint I am using is
https://myshopify.com/admin/api/2023-01/orders.json?fulfillment_status=unfulfilled However, I am getting the fulfilment order IDs when calling the Fulfillment get api separately . @end2endi https://github.com/end2endi , try it and I think you will get the values.
https://myshopify.com/admin/api/2022-01/orders/4779611111/fulfillment_orders.json
Does anyone have any luck in getting the fulfillment orders by calling the order.json endpoint?
— Reply to this email directly, view it on GitHub https://github.com/phpclassic/php-shopify/issues/283#issuecomment-1441101059, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACERLZ4VCOZRGQ4HAQDO3NDWY222NANCNFSM6AAAAAAS64E6KU . You are receiving this because you are subscribed to this thread.Message ID: @.***>
I implemented the function of shipping orders on the 2023-04 version. The sample code is as follows:
static function create_order_fulfillment_new($order_id, $notify_customer, $tracking_number, $tracking_company) {
$config = array(
'ShopUrl' => self::MYSHOPIFY_DOMAIN,
'ApiKey' => self::API_KEY,
'Password' => self::PASSWORD,
'ApiVersion' => '2023-04',
// The following must be added, refer to https://github.com/phpclassic/php-shopify/issues/187
'AccessToken' => self::PASSWORD,
'Curl' => array(
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_TIMEOUT => 10,
)
);
$sp= new PHPShopify\ShopifySDK($config);
// Only get the FulfillmentOrder when declare the shipping order.
$list = $sp->Order($order_id)->FulfillmentOrder()->get();
$fulfillmentorder_id = $list[0]['id'];
$params = array(
'notify_customer'=> $notify_customer,
'tracking_info' => [
'number' => $tracking_number,
'company' => $tracking_company
],
'line_items_by_fulfillment_order' => [
array('fulfillment_order_id' => $fulfillmentorder_id)
]
);
$ret = $sp->Fulfillment()->post($params);
print_r($ret);
}
If you find some bug, please point it out, thanks
I implemented the function of shipping orders on the 2023-04 version. The sample code is as follows:
static function create_order_fulfillment_new($order_id, $notify_customer, $tracking_number, $tracking_company) { $config = array( 'ShopUrl' => self::MYSHOPIFY_DOMAIN, 'ApiKey' => self::API_KEY, 'Password' => self::PASSWORD, 'ApiVersion' => '2023-04', // The following must be added, refer to https://github.com/phpclassic/php-shopify/issues/187 'AccessToken' => self::PASSWORD, 'Curl' => array( CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 10, ) ); $sp= new PHPShopify\ShopifySDK($config); // Only get the FulfillmentOrder when declare the shipping order. $list = $sp->Order($order_id)->FulfillmentOrder()->get(); $fulfillmentorder_id = $list[0]['id']; $params = array( 'notify_customer'=> $notify_customer, 'tracking_info' => [ 'number' => $tracking_number, 'company' => $tracking_company ], 'line_items_by_fulfillment_order' => [ array('fulfillment_order_id' => $fulfillmentorder_id) ] ); $ret = $sp->Fulfillment()->post($params); print_r($ret); }
If you find some bug, please point it out, thanks
I googled or referred to many other online methods, but none of them succeeded, or I felt that it was not easy to use. Finally, directly refer to the official https://shopify.dev/docs/api/admin-rest/2023-04/resources/fulfillment#post-fulfillments, and then construct the corresponding parameters. Of course, thanks to the SDK library php-shopify.
With Shopify API 2022-01, I fulfilled my orders with these instructions :
With Shopify API 2022-07 and above, this is deprecated as it's mentioned in others issues, but even with the doc and some samples, I'm not able to convert this code to be compliant with the new fulfillment API.
Is someone could provide me an exemple ?
Thank you.