Encountering a problem when attempting to generate an item adjustment in Zoho Inventory using API's

Below are the mandatory fields required to create an Inventory Adjustment via Zoho API:

  • API being used:
  • Token in Headers
  • Method: POST
  • Body:
{
    "date": "2023-08-02",
    "reason": "my reason",
    "description": "Testing",
    "adjustment_type": "quantity",
    "line_items": [{
        "item_id": 2954987000000641651,     // ID from Zoho
        "quantity_adjusted": -1
    }]
}

When calling this API through Postman, it works fine with the following response from Zoho:

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

ISSUE:

The problem arises when attempting to "Create Inventory Adjustment" from the Express server. There is a challenge in passing the item_id.

The API requires a Boolean data type for item_id, but due to JavaScript limitations, the provided ID: 2954987000000641651 which has 19 digits gets converted to a number that JavaScript can support (15 digits), resulting in a different ID like 2954987000000641500. This triggers an error response from Zoho:

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

This discrepancy occurs because specific item IDs get altered to fit within JavaScript's maximum supported value, causing non-existent IDs in the Zoho account.

Expected Behavior:

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

Actual Outcome:

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

An attempt was made using BigInt(2954987000000641651), but it resulted in a server error:

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

How can this issue be resolved?

Answer №1

I reached out to the Zoho team for assistance and they provided me with the following solution:

{
  "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"
}

They advised me to pass all values as strings, like so:

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}`
    }]
}

By ensuring that all values are in string format, there is no need to worry about integer limits in JavaScript.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

RegEx in JavaScript to identify and match the innerHTML property of all elements

I am currently in the process of developing a Chrome extension that needs to identify specific pages within a website, including the Log In / Sign In page, the Sign Up / Register page, the About page, and the Contact Us page. My approach involves obtainin ...

Failed to locate files in Express.js

Currently, I am running an express server: // Here we are setting up Dependencies var connect = require('connect') , express = require('express') , port = (process.env.PORT || 8081); // Database Setup removed for brevity var ...

Vue: Opening all GmapInfoWindows simultaneously upon clicking one

I am working on a platform where users can report crimes or incidents by placing markers on a map. These markers with all the reported incidents are then displayed on another map. Each marker has an info window that provides details about the incident and ...

"Encountering an undefined value in an Angular service method

Encountering a problem while trying to call the service app.module.ts providers: [ AppInitService, { provide: APP_INITIALIZER, useFactory: () => initializeApp, deps: [AppInitService], multi: true } ] app.initialize ...

Tips for sending two values to a PHP file using JavaScript Ajax

I have created a code for two dropdown menus. The goal is to select values from both menus and send them to a php file using the GET method. The values should be sent to the php file only when both menus have selections made. Below is the code snippet: ...

Securing a Single Page Application with its own dedicated API to prevent Cross-Site Request Forgery

In order to protect my application from XSRF attacks, I have two separate node servers. One server is dedicated to serving the frontend of my single-page app developed in React, while the other one functions as my backend API. After consulting the guidel ...

What's the best way to establish a victorious player in a game of Tic

I've been struggling to find a solution for determining the winner using WinCombos. Is there a way to compare the elements in my winCombos array with the cells of a 3x3 tic tac toe board to identify the winner? var player1 = "X"; var player2 = "O"; ...

When using server-side rendering in React with AJAX, an error may occur if trying to call setState

In order to display data to the user, I rely on the response from the AJAX request as I store all necessary information in the database. My component GenericPage.jsx: export default class GenericPage extends React.Component { componentWillMount() { ...

Certain hyperlinks are refusing to open within an embedded iframe

I'm currently facing an issue with finding a solution for a simple problem. I am in the process of developing a portfolio plugin and one of the requirements is to showcase projects within an iframe to demonstrate their responsive layout. However, I&ap ...

Can a JavaScript function be used with images to operate across multiple elements?

How can I make a function work on multiple elements? let image = document.getElementById("opacityLink"); image.onmouseover = function() { image.style = "opacity:0.9"; }; image.onmouseout = function() { image.style = "opacity:1"; }; <div class=" ...

Animating jQuery Counter with Changing Background Color

I've implemented a Counter that counts from 0 to a specified number, and it seems to be working perfectly. However, I want to add an animation where the background color of a div height animates upwards corresponding to the percentage of the counter. ...

Exploring the optimal method for file and memory requirements in a Node.js server powered by Express

It's always a good practice to declare your variables at the top for convenience and readability: But I'm curious about how JavaScript handles requiring files. Is everything loaded at declaration or is it loaded at execution time? Is there a sig ...

NextJS: When attempting to serialize the `function` as JSON, an error occurs as it is not a JSON serializable data type

In my Firestore database, I have a collection named "mentor" that contains documents with three fields: "name", "email", and "linkedin". My goal is to fetch all the documents from this collection and pass them as props so that I can render their fields on ...

Highlighting table column when input is selected

I am working with a table where each <td> contains an <input>. My goal is to apply the class .highlighted to all the column <td>s when an <input> is being focused on. Additionally, I want to remove this class from all other columns ...

How to use node.js to download a file and send it to another API using http

I am currently facing an issue where I am attempting to save file data from an http.request response to the file system. Whenever I call the function, a file is created on my desktop but it only contains the text: [Object object]. My question is how can I ...

When using Material-UI's <Table/> component, an error is thrown stating that the element type is invalid

Struggling with material-ui Table is not familiar territory for me, especially since I have used it in numerous projects before. Currently, I am utilizing @material-ui/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="33505c41567 ...

Converting a table into div elements and subsequently reverting it back to its original table format

[STOP DOWNVOTING: NEW AND IMPROVED] Discovering a simple technique on stackoverflow to transform tables into divs has been quite enlightening. By assigning classes to each tag, such as: <table class="table"> the process of converting from table to ...

Using isClient in Gridsome: What You Need to Know

While working with the FirebaseUI and Gridsome plugin, I encountered an error message stating ReferenceError: window is not defined. This issue arises from server-side rendering (SSR) as FirebaseUI attempts to access the browser-specific window object. Af ...

Tips for resolving the issue of infinite re-render with react-hook-form?

Struggling to build a basic form in React with react-hook-form library. Implemented various validations and features in the form. However, encountering the following console error. Error message on console: Warning: Maximum update depth exceeded. This can ...

Creating a design for an application using Node.js and MongoDB

As I develop a webapp using node.js and mongoose, I find myself with a query regarding the creation of the database structure. The current database definition looks like this: var user = new Schema({ id : ObjectId, name : String, password : String, em ...