HTTP POST Browser Keyword returns 500. Is it the body format?

I tried to send the HTTP POST request, but I am always getting 500 error.

I copied the request body from browser when I manually trigger the same request, and my body json file looks like this:
{
“id”: “123”,
“name”: “NewName”,
“deactivated”: false,
“group”: null
}

I noticed in my HTTP GET Keyword that null is displayed as None for example in my log.
So, I tried changing false to False, null to None in my json file.

Still getting 500.

Is there anything that I am missing, because my Browser Library HTTP GET Keyword works fine.

  1. You dont make “http requests” with browser library - you automate the browser.
  2. you dont show any code
  3. Python considers null as None and since RF is python project, thats how it goes.
  4. Yes, you are probably missing a lot but since you dont show your code, your payload, its really hard to say anything.
1 Like

My file is named data.json and this is the content:
{
“id”: “123”,
“name”: “NewName”,
“deactivated”: false,
“group”: null
}

My code looks like this
${res}= HTTP url=myUrl method=POST body=data.json

Tried putting the actual payload into body argument instead of just the name of the file ?

You cannot reference a file as payload (body or json). What your code is doing now, is sending the string “body.json” as the body of the request.

You’ll need to read the file content into a variable, easiest is to use the json module for this (or a RF library). Reading a json file like this gets you a dictionary, which you can pass to the json parameter of a HTTP request.

1 Like

I use this to put my json file into the variable

${requestBody}=    OperatingSystem.Get File    ${CURDIR}$/data.json
${res}= HTTP url=myUrl method=POST body=${requestBody}

Get File will get you the file content as a string. You’ll need to either turn it into JSON (encode / serialize) to pass it to the body parameter or first convert the string to a (Python) dict and pass that to the json parameter.

If you load the file content as json (using e.g. the JSONLibrary or json module in Python) you can pass that directly to the json parameter.

The variable ${requestBody} is already a dictionary.
When I tried to convert it it reported an error.

I checked with

${type}=    Evaluate    type(${requestBody}).__name__
Log    The type of the variable is: ${type}

And the result was: The type of the variable is: dict

python dict is automatically serialized into json in 99% of the cases, i dont think you need to convert anything. Just place the dict into body.