VMware Cloud Community
pizzle85
Expert
Expert
Jump to solution

execute REST operation against custom REST API

I'm attempting to integrate ticket creation in our ticketing system in vRO. Our applicaitons team has provided me with a bit of documentation about the API calls and a CURL example using JSON. I can execute this find through a CURL and through postman but cant get it working through vRO. The CURL command:

curl --data 'api_key=<key>&ticketdata={"Source":"Phone","Portfolio":"Administrative Services","Service":"Business Applications","Category":"Category","Subcategory":"Report an Incident","Priority": 5,"Summary":"Request","LastModifiedByEmail":"servicedesk@mail.com","Description": "ticket_description","CustomersID":"52448400","AssignedSupportLevel":"Tier 1 Support","OwnedByTeam":"Help Desk Administrative"}' https:/<host>/myitapi/ticketcreate

works fine.

I can't get this to work from vRO and am really not sure where to look to figure it out.

Does anyone have any idea how i would format this when using a REST host in vRO to execute the request. The content type is application/x-www-form-urlencoded if that matters...

1 Solution

Accepted Solutions
pizzle85
Expert
Expert
Jump to solution

it appears that with the application/x-www-form-urlencoded content type vRO doesnt escape any of the characters. Submitting the form data in raw html worked. i used postman to build the form then get the HTML data to use, this is what i ended up with:


api_key=KEY&ticketdata=%7B%22Source%22%3A%22Phone%22%2C%22Portfolio%22%3A%22Administrative+Services%22%2C%22Service%22%3A%22Business+Applications%22%2C%22Category%22%3A%22Category%22%2C%22Subcategory%22%3A%22Report+an+Incident%22%2C%22Priority%22%3A+5%2C%22Summary%22%3A%22Request%22%2C%22LastModifiedByEmail%22%3A%22servicedesk%40mail.com%22%2C%22Description%22%3A+%22ticket_description%22%2C%22CustomersID%22%3A%2252448400%22%2C%22AssignedSupportLevel%22%3A%22Tier+1+Support%22%2C%22OwnedByTeam%22%3A%22Help+Desk+Administrative%22%7D

View solution in original post

Reply
0 Kudos
6 Replies
pizzle85
Expert
Expert
Jump to solution

it appears that with the application/x-www-form-urlencoded content type vRO doesnt escape any of the characters. Submitting the form data in raw html worked. i used postman to build the form then get the HTML data to use, this is what i ended up with:


api_key=KEY&ticketdata=%7B%22Source%22%3A%22Phone%22%2C%22Portfolio%22%3A%22Administrative+Services%22%2C%22Service%22%3A%22Business+Applications%22%2C%22Category%22%3A%22Category%22%2C%22Subcategory%22%3A%22Report+an+Incident%22%2C%22Priority%22%3A+5%2C%22Summary%22%3A%22Request%22%2C%22LastModifiedByEmail%22%3A%22servicedesk%40mail.com%22%2C%22Description%22%3A+%22ticket_description%22%2C%22CustomersID%22%3A%2252448400%22%2C%22AssignedSupportLevel%22%3A%22Tier+1+Support%22%2C%22OwnedByTeam%22%3A%22Help+Desk+Administrative%22%7D

Reply
0 Kudos
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

You should be able to add a REST host and an REST operation. On the REST operation you already set the content type if it is a PUT or POST operation.

To build a JSON as REST operation content, there are two simple ways:

1. Write your JSON content as string:

var content = '{Source:' + mySource;

content += ',Portfolio:' + myPortfolio;

content += ',Service:' + myService; // and so on and so on ...

content += '}';

2. Create a object and convert it to JSON:

var json = new Object();

json.Source = mySource;

json.Portfolio = myPortfolio;

json.Service = myService; // and so on and so on ...

var content = JSON.stringify(json);

Cheers,

Chris

Reply
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Encoding a URI in Orchestrator is fortunately quite simple:

Assuming your input text variable name is inText of type string:

var encodedURI = encodeURI(inText);

System.debug("Source Text: "+inText);

System.debug("Encoded URI: "+encodedURI);

Generates the following output in the Logs tab of the Orchestrator Workflow when provided with your input string:

[2015-05-29 09:19:00.956] [D] Source Text: api_key=KEY&ticketdata={"Source":"Phone","Portfolio":"Administrative Services","Service":"Business Applications","Category":"Category","Subcategory":"Report an Incident","Priority": 5,"Summary":"Request","LastModifiedByEmail":"servicedesk@mail.com","Description": "ticket_description","CustomersID":"52448400","AssignedSupportLevel":"Tier 1 Support","OwnedByTeam":"Help Desk Administrative"}

[2015-05-29 09:19:00.956] [D] Encoded URI: api_key=KEY&ticketdata=%7B%22Source%22:%22Phone%22,%22Portfolio%22:%22Administrative%20Services%22,%22Service%22:%22Business%20Applications%22,%22Category%22:%22Category%22,%22Subcategory%22:%22Report%20an%20Incident%22,%22Priority%22:%205,%22Summary%22:%22Request%22,%22LastModifiedByEmail%22:%22servicedesk@mail.com%22,%22Description%22:%20%22ticket_description%22,%22CustomersID%22:%2252448400%22,%22AssignedSupportLevel%22:%22Tier%201%20Support%22,%22OwnedByTeam%22:%22Help%20Desk%20Administrative%22%7D

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
pizzle85
Expert
Expert
Jump to solution

awesome! that will make life much easier! thanks for the response.

pizzle85
Expert
Expert
Jump to solution

I finally got around to trying out the encodeURI method you suggested. Unfortunately it does not encode the colons...

Reply
0 Kudos
pizzle85
Expert
Expert
Jump to solution

incase anyone is interested ive attached the action im using to URL encode the body of my request. In my particular case i required the following that the encodeURI method did not provide:

  • encode spaces within values as + (key:value pair)
  • encode & with %26
  • encode @ with %40
  • encode : with %3A
  • encode , with %2C

This may be unique to my use case, and im sure there are other characters that are missing form my action that others may require