How to Create JSON body text in HTTP Request

json
studio

#1

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?


How to send body using POST method of HTTP Request activity
Call Robot In Orchestrator By Rest APi
#2

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.


#3

Hello,

I’m having the same problem. I`m trying to start a job using HTTP request activity and I have to send the following information in the body json:

{
“startInfo”: {
“ReleaseKey”: “XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX”,
“RobotIds”: [
XXX
],
“NoOfRobots”: 0,
“Strategy”: “Specific”
}
}

I have tried to store in the variable StartProcessDto the value “{”“ReleaseKey”": ““XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX””,"“RobotIds”": [XXX],"“NoOfRobots”": 0,"“Strategy”": ““Specific””}" .

How should I set startInfo variable value?

Regards,


UiPath Orchestrator API : StartJobs
Orchestrator api
#4

#5

Dear Community
Where can I find the “ReleaseKey”?


#6

Hello @binaer,

You can use https://platform.uipath.com/odata/Releases method.

https://orchestrator.uipath.com/v2017.1/reference#releases

Here is an example TEST_ORCHESTRATOR_API.zip (15.8 KB)

Regards,
Susana


Calling restApi from UIPath by passing jsonObject as parameter
UiPath Robot: Start/Run .nupkg via comand line
#7

Hi Susana,

Where are you setting the UID/Pass for authentication in Authentication process?.

Thanks,
Sreeman.


#8

Hello @sreekolluri,

The Tenant name, user email and password are setting in the Parameters property of the HttpClient activity.

Regards,
Susana


#9

Thanks a lot Susana…

Regards,
Sreeman.


#10

Hello Susana,

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.

Regards
G


#11

Hola! sabes que no me funciona el tema de pasarle valores como variables a los parametros del http… podrias indicarme como lo hiciste?


#12

Hola @pardita,

¿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?

Un saludo,
Susana