Need to send this json through POST to a service,but don't know how to create it in Robot Framework:

{
      "id": "123456",
      "contactinfo": [
        {
            "contactid": "[email protected],",
            "typeOfcontact": "email"
        },
        {
            "contactid": "123543523Y",
            "typeOfcontact": "Phonenumber"
        }
      ],
      "subscriptionid":"132456"
    }

The following is my work:

*** Settings ***

Library    RequestsLibrary
Library    JSONLibrary  

*** Variables ***
${Base_URL}    http://example.com
** Test Cases ***

MyFirstTest
   Create Session    Update_Subscription    ${Base_URL}
   ${headers}=    Create Dictionary    Content-Type    application/json    Authorization    Token 1w121
   &{data}=    Create Dictionary    driverId=AZL123456    subscriptionId=SBS132456
  ${response}=  Post Request    Update_Subscription      ocpi/api/v1/user-enrollment/update-subscription    headers=${headers}   json=${data}  

   ${json_response}=  Convert To String    ${response.status_code}

   Log To Console    ${response.content}
   Should Be Equal    ${json_response}    200  

1 Answers

0
Todor Minakov On Best Solutions

contactinfo is a list of dictionaries, so you just need to create this structure, and add it to the data dictionary:

${entry 1}=    Create Dictionary    contactid    [email protected]
${entry 2}=    Create Dictionary    123543523Y 
 Phonenumber
${contactinfo}=    Create List     ${entry 1}    ${entry 2}
&{data}=    Create Dictionary    driverId=AZL123456    subscriptionId=SBS132456    contactinfo=${contactinfo}