Hi,
How do we achieve the functionality of fulfillment_service field that is available on /variant REST admin APIs in GraphQL? In REST API we could just provide the fulfillment service handle and REST API would magically add it?
I created a simple fulfillment service in my dev store and it appears in the locations drop down on variants. And when I try to run the mutation inventoryActivate using the variant’s inventory item id and the fulfillment service’s location id, I get the below error -
The product couldn’t be stocked at <fulfillment_service_handle> because the inventory is managed by <fulfillment_service_handle>.
Hi Prabhuling,
I believe you’ll need to use the fulfillmentServiceCreate mutation which should automatically create a location associated with the fulfillment service.
Once the fulfillment service is created, you can use the inventoryActivate mutation to activate an inventory item at the location associated with the fulfillment service. This is similar to setting the fulfillment service handle in the REST API.
Try out this flow and let us know if it works for your use case.
Hi,
The fulfillment-service is already created from the UI : Settings → Shipping and delivery → Custom order fulfillment → Add fulfillment service. E.g, ‘test_fulfillment’
With REST api, I can just send this ‘test_fulfillment’ in the variant payload and ‘test_fulfillment’ is reflected in the Inventory Drop Down on the variant (similar to just selecting ‘test_fulfillment’ from the drop down on UI)
Want to be able to do the same using GraphQL on the already created fulfillment service.
PS: Creating fulfillment service from UI also creates seems to create a location (seen in API response, but not on UI)
We are having this same issue.
We can activate inventory, but we can not set the fulfillment location as the active location (which was done in rest by setting the fulfillmentServiceId).
The GraphQL documentation doesn’t seem to address how to do this, other than “activating” the location, which only links the location, but does not set it as active.
I am trying the following steps in order to mimic the fulfillment_service field functionality.
- For the fulfillment_service name given, find the location using locations query (with includeLegacy = true) : check if the location is a Fulfillment Service and compare the fulfillment service handle with the fulfillment_service name to match.
- Activate Inventory for the variant’s inventory item by using inventoryActivate mutation (stockAtLegacyLocation needs to be set to true. And this is available from 2024-10 version only)
Here is the locations query used -
{
locations(first: N, includeLegacy: true) {
nodes {
fulfillmentService {
id
handle
}
id
isFulfillmentService
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
}
}
}
I am not sure if this is the right way. But on Shopify UI at least, I can see location changed to fulfillment_service.
It would be great if someone can corroborate this, and highlight if I missed something.
Hi,
I’m not sure if you resolved this issue - we found the cause was that the mutation provided in the API example code excluded the stockAtLegacyLocation variable. Even if this was provided in the variable set, it was not being utilized due that variable not existing in the mutation query. The correct query would be:
mutation ActivateInventoryItem($inventoryItemId: ID!, $locationId: ID!, $available: Int, $stockAtLegacyLocation: Boolean) {
inventoryActivate(inventoryItemId: $inventoryItemId, locationId: $locationId, available: $available, stockAtLegacyLocation: $stockAtLegacyLocation) {
inventoryLevel {
id
quantities(names: [“available”]) {
name
quantity
}
item {
id
}
location {
id
activatable
}
}
userErrors {
field
message
}
}
}
1 Like
Right. This is essentially what I mentioned in my earlier message. And that stockAtLegacyLocation is available only from 2024-10. I can see location change to a fulfillment service location on the Shopify Admin dashboard.
And, in order to read fulfillment_service for a productvariant I rely on the first inventoryLevels under inventoryItem for a productvariant using the below query. Is this correct? Since from my limited experience I couldn’t associate any other location to a variant if it is associated with a fulfillment service.
query ProductVariant {
productVariant(id: “gid://shopify/ProductVariant/1234567”) {
inventoryItem {
measurement {
weight {
unit
value
}
}
inventoryLevels(first: 1) {
nodes {
location {
fulfillmentService {
handle
}
}
}
}
id
}
product {
id
legacyResourceId
}
}
}
That is our approach also. In our case, we sample the first five items in inventoryLevel (in the event that there are multiple locations stocking the product) and then match based on the id. This seems reliable from our testing so far.
How would a GraphQL response for the above query look like for a variant if its REST response has fulfillment_service field value as ‘test_fulfillment’.
As far as I understand, it will have only one node in inventoryLevel and fulfillmentService.handle value will be ‘test_fulfillment’
Would there be any deviation in this expectation?
I tested this concept, and despite having multiple locations with inventory, only the active location was being returned.
Theres a really helpful guide on creating a fulfillment service here, including all the graphql calls Build for fulfillment services