Highlighted
Absent Member.. Absent Member..
Absent Member..
481 views

(SM) Support Tip: REST JSON payload(s) to update multiple records using JavaScript

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 POSTand 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.

image1.jpg

 

   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.

 Image2.jpg

 

Again, this an example code where you can take some ideas from or at least understand how it works via JavaScript.

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%2CORNER,%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:

image3.jpg

Hope this helps, if so, don't forget to KUDO the post! 

Regards, 

Labels (1)
1 Reply
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Re: (SM) Support Tip: REST JSON payload(s) to update multipl

Hello Enrique.

Maybe you can help me.

I'm doing an integration of HSPM with another system using REST.

I can open the ticket in the other system but the parameters are not being sent.
I tried to pass the parameters directly through the url, but the function of the HTTPRequest returns error.
I'm doing now via json, but even the parameters are not being passed to the other system too.
The following script is attached. If someone has an example of how to do it.

Thank you so much.

Regards,

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.