JSON Request in query parameters

harishdasari
Tera Guru

Hi,

How to pass this JSON request in query parameters of REST API

"comment":   { "body": "The smoke is very colorful." },

find_real_file.png

Thank you.

1 ACCEPTED SOLUTION

Hi Harish,



http://wiki.servicenow.com/index.php?title=RESTMessageV2_API#setRequestBody.28String_body.29



You can use setRequestBody method for setting this "request body"



eg,



setRequestBody(JSON.stringify(myObj));


View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Harish,



it seems this request you want to send in the body of the request. you could use content body for POST or PUT method.


What is the exact requirement?



You can give query parameters in the GET method.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,



Thanks for responding, Yes I am passing the below JSON request in content of REST API,



{


  "ticket": {


      "subject":   "New Ticket is created!",


      "comment":   { "body": "Urgent incident needs to be fixed ASAP" },


      "priority": "urgent"


  }


}




Now I needs to put this in business rule for sending tickets to outbound.


How can I put this in Business rule as this is in JSON format. JSON Request starts with ticket and next its fields.


"comments" : {"BODY" : XXXXX }     will change dynamically based on what user fill in short description.


can you please help me how to put this in business rule



Thank you.


Hi Harish,



I believe you want to send short_description of the current record, then you can try something like below



var myObj =


{


  "ticket": {


      "subject":   "New Ticket is created!",


      "comment":   { "body":   current.getValue('short_description')}, // set value of the short description to body property of comments.


      "priority": "urgent"


  }


};




find_real_file.png


Hi Deepak,



This JSON format contains one or more arrays, Now I have to send this JSON format in rest request body (NOT in RESPONSE BODY) to third party application to create incident in their application.



var myObj =


{


  "ticket": {


      "subject":   "New Ticket is created!",


      "comment":   { "body":   current.getValue('short_description')}, // set value of the short description to body property of comments.


      "priority": "urgent"


  }


};




Thank you.