Hello SM Community,
In some scenarios it would be faster to use a single POST to update several records in SM via REST, this is however not yet possible on SM (ER open for this QCCR1E134475 REST API - Required JSON payload to update multiple records in single POST) and in order to use POST udpates we would need to modify manually the URL to point an specific resource ID.
On the meantime we enhace the REST API, we might need to use a custom JS to simulate this behavior or at least some code everyone can use as a base to start playing with the SM REST API - JS.
Find below an example code that will receive a list of IDs, the values to modify and the collection/resoruce names, at the moment the code will assume the resource has only one KEY field and we are only updating one value, however the code can be easily adjusted to accept more KEYS or Fields to update.
I used also two functions ( doRESTPostRequest and createBasicAuthHttpHeaders ) from the OOB SL smis_RestClient, however I did added them to my script because I had to adapt them to use Content-Type JSON (OOB it will use application/XML) and because for this post I guess is easier to have all the needed functions on a single file.
Attached is the SL UNL file with also an example where I am updating two contact's email address using the code. (NOTE: for REST URL creation, always remember to replace empty space characters with %2, so for example if the key field has empty spaces in between:
ACRE CORNER, ROB --> ACRE,ORNER,%2ROB
Once the Script is executed, you will get some prints with the ID that is being modified, the URL used, and the JSON payload:
Hope this helps, if so, don't forget to KUDO the post!