Problem of double quotes in POST body

Hi gents,
I’m very new to Robot Framework and Python as well (a couple of days now I’m using it), but I’m facing an issue when trying to post my request.

My concern is that I need to have double quotes around my body values in the request :

Here is what I get :
headers={‘User-Agent’: ‘python-requests/2.28.1’, ‘Accept-Encoding’: ‘gzip, deflate’, ‘Accept’: ‘/’, ‘Connection’: ‘keep-alive’, ‘adoriaClientKey’: ‘ef7dc91b-d778-4800-b6d0-1f9438240989’, ‘Content-Type’: ‘application/json; charset=utf-8’, ‘Cache-Control’: ‘no-cache’, ‘Content-Length’: ‘38’}
body=number=5&from=2022-10-21&to=2022-10-21

Here is what I need to have :
headers={‘User-Agent’: ‘python-requests/2.28.1’, ‘Accept-Encoding’: ‘gzip, deflate’, ‘Accept’: ‘/’, ‘Connection’: ‘keep-alive’, ‘adoriaClientKey’: ‘ef7dc91b-d778-4800-b6d0-1f9438240989’, ‘Content-Type’: ‘application/json; charset=utf-8’, ‘Cache-Control’: ‘no-cache’, ‘Content-Length’: ‘38’}
body=number=“5”&from=“2022-10-21”&to=“2022-10-21”

Here is my piece of script :

Post data From External Pricelist TariffNumber
    [Arguments]    ${iso}
    ...    ${keyValue}
    ...    ${internalSiteCode}
    ...    ${priceListCode}
    ...    ${tariffNumber}
    ...    ${from}
    ...    ${to}

    Create Session    mysession    ${UrlExtPricelist}    verify=true
    &{body}=    Create Dictionary
    ...    number=${tariffNumber}
    ...    from=${from}
    ...    to=${to}

    &{header}=    Create Dictionary
    ...    key=${keyValue}
    ...    Content-Type=application/json; charset=utf-8
    ...    Cache-Control=no-cache

    ${response}=    POST On Session    mysession
    ...    /${iso}/site/${internalSiteCode}/priceList/${priceListCode}/tariffNumber
    ...    headers=${header}
    ...    data=${body}
    RETURN    ${response}

Thanks in advance for help :pray:

Continuing the discussion from Problem of double quotes in POST body:

I have the answer to my problem. I should have used

json=${body}

rather than

data=${body}

.

1 Like