Good Day,
I just started to learn how to use RPA to automate somethings and would like to seek for your expertise that I am using REST method and below is my work flow.
Kindly guide/advice the code below on how to call or the command line for a variable into HTTP Request body (using application/json)?
Workflow (REST Method): Using Auto read the email > Grab the outlook body content > Store in CSV (build database + write csv) > Read CSV > HTTP Request POST > Log a case on ServiceNow
Below is the sample of my coding…
assign properties -
1st variable - extractSubject and the codes is item.subject
When I tried to run it, ServiceNow does not create the case whereas if I hard code without calling the variables, it works… hence able to provide step by step and guide me along with this? I’ve read and tried all searching related to http request json but still not working.
I would compare the two final versions of your JSON to see if there is anything that should be escaped or encoded. I could also recommend importing Newtonsoft.Json to serialize the content from an object rather than building the JSON string yourself.
Short of that, is ServiceNow returning an error message to point to what might be wrong?
You have a mixture of quotes, I’m not sure if this is your JSON string or typing it out with your browser, but JSON should be double-quoted, not single-quoted.
After normalizing the quotes, you’ll notice + extractSubject + is a literal string as your also missing an escaped double-quote around extractSubject
Good Day, perhaps i make the code more understandable more simple for you to advice me and also would like you to guide me how to call the json object in the http request body (bodyformat: application/json). I have no idea if my command line typed correctly.
====================================================================
earlier I tried using assign properties and type (below as follows)
variable: abc
value: JsonConvert.SerializeObject(variablesReadFromCsvRow)
“{”“u_choice_1"”:““string 1"”,”“u_extractNames”“:”“” + abc + “”“}”
able to check if the above command line is typed correctly?
I was facing this issue few days ago. I have assigned JSON string into an string variable for example called “request”. Then I have used .Replace method to replace parts of json with variables and assigned it to request again. I was able to use json created in that way as a request body.
It would be easier if you could provide a sample showing your input and what the final output looks like without knowing what is in variable, it all just a guess.
quick example:
myArray = New Dictionary(Of String, String) From {{"Name", "Bob"}, {"Age", "109"}}
String.Join(",", myArray)
JsonConvert.SerializeObject(myArray)
Output:
[Name, Bob],[Age, 109]
{"Name":"Bob","Age":"109"}
From what you’ve provided alone, the only things I could point out was the mismatched quotes " " vs “ ” vs ’ , both my UiPath and Visual Studio complain about the curly / “smart” quotes. But there could be other things involved, depending on what the expected payload is and what the values of the keys are whether or not they need to be escaped in the JSON and so on
So if you can provide some sort of sample, and indicate what error if any you are getting back from ServiceNow, that would better assist others to help offer suggestions.