How to close an order

Highlighted
Tourist
4 0 1

Hello (new user)

I am trying to close an order using the REST API.

We have downloaded the orders from Shopify, picked, packed and shipped them in the Warehouse system.

We now need to close the order in Shopify (fulfilled) and update the order with the tracking number.

I submit the following POST (I am not sure if this is the correct way to do this)

POST /admin/api/2020-04/orders/2410203971689/fulfillments.json

With the following json

{
"fullfillment": {
  "location_id": 36970070121,
  "tracking_number": "TRACKINGNO1",
  "tracking_urls": "https://shipping.xyz/track.php?num=123456789"
  }
}

It returns this error:

Received error response code: 400
Response body:
{"errors":{"fulfillment":"Required parameter missing or invalid"}}

Any ideas will be greatly appreciated.

0 Likes
Highlighted
Shopify Partner
520 38 109

The tracking_urls needs to be passed as an array. See examples here --> https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillment?api[version]=.... Hope this helps!

0 Likes
Highlighted
Tourist
4 0 1
Hello



I took the URL segments out and just tried to set the tracking number.

{

"fullfillment": {

"location_id": 36970070121,

"tracking_number": "TRACKINGNO1"

}

}

I get the same error.
0 Likes
Highlighted
Shopify Partner
520 38 109

I tried this out and ran into the same outcome (see API request/response pair below). Not sure what's going on, since it should be pretty straightforward. You could take a look at the Shopify GraphiQL API, since it appears that you can create order fulfillments through there as well --> https://shopify.dev/docs/admin-api/graphql/reference/mutation/fulfillmentcreatev2?api[version]=2020-....

 

 

POST https://{shopify_store}.myshopify.com/admin/api/2020-04/orders/{order_id}/fulfillments.json HTTP/1.1
Content-Type: application/json
Authorization: Basic {auth_creds}
User-Agent: PostmanRuntime/7.25.0
Accept: */*
Host: {shopify_store}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 158

{
"fullfillment": {
  "location_id": {location_id},
  "tracking_number": "123456789",
  "tracking_urls": ["https://shipping.xyz/track.php?num=123456789"]
  }
}
HTTP/1.1 400 Bad Request
Date: Fri, 12 Jun 2020 13:22:26 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=df5104a767563b50779a684629b2ce53a1591968146; expires=Sun, 12-Jul-20 13:22:26 GMT; path=/; domain=.myshopify.com; HttpOnly; SameSite=Lax
X-Sorting-Hat-PodId: 161
X-Sorting-Hat-ShopId: 3036253
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 3036253
X-ShardId: 161
X-Stats-UserId: 
X-Stats-ApiClientId: 309925
X-Stats-ApiPermissionId: 8304915
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2020-04
Strict-Transport-Security: max-age=7889238
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://cdn.shopify.cn https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders%2Ffulfillments&source%5Bsection%5D=admin_api&source%5Buuid%5D=e3b5f7ae-cf78-4066-87f9-83e410cae98a
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Forders%2Ffulfillments&source%5Bsection%5D=admin_api&source%5Buuid%5D=e3b5f7ae-cf78-4066-87f9-83e410cae98a
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
X-Request-ID: e3b5f7ae-cf78-4066-87f9-83e410cae98a
CF-Cache-Status: DYNAMIC
cf-request-id: 034a4b3cd200000404d4aa0200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5a23e1748fdb0404-ORD
alt-svc: h3-27=":443"; ma=86400
Content-Length: 66

{"errors":{"fulfillment":"Required parameter missing or invalid"}}
0 Likes
Highlighted
Tourist
4 0 1
Hello



I only have access to REST API tools.

Is there any other way to close an order using the REST API?
0 Likes
Highlighted
Shopify Partner
520 38 109

I'd search the board, since there are other cases of people having issues with this specific REST API endpoint. :) 

 

https://community.shopify.com/c/forums/searchpage/tab/message?advanced=false&allow_punctuation=false...

 

If anyone from Shopify is reading this, my latest failed attempt has an X-Request-ID of 73b12ccd-2dbf-4c78-802e-99deafc47dc3. Looking at similar posts, I can verify I'm passing along the body as Content-Type: application/json. I can pull up other API endpoint requests along my Postman tabs and they all work fine. Similar headers being sent in my requests. Just this one particular API request consistently fails...

0 Likes
Highlighted
Shopify Partner
520 38 109

I was able to finally get this to work. Couldn't figure it out via the REST API, which likely has dated/incorrect documentation. But I used the GraphiQL API and was able to mark orders as fulfilled that way. Here is a code snippet below. I defined Content-Type as application/json in the header and passed the content body as shown. Had to define the order, the order line item(s), and the fulfillment location. After getting back the HTTP 200 successful response, I looked in the admin web UI and saw the order was indeed flagged as fulfilled.

 

Hope this helps anyone else who runs into this challenge.

 

POST https://{my_shop}.myshopify.com/admin/api/2020-04/graphql.json HTTP/1.1
Content-Type: application/json
X-Shopify-Access-Token: {my_access_token}
User-Agent: PostmanRuntime/7.25.0
Accept: */*
Host: {my_shop}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 442

{"query":"mutation createFulfillment($input: FulfillmentInput!) {  fulfillmentCreate(input: $input) {    fulfillment {      id      status    }    userErrors {      field      message    }  }}","variables":{
  "input": {
    "orderId": "gid://shopify/Order/1897838149684",
    "locationId": "gid://shopify/Location/203128",
    "lineItems": {
      "id": "gid://shopify/LineItem/4204617924660",
      "quantity": 1      
    }
  }
}}
HTTP/1.1 200 OK
Date: Mon, 15 Jun 2020 16:59:25 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=d38e5cb7e3bcd7eba275d9399241e07011592240364; expires=Wed, 15-Jul-20 16:59:24 GMT; path=/; domain=.myshopify.com; HttpOnly; SameSite=Lax
X-Sorting-Hat-PodId: 161
X-Sorting-Hat-ShopId: 3036253
Vary: Accept-Encoding
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 3036253
X-ShardId: 161
X-Stats-UserId: 
X-Stats-ApiClientId: 309925
X-Stats-ApiPermissionId: 8304915
X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
X-Shopify-API-Version: 2020-04
Content-Language: en
X-Shopify-API-Deprecated-Reason: https://help.shopify.com/api/getting-started/api-deprecations
Strict-Transport-Security: max-age=7889238
X-Shopify-Stage: production
Content-Security-Policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://cdn.shopify.cn https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=query&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fgraphql&source%5Bsection%5D=admin_api&source%5Buuid%5D=6ae7e237-84fc-450c-b180-e670db10f921
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block; report=/xss-report?source%5Baction%5D=query&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fgraphql&source%5Bsection%5D=admin_api&source%5Buuid%5D=6ae7e237-84fc-450c-b180-e670db10f921
X-Dc: gcp-us-central1,gcp-us-east1,gcp-us-east1
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
X-Request-ID: 6ae7e237-84fc-450c-b180-e670db10f921
NEL: {"report_to":"network-errors","max_age":2592000,"failure_fraction":0.01,"success_fraction":0.0001}
Report-To: {"group":"network-errors","max_age":2592000,"endpoints":[{"url":"https://monorail-edge.shopifycloud.com/v1/reports/nel/20190325/shopify"}]}
CF-Cache-Status: DYNAMIC
cf-request-id: 035a84f50d0000553215819200000001
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 5a3dd76819c25532-ORD
alt-svc: h3-27=":443"; ma=86400
Content-Length: 292

{"data":{"fulfillmentCreate":{"fulfillment":{"id":"gid:\/\/shopify\/Fulfillment\/2396477194402","status":"SUCCESS"},"userErrors":[]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}}}
1 Like
Highlighted
Tourist
4 0 1
Hello

It was an embarrassing error.

I had spelled fulfillment wrong (was using fullfillment)

The following works

{

"fulfillment": {

"location_id": 37145280617,

"tracking_number": "1082396000051779",

"tracking_company": "Canada Post Expedited Parcel"

}

}
1 Like
Highlighted
Shopify Partner
520 38 109

LOL, I just copied and pasted your JSON into my attempts and didn't notice that either. At least now we know both the REST API and GraphiQL API work equally as well along these lines. 

1 Like
Highlighted
Shopify Partner
2294 116 352

This is common enough it really should be an alias, or did you mean feedback message.

Or the local dev tooling really needs to catch it.

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes