0

I've been using a RobotFramework for sending a POST request My code is the following :

*** Settings ***
Library  RequestsLibrary
Library  JSONLibrary
Library  Collections


*** Variables ***
${API_Base_Endpoint}    http://thetestingworldapi.com/




*** Test Cases ***
Post_Req_Test
    Create Session          AddData            ${API_Base_Endpoint}
    ${body}=                create dictionary   first_name=Tester1  middle_name=NAN  last_name=Tester2  date_of_birth=01/01/1999
    LOG TO CONSOLE          ${body}
    ${header}=              create dictionary   Content-Type=application/json
    ${response}=            post on session     AddData    api/studentsDetails     data=${body}  headers=${header}

But from some reason I'm getting a "HTTPError: 400 Client Error: Bad Request for url: http://thetestingworldapi.com/api/studentsDetails"

I've tried to send same request via Postman , and it works with no issues.

Any ideas what may go wrong ?

5
  • 1
    The body needs to be serialized to JSON, its essentially the same as this issue stackoverflow.com/questions/70142412/… Commented Feb 13, 2022 at 22:28
  • @MatthewKing Thank you ! it worked , I just wondering how no one performs serialization in every tutorial I saw. Thanks again Commented Feb 14, 2022 at 6:33
  • With the help of @MatthewKing I was referenced to this solution Worked for me Commented Feb 14, 2022 at 6:35
  • 1
    based on your comment, I did some digging and it seems that if you pass the body to json e.g. json=${body} instead of data=${body}, you won't need the serialization line I suggested Commented Feb 14, 2022 at 10:56
  • Yep , worked as well Commented Feb 14, 2022 at 14:54

1 Answer 1

0

With the help of @MatthewKing I was referenced to this solution Worked for me

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.