I'm attempting to POST through a REST API that has a content type of form-data from vRO. Does anyone have any idea how i need to format the body of the request in vRO? At this point im just building a JSON object then stringifying the object and sending it off.
{key1:value1,key2:value2}
var body = new Object();
body.api_key = apiKey;
body.AssignedSupportLevel = assignedSupportLevel;
body.Category = category;
body.CustomersUFID = customersUFID;
body.Description = description;
body.LastModifiedByEmail = lastModifiedByEmail;
body.OwnedByTeam = ownedByTeam;
body.Portfolio = portfolio;
body.Priority = priority;
body.Service = service;
body.Source = source;
body.Subcategory = subcategory;
body.Summary = summary;
var request = restHost.createRequest("POST", "/myitapi/v1/tickets", JSON.stringify(body));
request.contentType = "multipart/form-data";
return request.execute();
Thanks for the reply Ilian. I was able to format the request body as specified in the RFCs as shown below. I also wrote an action to do the formatting for me which i attached. Hopefully this will help someone else out.
var body = "--WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"api_key\"\r\n\r\n" +
apiKey + "\r\n" +
"--WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"AssignedSupportLevel\"\r\n\r\n" +
assignedSupportLevel + "\r\n" +
"--WebKitFormBoundary7MA4YWxkTrZu0gW--"
The action has two expectations as described in the description.
Read the following RFC https://www.ietf.org/rfc/rfc1867.txt , in particular section 3.3 (use of multipart/form-data) and 6 (Examples).
So to properly format the request body you should know the structure of the form you want to POST to. Consult the documentation of your REST API.
Thanks for the reply Ilian. I was able to format the request body as specified in the RFCs as shown below. I also wrote an action to do the formatting for me which i attached. Hopefully this will help someone else out.
var body = "--WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"api_key\"\r\n\r\n" +
apiKey + "\r\n" +
"--WebKitFormBoundary7MA4YWxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"AssignedSupportLevel\"\r\n\r\n" +
assignedSupportLevel + "\r\n" +
"--WebKitFormBoundary7MA4YWxkTrZu0gW--"
The action has two expectations as described in the description.