'How do I send request in robot framework for api testing

I am passing username and password in the Post request body but it gives Issue as Client Error: “Not Acceptable for url: https://apiexample.com/demo” #but when I use json file to pass username and password then it works but I don't want to pass json file instead I want to give my username and password in the request body

*** Variables ***
${base_Url}=    https://apiexample.com

*** Test Cases ***
GenerateToken
    ${headers}=  create dictionary   Content-Type=application/json
    ${body}=    create dictionary    [email protected]   password=abc123
    #${body}=   get file  /Users/Documents/data.json   // (but i don't want to use this file method
    create session  mysession   ${base_Url}     headers=${headers}
    ${response}=    Post On Session    mysession   /demo  data=${body}   headers=${headers}

    log to console  ${response.status_code}


Solution 1:[1]

You need to pass request body in form of JSON format

*** Settings ***
Library           RequestsLibrary

*** Variables ***
&{JSON}    [email protected]    password=abc123

*** Test Cases ***
Test
    create session  mysession   ${base_Url}     headers=${headers}
    ${response}=    Post On Session    mysession   /demo   json=${JSON}   headers=${headers} 
    Log    ${response}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 durgesh dhamal