I’m doing a HTTP Post request and need to send information in the body in JSON. I basically need to send:
{
“rfi”: {
“subject”: “My first API RFI!!”,
“assignee_id”: 632125,
“question”: “Does the API work?”
}
}
I get compiler errors when trying to type this into the body. It basically seems to want me to do this as a string, and I’m having a hell of a time getting it to work as a string with all of the quotes in there.
How do I enter this into the “Body” of an HTTP Request?
You can try storing it in a variable and passing that:
string myJsonBody = “{”“rfi”“: {”“subject”“: ““My first API RFI!!””,”“assignee_id”“: 632125,”“question”“: ““Does the API work?””}}”
Note that in VB quotes need to be escaped with another quote (so if you want to have " in a string, write “”), while in C# you escape with \ .
If you want more granular control, you might be better off doing a C# model class (data holder essentially) and optionally adding a method to it that will return the object properly formatted. Alternatively you could leave the serialization separate, to keep your model cleaner (depends on your preferences).
If you’ll use an existing library (like Newtonsoft.Json, which UiPath Studio already uses), you don’t need to worry for the most part how to serialize most types, as it will do that for you (including enums, arrays and lists, which is quite handy).
Something like:
using System;
using Newtonsoft.Json;
public class RfiData
{
public string Subject {get; set;}
public int AssigneeId {get; set;}
public string Question {get; set;}
public string FormatAsJson()
{
return JsonConvert.SerializeObject(this);
}
}
PS. Can’t seem to find a “Code” block, fortunately it’s simple code so formatting is not messy.
I have tried to store in the variable StartProcessDto the value “{”“ReleaseKey”“: ““XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX””,”“RobotIds”“: [XXX],”“NoOfRobots”“: 0,”“Strategy”“: ““Specific””}” .
Could you please tell how could I pass the parameters for generating the oauth2 token . I want to invoke a google api for which I got the oauth credentials . But , I am getting an error when I try to pass the credentials in headers or as parameters.
¿Puedes darme un poco más de información? ¿Qué operación estás tratando de hacer? ¿Qué actividad estás utilizando Orchestrator Http Request o Http Request?
Hi, is there a way to pass the data in the body yet dynamically change the input (I’m trying to post), im trying to post multiple issues through and API.
I think it is one of the best way to manage JSON and one of the simples in further use.
In this case you don’t have to worry about any additional quotes or other special marks.