Hi folks. I'm using server-side suitescript to ge...
# suitescript
e
Hi folks. I'm using server-side suitescript to get item data from an external API and then create the items in Netsuite. Is there some recommended approach to throttle the API requests when creating multiple items? I am making one request per item in a loop.
e
Are you concerned about API requests on external API or NetSuite? On the NetSuite side, you're likely going to run into script governance limits first if you're creating hundreds of items. If you think it might scale up to that many, you should consider a Map/Reduce job instead.
e
Understood on the script governance on the Netsuite side. My question was for requests to an external API. There is general javascript info online about writing your own sleep function which I did not have success with. I thought I'd ask the question here to learn if there is a Netsuite-preferred approach.
w
If you know how many calls you are permitted in a given period you can have your script stop when the limit is reached. On the deployment you can set the schedule to re-run once your api limit resets.
If you dont know, you can have your script stop when the limit is reached. The next scheduled run can then make one attempt, and know if it's limit is reached. How frequently you want to re-try is up to you but limited to the every 15 min schedule limit (There are ways to push the retry to be shorter but they are very hacky).
e
Limited to three calls per second. I don't think restarting the script would be practical. The actual scenario is creating an invoice, which means creating the associated customer and line items. Each of these (invoice, customer, one or more items) is a request to a remote API. At the minimum, I think it would be more logical to keep everything in-process per invoice. Hence the need to introduce some throttling between requests. One gain I can make is to combine the item requests into a single request (same endpoint). It would nice to still have some explicit throttling in place rather than rely on luck. Preferably this throttling should not impact governance allocation excessively. Appreciate the comments so far.