Search code examples
azureazure-logic-appsshopify-api

How to fix Inventory Item Id "expected float to be a id" issue in Shopify REST API call?


I'm fundamentally new to Shopify and working on an integration project using Azure Logic App.  One of the requirements is to set the available inventory quantity in Shopify using this API endpoint myShopify.com/admin/api/2023-04/inventory_levels/set.json.  I test the API endpoint using Postman and it perfectly works. 

The problem that I'm getting is in the Logic App, when I sent the request for the below input,

{
    "uri": "https://myShopify.com/admin/api/2023-01/inventory_levels/set.json",
    "method": "POST",
    "headers": {
        "Accept": "*/*",
        "Content-Type": "application/json",
        "X-Shopify-Access-Token": "xxxxxxxxxxxxxxxxx"
    },
    "body": {
        "available": 89,
        "inventory_item_id": 40978570519510,
        "location_id": 70811973482
    }
}

As you can see in the above payload, the body object has the inventory_item_id field with the value of 40978570519510 which is a double data type. The logic app output throws an error that says below

{
   "body": {
        "errors": {
            "inventory_item_id": "expected Float to be a id"
        }
   }
}

I don't really understand the problem.  I did googled it but could not find any similar issues encountered in Shopify. 

Has anyone encountered this before? any help is greatly appreciated.


Solution

  • I did find a way on how to solve the issue. The problem is not in the Azure Logic App but rather it's how I'm using the Shopify API Admin. According to this API documentation https://shopify.dev/docs/api/admin-graphql/2023-04/mutations/inventoryActivate, it activates an inventory item at a specified location using GraphQL mutation. This is where I missed the part, I should first activate the inventory item with an initially available quantity before setting the inventory level for an inventory item at a location. I think that's how Shopify wants to initially activate inventory levels at a location.

    I hope this will help someone who has the same issue.