How to send body using POST method of HTTP Request activity

Hi all,

I’m a newbie to UI Path. I want to send JSON body using POST method of Request activity.

Not sure how body parameter would accept as I’m getting error every time.

Also, if anyone can give me a suggestion of the best way to send the body because JSON Body will have dynamic data everytime,

{
“autoReponse”: false,
“body”: “I am testing something”,
“subject”: “swagger test”,
“channel”: “Chat”,
“queue”: “Test”,
“submitter”: “xx”
}

All the keys above would have dynamic data. The dynamic data is being fetched from database and is saved to datatable in start of each process.

If I can get an example, that’d be great.
Thanks

Hi @malhotraneha162000

See these

Thanks,
Prankur

ohh cool. That was quick.

Thanks much @PrankurJoshi :slight_smile:

I have another problem too that I stated in my question :

If anyone can give me a suggestion of the best way to send the body because JSON Body will have dynamic data everytime,

{
“autoReponse”: false,
“body”: “I am testing something”,
“subject”: “swagger test”,
“channel”: “Chat”,
“queue”: “Test”,
“submitter”: “xx”
}

All the keys above would have dynamic data. The dynamic data is being fetched from database and is saved to datatable in start of each process.

See if this helps

Tahnks,
Prankur

Thanks @PrankurJoshi,

I will have a look and will get back if I get struck.

Thanks

1 Like

Hi @PrankurJoshi,

A very quick question, I’m struck again :frowning:

So basically, I am using a variable through ‘Assign’ activity to set the JSON body for POST request:

“{ ““body””: ““Test””,”“subject”":"" +subject+ “”, ““topicId””:"" +topicID+ “”, ““submitter””: “”+ submitter+ “”}"

Here, How do I append dynamic values for string variables - ‘subject’, ‘submitter’ and integer value - ‘topicId’
Do you may have any idea ?

@All Please suggest me how should I set dynamic Integer value to the JSON Body, if anyone has face similar issue, good to share the workaround :slight_smile:

Thanks

hello i need to send a body to, but the type of my body request is x-www-form-urlencoded in other case a need to send a form-data body

Hi Friends,

@PrankurJoshi, @ClaytonM @andrzej.kniola @Susana

I my workflow I am trying to post a request using Json body.
But, when I am trying to create a variable for Json body. I am getting Compiler error. Please find the screenshot below.

My Json Body Request is: {“userInfo”:{“firstName”:“John”,“lastName”:“Smith”,“address1”:“123 App Avenue”,“address2”:“Unit 123",“country”:“US”,“city”:“Denver”,“state”:“CO”,“zipCode”:“12345”,“phoneNumber”:“1231231234”,“email”:"beer@snipp.com”},“isQa”:true,“externalUniqueId”:“ID241”,“promotionIdentifier”:“100000”,“amount”:“5”,“deliveryConfiguration”:{“deliveryOptions”:{“campName”:"",“from”:“noreply@rewards.com”,“to”:"",“senderFirstName”:“App”,“senderLastName”:“Reward”,“subject”:“Your reward”,“message”:“Congratulations”,“bccAddress”:"",“ccAddress”:""},“deliveryMethod”:“email”,“disableDefaultDeliveryMethod”:false,“sendReward”:true}}

Using double quote i tried to store the body into a variable.

Please suggest, how can I store Json body into a variable.

1 Like

It looks like you want to store the request into a string. So what you will need to do is embed all the inner quotes (otherwise, each new quotation either opens or closes a string). So to do this, you can sometimes just simply replace the inner quotations with a single quote. If that doesn’t work (as I am not sure), you will need to use 2 quotes for each inner quotation
image

Regards.

1 Like

If I want to send the Json request body directly into HTTP Body then. Do I need to replay all the single quote to double quotes?

image

Yeah, I think so. If you hover over “Body”, it will show what type it should be, like <String>. I don’t have much experience with HTTP Request activity though.

I am getting 400 status code (Bad Request).

My suggestion would be to output whatever you put in the Body to a Message Box or WriteLine or Text File, so you can verify the string is correct. I’m not sure on the Body format though, cause I don’t have much experience with it. Good luck.

Thanks for the support @ClaytonM. I hope, some of our friends might help me.

Hi @ClaytonM Thanks for the support. It worked :slight_smile:

2 Likes

Hi @Bhaskar_Mukka,

I tried with escaping the double quotes too. But after hitting the request, I get the error as “error:request is not valid json”.
Any insights into this?
@ClaytonM @aksh1yadav

Thanks!

Hi @Akanksha_Varshney,

I have gone through you post

Can you please share the original request body. So that I can try from my end and let you know what is the issue.

Hi @Bhaskar_Mukka,
Thanks for checking.
Following is the original Request Body, that is working fine in Postman.
{
“default_phone_number”:null,
“password”: “qwer1234”,
“email”:"av@avtest.com",
“first_name”:“AV”,
“is_admin”: true,
“last_name”:“Admin”,
“permissions”:{
“edit_apps”:true,
“edit_commcare_users”:true,
“edit_data”:true,
“edit_web_users”:true,
“view_report_list”:[
],
“view_reports”:true
},
“phone_numbers”:[
],
“role”:“Admin”,
“username”:"av@avtest.com"
}

Request Body as string:
“{‘default_phone_number’:null,’password’: ‘qwer1234’,’email’:’av@avtest.com’,’first_name’:’Joe’,’is_admin’: True,’last_name’:’Admin’,’permissions’:{‘edit_apps’:True,’edit_commcare_users’:True,’edit_data’:True,’edit_web_users’:True,’view_report_list’:,’view_reports’:True},’phone_numbers’:,’role’:’Admin’,’username’:’av@avtest.com’}”

Thanks!

Hi @Akanksha_Varshney

Can you please try the attached request body and let me know is it working or not.

RequestBody.json (413 Bytes)

Note: Please open the json file in notepad and try.

Hey @Bhaskar_Mukka,

Was able to resolve the issue bu reading the JSON from a text file, without making it a string value.
Thanks @aksh1yadav for all the help!

1 Like