Dear Support,
Is there any API command to remove SKU name from Inventory?
After deleting a specific variant successfully using API command, the SKU name under that deleted variant still shows in the inventory. We can remove it from shopify webpage manually. We are looking the way to remove that orphan SKU using API call.
Could you please help us to let know how to do that?
Thank you,
Kamal Hossain
Hey @khossain , there is for sure a way to update an Inventory Item’s SKU using a PUT request in REST via the Inventory API. In the body of the request, you can just leave the “SKU” field blank like this:
{“inventory_item”:{“id”:your-inventory-item-ID,“sku”:“”}}
Let me know if I’m understanding you correctly - hope this helps!
Thank you very much for your reply. Yes, you understood me correctly that I am looking for.
I am following the below steps, could you please correct me:
Step-1: Get inventory Item ID by GraphQL:
I executed below command and getting inventory item id
end point: /admin/api/2022-04/graphql.json
Query:
{
productVariants(first: 1, query: “sku:KPHN2000000013Y5200000100”) {
edges {
node {
id
sku
legacyResourceId
displayName
inventoryItem {
id
legacyResourceId
}
}
}
}
}
Step-2:
Using Inventory item id from Step-1, I am going to send a PUT request following your code example. Could you please correct me Is that below Endpoint looks correct that I am trying?
End point for PUT request: /admin/api/2022-04/inventory-items/{inventory_item_id}.json
Thank you,
Kamal
In GraphQL, it would be a POST request to the /admin/api/2023-01/graphql.json endpoint for both queries and mutations.
The workflow would be:
- Query
inventoryItems with a sku filter to find the variant ID:
{
inventoryItems(first:1, query:"sku:YOUR_SKU_HERE") {
nodes {
id
sku
variant {
id # we need this for the mutation in step 2
sku
}
}
}
}
- Use the
productVariantUpdate mutation to update the sku at the variant level, which will extend to the inventoryItem.sku field:
mutation ($input: ProductVariantInput!) {
productVariantUpdate(input: $input) {
productVariant {
id
sku
inventoryItem {
id
sku
}
}
}
}
With variables:
{
"input": {
"id": "gid://shopify/ProductVariant/1234",
"sku": null
}
}
Hope that helps!
Dear Support,
It worked for me !
I used GraphQL to get Inventory item ID and used PUT API command to clear the SKU
GraphQL for Inventory item id:
lv_sku_name := '\"sku:'||p_sku_name||'\"';
lv_payload := '{"query": "{inventoryItems(query:'||lv_sku_name||',first: 1) {edges {node {id legacyResourceId sku}}}}"}';
lv_end_point := /admin/api/2022-04/graphql.json
PUT Api command to clear SKU:
lv_end_point := '/admin/api/'||gv_api_version||'/inventory_items/'||lv_inv_item_id||'.json';
lv_payload :='{"inventory_item":{"id":'||lv_inv_item_id||',"sku":""}}';
Thank you for your help and quick support
Kind Regards,
Kamal