HTTP Request / POST /JSON

Hello everyone,

I wanted to send JSON data to another app with using HTTP Request / POST in UiPath. But I could not do. Error message is 401-UnAuthorized at the app-side (destination)

  • This is the python code that i used for this purpose (sending JSON data) before…
    payload = {“auth_token”: “YOUR_AUTH_TOKEN”, “status”:stu2, “data-title1”:indeks, “data-title2”:env, “data-title3”:pakno, “data-title4”:cur, “data-title5”:tmp}
    r=requests.post(“http://xxxxxx:3030/widgets/hot21”,data=json.dumps(payload))

  • I tried to write Robot-equivalent as follows
    jason.csv File:
    status,data-title1,data-title2,data-title3,data-title4,data-title5
    green,21,emre,pakno,cur,tmp
    Read CSV:
    FilePath: “json.csv”
    DataTable: dtCSV
    Assign:
    payload=jsonConvert.SerializeObject(dtCSV)
    (payload is string)
    HTTP Request:
    EndPoint: “http://xxxxxx:3030/widgets/hot21
    Method: POST
    OAuth2/OAuth2Token:“YOUR_AUTH_TOKEN”
    Body: payload

Thanks in advance,

Issue resolved

What was the issue and how did you resolved? could you please provide resolution? It will helpful for other team members

I used dictionary instead of CSV and DataTable
So, I changed the Robot as follows:

Variables:
payload_dictionary Variable type: System.Collections.Generic.Dictionart<System.String, System.String>
payload_string Variable type: String

Add to dictionary:
Dictionary: payload_dictionary
Key: “auth_token”
Value: “YOUR_AUTH_TOKEN”

Add to dictionary:
Dictionary: payload_dictionary
Key: “status”
Value: “green”

Add to dictionary:
Dictionary: payload_dictionary
Key: “data-title1”
Value: “21” (or a variable)

Add to dictionary:
Dictionary: payload_dictionary
Key: “data-title2”
Value: “emre” (or a variable)
… (adding other keys)

Assign:
payload_string=JsonConvert.SerializeObject(payload_dictionary)

HTTP Request:
EndPoint: “http://xxxxxx:3030/widgets/hot21”
Method: POST
Body: payload_string
BodyFormat: application/json

PS: I found JsonConvert.SerializeObject function by asking a question in stackoverflow.com. Thanks to JussiV’s help…