Highlighted
Lieutenant
Lieutenant
151 views

Write SM Script to upload file to third party system using doHttpRequest method

Hi, can any expert here share with me how I can write the script in SM using doHttpRequest to upload file to third party system via their Rest API as shown in the attached jpg which I can do successfully using Postman?

The file to upload is specified in the post request body using form-data.  I'm not sure how to specify that in SM script.

Thanks in advance.

 

0 Likes
1 Reply
Highlighted
Commander Commander
Commander

Hi,

Here is what i did:
1) Add and attachemt to incident
2) Create a button on incident to POST attachment using script, something like this:

var attachmentArray = new Array();
var attachmentObj=system.vars.$L_file.getAttachments();
for(var attachment in attachmentObj) {
    if(attachmentObj[attachment].len>xxxxxxx) { /*check the attachmet size, if its oversized then quit
         return "file too big"
    } else {   
      attachmentArray.push({"name":attachmentObj[attachment].name,"data":base64Encode(attachmentObj[attachment].value)});
    }

...

var objCreate = {
                                 "attachments":attachmentArray
                                 }
/* POST */

 

Regards,
Ainer

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.