shopify fulfillment not working with rest api

180 views Asked by At

I am trying to fulfilment by line items with shopify API but it is not working this is my demo store

I have add all the thing original demo store name and access key

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://bforbay.myshopify.com/admin/api/2023-10/fulfillments.json',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "fulfillment": {
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": 5749831630946, // this one is order id
                "fulfillment_order_line_items": [
                    {
                        "id": 13418123853922, // one iteam id 
                        "quantity": 1 
                    }
                ]
            }
        ],
        "tracking_info": {
            "number": "AWEADSF898",
            "url": "https://www.my-shipping-company.com?tracking_number=MS1562678"
        }
    }
}',
  CURLOPT_HTTPHEADER => array(
    'X-Shopify-Access-Token: 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',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

I am geting error {"errors":"Not Found"} why?

I have read_fulfillments,write_fulfillments scope also

I try to get the fulfillment id also

get: https://bforbay.myshopify.com/admin/api/2023-04/orders/5749831630946/fulfillment_orders.json

header: X-Shopify-Access-Token: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

but get this

{
    "fulfillment_orders": []
}
2

There are 2 answers

1
TSCAmerica.com On

To create fulfillments, the URL usually follows this format: https://{store-name}.myshopify.com/admin/api/2023-10/orders/{order_id}/fulfillments.json. It seems like you're missing the orders/{order_id} part in your URL. Try this

$curl = curl_init();
$order_id = '5749831630946'; // Actual order ID

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://bforbay.myshopify.com/admin/api/2023-10/orders/' . $order_id . '/fulfillments.json',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "fulfillment": {
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": 5749831630946, // Actual fulfillment order ID
                "fulfillment_order_line_items": [
                    {
                        "id": 13418123853922, // Actual item ID
                        "quantity": 1 
                    }
                ]
            }
        ],
        "tracking_info": {
            "number": "AWEADSF898",
            "url": "https://www.my-shipping-company.com?tracking_number=MS1562678"
        }
    }
}',
  CURLOPT_HTTPHEADER => array(
    'X-Shopify-Access-Token: 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',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;
0
Mohd Baquir Qureshi On

You can use shopify Graphql APIs too for fulfilling the orders:

{
  nodes(ids: ["gid://Order/4534534534"]) 
  {
    ... on Order {
      id
      fulfillmentOrders(first: 1, query:"status:OPEN"){
        edges{
          node{
            id
          }
        }
      }    
    }
  }
}

Find the fulfillment order ID from the above query and then run the below mutation for fulfilling the order.

mutation MyMutation {
  fulfillmentCreateV2(
    fulfillment: {lineItemsByFulfillmentOrder: {fulfillmentOrderId: ""}, trackingInfo: {url: ""}}
  ) {
    fulfillment {
      name
    }
  }
}