Issue while creating an item adjustment in Zoho inventory through API's

149 Views Asked by At

Here is the require fields of Create the Inventory Adjustment through Zoho API:

{
    "date": "2023-08-02",
    "reason": "my reason",
    "description": "Testing",
    "adjustment_type": "quantity",
    "line_items": [{
        "item_id": 2954987000000641651,     // This id is coming from Zoho
        "quantity_adjusted": -1
    }]
}

When I try to hit this API from Postman it is working good and have this message from zoho:

"code": 0,
"message": "Inventory Adjustment has been added",
"inventory_adjustment": {
  // other details
}

PROBLEM:

Now let's come to the my server when I try to "Create Inventory Adjustment" from my Express server. I have problem to pass item_id.

API require an bool data type for item_id but in JavaScript when I try to pass this ID: 2954987000000641651 it has 19 digits and JavaScript integer only support 15 digits. So it's convert every ID with like this 2954987000000641500 and I have this response from Zoho:

{
  code: 103003,
  message: 'Non-inventory items(s) are involved in this transaction.'
}

This is because When I try to adjust a specific item ID, it changes the id into different number that js maximum support. And that item is not exist in my zoho account. Like:

Expected:

{
    "date": "2023-08-02",
    "reason": "my reason",
    "description": "Testing",
    "adjustment_type": "quantity",
    "line_items": [{
        "item_id": 2954987000000641651,     // This id is coming from Zoho
        "quantity_adjusted": -1
    }]
}

What actually happening:

{
    "date": "2023-08-02",
    "reason": "my reason",
    "description": "Testing",
    "adjustment_type": "quantity",
    "line_items": [{
        "item_id": 2954987000000641500,     // This id is coming from Zoho
        "quantity_adjusted": -1
    }]
}

I also tried to use BigInt(2954987000000641651) but my server gives me error:

TypeError: Do not know how to serialize a BigInt
at JSON.stringify(<anonymous>)....

How can I solve this problem?

1

There are 1 best solutions below

0
Zubair Javed On

I contact the Zoho team. They suggest me this way:

{
  "line_items": [
    {
      "item_id": "item_id",
      "quantity_adjusted": "-1",
      "adjustment_account_id": "adjustment_account_id",
      "warehouse_id": "warehouse_id",
      "serial_numbers": [
        "serial_number"
      ]
    }
  ],
  "date": "2022-02-17",
  "reason": "reason",
  "adjustment_type": "quantity"
}

Pass all the values in string, like

let reqData = 
{
    date: new Date().toISOString().slice(0, 10),
    reason: "Parts For Rental",
    description: "Testing...",
    adjustment_type: "quantity",
    line_items: [{
        item_id: `${Item.item_id}`,
        quantity_adjusted: `-${part.Quantity}`
    }]
}

When all values are in the format of string then no worries about the integer limit in js.