Good day, thanks for passing by.
The initial setup was to pass an order id and mark it as fulfilled, it worked, but then I was asked to create different fulfillments in case some items were delivered later, so leaving the chance to mark them as partial fulfillments was a new need.
Overview on the initial setup.
1 A. In my app, first I get the fulfillment order ID through the API posting the order id here:
/admin/api/2023-07/orders/{order_id}/fulfillment_orders.json
I parsed the response array and got that data from fulfillment_orders->id
2 A. Then, I was able to mark orders as fulfilled, posting the fulfillment_order_id, a tracking number identifier and a tracking url, here:
/admin/api/2023-07/fulfillments.json
The current approach that is not working.
1 B. Did step 1 A.
2 B. Then I didn’t found a way to split the fulfillment using an API endpoint, but only through GraphQL.
Using:
/admin/api/2023-07/graphql.json
Passing the following mutation and variables:
mutation fulfillmentOrderSplit($fulfillmentOrderSplits: [FulfillmentOrderSplitInput!]!) {
fulfillmentOrderSplit(fulfillmentOrderSplits: $fulfillmentOrderSplits) {
fulfillmentOrderSplits {
fulfillmentOrder{
id
status
},
remainingFulfillmentOrder{
id
status
}
replacementFulfillmentOrder{
id
status
}
}
userErrors {
field
message
}
}
}
{"fulfillmentOrderSplits":{
"fulfillmentOrderId":"gid://shopify/FulfillmentOrder/{related_fulfillmentOrder_id}",
"fulfillmentOrderLineItems":{
"id":"gid://shopify/LineItem/{related_item_lineItem_id}",
"quantity":1
}
}}
The int value for fulfillmentOrderId was obtained through the step 1 A, the int value for fulfillmentOrderLineItems->id was obtained through the step 1 A (or 1 B if you want), but parsing differently the response array, by:
a) storing an array of the available line items that were present in the step 1 A response
b) putting it into a loop
and c) storing the line item id whenever the variant id provided to the app, was equal to the value stored in the array for the variant id of the line item.
These values were double checked with the following query:
query get_fulfillment_orders_with_order_id{
node(id: "gid://shopify/Order/{order_id}") {
id
... on Order {
fulfillmentOrders(first:10) {
edges {
node {
id
}
}
}
lineItems(first: 10){
edges{
node{
id
product{
id
title
}
variant{
id
title
}
}
}
}
}
}
}
The results were OK:
{
"data": {
"node": {
"id": "gid://shopify/Order/**{related_order_id}**",
"fulfillmentOrders": {
"edges": [
{
"node": {
"id": "gid://shopify/FulfillmentOrder/{related_fulfillmentOrder_id}"
}
}
]
},
"lineItems": {
"edges": [
{
"node": {
"id": "gid://shopify/LineItem/{related_item_lineItem_id}",
"product": {
"id": "gid://shopify/Product/{related_item_product_id}",
"title": "{related_item_product_title}"
},
"variant": {
"id": "gid://shopify/ProductVariant/{related_item_variant_id}",
"title": "{related_item_variant_title}"
}
}
},
{
"node": {
"id": "gid://shopify/LineItem/{unrelated_item_lineItem_id}",
"product": {
"id": "gid://shopify/Product/{unrelated_item_product_id}",
"title": "{unrelated_item_product_title}"
},
"variant": {
"id": "gid://shopify/ProductVariant/{unrelated_item_variant_id}",
"title": "{unrelated_item_variant_title}"
}
}
}
]
}
}
},
"extensions": {
"cost": {
"requestedQueryCost": 45,
"actualQueryCost": 12,
"throttleStatus": {
"maximumAvailable": 2000,
"currentlyAvailable": 1988,
"restoreRate": 100
}
}
}
}
But when executing step 2B, this was the response:
"data": {
"fulfillmentOrderSplit": null
},
"errors": [
{
"message": "invalid id",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"fulfillmentOrderSplit"
]
}
],
"extensions": {
"cost": {
"requestedQueryCost": 13,
"actualQueryCost": 1,
"throttleStatus": {
"maximumAvailable": 2000,
"currentlyAvailable": 1982,
"restoreRate": 100
}
}
}
}
Could you please give me some hints of what I did wrong?