Search code examples
jsonapibase64robotframework

RobotFramework POST request with Base64 content


I would really appreciate an example request for the following body data:

{
    "Content": "PD94bWwgdmVyc...F",
    "UserId": "user@mail.com",
    "FileName": "Test.txt"
}

This is JSON body and the content of the file should be represented as Base64 string.


Solution

  • I have managed to compile a code that is able to send post requests with base64 content. This is good practice if you want to avoid pointing filepaths on your local machine.

    N.B. JSONLibrary is required

    Create Session    mysession   ${url}
    &{headers}  Create Dictionary  Content-Type=application/json; charset=utf-8     Authorization=${token}
    ${json}=    Catenate    {"Content": "PD94bWwgdmVyc2..."}   
    ${resp}    POST     url=${url}/api/endpoint   data=${json}    headers=${headers}
    

    The status should be: expected_status=200

    I am pretty sure that this code could be improved, feel free to contribute.