为什么更新库存失败,线上也是有这个商品的?

这是我们的请求:
Url:https://[REDACTED]myshopify.com/admin/api/2024-10/graphql.json, headers:[X-Shopify-Access-Token: shpat_33[REDACTED], Content-Type: application/json, url: https://[REDACTED].myshopify.com/admin/api/2024-10/graphql.json, method: POST], entity:{“query”:“mutation InventorySet($input: InventorySetQuantitiesInput!) { inventorySetQuantities(input: $input) { inventoryAdjustmentGroup { createdAt reason referenceDocumentUri changes { name delta } } userErrors { field message } } }”,“variables”:{“input”:{“ignoreCompareQuantity”:true,“name”:“available”,“quantities”:{“inventoryItemId”:“gid://shopify/InventoryItem/46955318214856”,“locationId”:“gid://shopify/Location/70629654728”,“quantity”:2},“reason”:“correction”}}}
更新库存返回的是:
{\“data\”:{\“inventorySetQuantities\”:{\“inventoryAdjustmentGroup\”:null,\“userErrors\”:[{\“field\”:[\“input\”,\“quantities\”,\“0\”,\“inventoryItemId\”],\“message\”:\“The specified inventory item could not be found.\”}]}},\“extensions\”:{\“cost\”:{\“requestedQueryCost\”:11,\“actualQueryCost\”:10,\“throttleStatus\”:{\“maximumAvailable\”:4000.0,\“currentlyAvailable\”:3990,\“restoreRate\”:200.0}}}}

Hey @Alex_Zhu ! Quick heads up first - I’ve redacted your shop URL and access token from your post. Access tokens should be treated like passwords and never shared publicly. I’d recommend rotating that token in your app settings just to be safe.

The error “The specified inventory item could not be found” can be a bit misleading at times - it often means the inventory item isn’t connected to that location yet, not that the item doesn’t exist. Before you can set quantities with inventorySetQuantities, the inventory item needs to be activated at the location using the inventoryActivate mutation.

You can check where the item is currently stocked by querying the inventory item’s inventoryLevels:

query {
  inventoryItem(id: "gid://shopify/InventoryItem/46955318214856") {
    id
    inventoryLevels(first: 10) {
      edges {
        node {
          location {
            id
            name
          }
          quantities(names: ["available", "on_hand"]) {
            name
            quantity
          }
        }
      }
    }
  }
}

If your location isn’t in that list, activate it first:

mutation {
  inventoryActivate(
    inventoryItemId: "gid://shopify/InventoryItem/46955318214856"
    locationId: "gid://shopify/Location/70629654728"
    available: 2
  ) {
    inventoryLevel {
      id
      quantities(names: ["available"]) {
        name
        quantity
      }
    }
    userErrors {
      field
      message
    }
  }
}

One other thing - you’re using API version 2024-10 which is outdated. The current stable version is 2025-10. Worth updating to avoid any deprecated behavior. See the API versioning docs for the release schedule.

If you’re still seeing the error after activating the item at that location, please share the corresponding x-request-id (can be found in response headers) for a failed inventorySet mutation and I’ll be able to see the details in our logs without you having to share sensitive info in your post :slight_smile: