Hello!
I've encountered an issue while integrating NetSuite and Smartsheet via API. The script works inconsistently and occasionally creates duplicate rows in the Smartsheet table.
Current Script Logic:
- A record is created in NetSuite, triggering the script.
- The script collects data about the parent row.
- A request is sent to add a row to the table via the API method
.../sheets/{sheetId}/rows
. - The script waits for a response with the ID of the created row.
- If no ID is received (error or empty response body):
- A 2-minute wait period is initiated.
- The API search method
.../search?query=
is called to find the row by its content. - If the row is found (status code 200), its ID is retrieved, and the script continues.
- If the row is not found, another attempt is made to add it using
.../sheets/{sheetId}/rows
.
- This process repeats up to 5 times before the script terminates.
Issue:
The error SSS_REQUEST_TIME_EXCEEDED
(request timeout exceeded) occurs in NetSuite. However, the key problem is:
- When adding the parent field, a timeout error sometimes occurs.
- A search request using
.../search?query=
returns a 200 status code. However, the row does not actually exist in the table! Even after waiting for 2 minutes. - When attempting to add the row again, it successfully gets added. As a result, duplicate rows appear in the table.
Example: I attempt to add a row with the value “IT3775”, encounter a timeout error, wait 2 minutes and search for “IT3775”, get a status code of 200 (although the row is still not there), then try to add the row again and end up with duplicates.
Below I've provided the script execution logs from NetSuite (some fields are hidden as a security measure), as well as screenshot from the SmartSheet table so that you can see the problem clearly.
line 2347 - First attempt to add a parent line. (An error was occurred in the script, but eventually this field appears in the SmartSheet table).
line 2348 - Second attempt to add a parent line (successful).
line 2349 - Child fields.
P.S.I will provide the script code if needed.
Questions:
- Why does the .../search?query= method return status code 200 if the row is not in the table yet? (Why don't they return 204 or 404, for example?).
- How can this situation be handled properly to avoid duplicate rows?
- Could this issue be caused by a delay in data processing on Smartsheet’s side?
I’d appreciate any ideas or experiences in solving similar issues!
Thank you!