# Put request with long body

**URL:** <https://forum.robotframework.org/t/put-request-with-long-body/1816>\
**Category:** Robot Framework\
**Created:** [21 May 2021 09:05 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816 "2021-05-21T09:05:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonasbr93](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jonasbr93](https://forum.robotframework.org/u/Jonasbr93)\
**Post date:** [21 May 2021 09:05 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/1 "2021-05-21T09:05:17Z")

</div>

Hello everyone

Im quite new using robot framework and im having a problem, with a post request that as a big body :

{  
“address”: {  
“addressLine1”: “string”,  
“addressLine2”: “string”,  
“addressLine3”: “string”,  
“city”: “string”,  
“companyName”: “string”,  
“country”: {  
“abbreviation”: “string”,  
“name”: “string”  
},  
“firstName”: “string”,  
“id”: 0,  
“isBusiness”: true,  
“isDefault”: true,  
“isoCountryAlpha2”: {  
“alpha2”: “string”,  
“name”: “string”  
},  
“isoCountrySubdivision”: “string”,  
“lastName”: “string”,  
“phoneFax”: {  
“id”: 0,  
“isActive”: true,  
“isDefault”: true,  
“phoneNumber”: “string”  
},  
“phonePrimary”: {  
“id”: 0,  
“isActive”: true,  
“isDefault”: true,  
“phoneNumber”: “string”  
},  
“phoneSecondary”: {  
“id”: 0,  
“isActive”: true,  
“isDefault”: true,  
“phoneNumber”: “string”  
},  
“postalCode”: “string”,  
“state”: {  
“abbreviation”: “string”,  
“name”: “string”  
},  
“stateProvinceRegion”: “string”  
},  
“addressName”: “string”,  
“applicationContext”: {  
“applicationName”: “string”,  
“autowireCapableBeanFactory”: {},  
“beanDefinitionCount”: 0,  
“beanDefinitionNames”: [  
“string”  
],  
“classLoader”: {  
“defaultAssertionStatus”: true,  
“parent”: {}  
},  
“displayName”: “string”,  
“environment”: {  
“activeProfiles”: [  
“string”  
],  
“defaultProfiles”: [  
“string”  
]  
},  
“id”: “string”,  
“parent”: {},  
“parentBeanFactory”: {},  
“startupDate”: 0  
},  
“archived”: {},  
“id”: 0  
}

Since the request is only to add Address i belive i dont have to change all the filds of the body but im still very confused how to make it work. Some people have pointed to me to use jsonpath library but i still not sure how it would work to select the path that i might need to change. Im ok with small bodys but this one is making go nuts. Someone could give me a hand? Thanks in advance

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [21 May 2021 22:40 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/2 "2021-05-21T22:40:49Z")

</div>

Hi Jonas,

Just to clarify:

- which library are you using to test your application
- how do you currently have this data setup in your robot file?

Also another thing, this looks like it’s an example JSON body provided by the developer? you might want to check with your developer which of these fields are mandatory and or what the JSON looks like when generated by the client application. As an example are “addressLine2” and “addressLine3” always sent?, if they are, are they a blank string?

As there are a few ways to tackle this problem knowing these things will let me give you a better answer for your case.

Dave.

---

<div class="post-metadata">

**Author:** ![Jonasbr93](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jonasbr93](https://forum.robotframework.org/u/Jonasbr93)\
**Post date:** [24 May 2021 07:45 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/3 "2021-05-24T07:45:34Z")

</div>

Hello ! First of all thanks. Till the moment i’ve been only using RequestsLibrary but i belive for this one i will need to use json library or json validator. Not sure yet. Till the moment i havent anything in my robot file because i dont know how to make it work. im ok making requests with small bodys but when i have json files like this example i dont know how to make it work. i’ve been searching and for the info that i found i have to make somenthing like key values.

About the mandatory fields its also another questions. I dont have that info. Thats all the info i got from the swagger documentation, this is an free Api from Broadleaf Commerce - dont know if you might know it - its more like an exercise they gave me so i can get ready for future projects using Robot Framework.

In a different kind of request what i’ve done and it did work was that :

Create session customer ${Base\_URL}  
${inner}= Create Dictionary customerId=200 id=200 name=Bruno value=0  
${array}= Create List ${inner}  
${body}= Create Dictionary customerAttributes=${array} [emailAddress=xxxx@gmail.com](mailto:emailAddress=xxxx@gmail.com) firstName=algo id=200 lastName=Oliveira registered=True

But i dont know how i make it work here with a body like that one… I dont know which fields are mandatory and if they are all mandatory - i belive not - how could i make it work using this key - values of JsonLibrary.

Thanks once again for the help

---

<div class="post-metadata">

**Author:** ![Jonasbr93](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jonasbr93](https://forum.robotframework.org/u/Jonasbr93)\
**Post date:** [24 May 2021 10:48 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/4 "2021-05-24T10:48:29Z")

</div>

Im pretty sure that noone of this what im doing is right but i have no idea how to make this work :x

\*\*\* Settings \*\*\*  
Library RequestsLibrary  
Library JSONLibrary

\*\*\* Variables \*\*\*  
${Base\_URL}= [http://localhost:8082/api/v1](http://localhost:8082/api/v1)

\*\*\* Test Cases \*\*\*  
TC\_007\_PUT\_Customer  
${json}= Load Json From File Tests/Swagger/address.json  
${json\_object}= Update Value To Json ${json} $.address.addressLine1 Ratchadapisek Road

```
${queryParams}= Create Dictionary customerId=200
Create session customer ${Base_URL}

${body}= Create Dictionary data=${json_object}
${header}= Create dictionary Accept=application/json
${response}= PUT On Session customer /customer/address? params=${queryParams} json=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
```

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [24 May 2021 11:36 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/5 "2021-05-24T11:36:59Z")

</div>

Hi Jonas,

Since you are using requests library you have a few options, you can either create the dictionary structure like you have already done (in your second post) or you can just construct a string and send that as the body.

Creating the dictionary structure is probably the better approach as it’s easier to update the element values.

In case you didn’t know anything between curly braces “{” and “}” in a json string is the equivalent of a dictionary and anything between square braces “[” and “]” in a json string is the equivalent of a list.  
The json body you constructed in your second post would look like this:

```python
{"customerAttributes":[{"customerId":200, "id":200, "name":"Bruno", "value":0
}], "emailAddress":"xxxx@gmail.com", "firstName":"algo", "id":200, "lastName":"Oliveira", "registered":true}

```

or formatted it would look like:

```python
{
    "customerAttributes": [
        {
            "customerId": 200,
            "id": 200,
            "name": "Bruno",
            "value": 0
        }
    ],
    "emailAddress": "xxxx@gmail.com",
    "firstName": "algo",
    "id": 200,
    "lastName": "Oliveira",
    "registered": true
}

```

When I formatted your original JSON from your first post it looked like this:

```python
{
    "address": {
        "addressLine1": "string",
        "addressLine2": "string",
        "addressLine3": "string",
        "city": "string",
        "companyName": "string",
        "country": {
            "abbreviation": "string",
            "name": "string"
        },
        "firstName": "string",
        "id": 0,
        "isBusiness": true,
        "isDefault": true,
        "isoCountryAlpha2": {
            "alpha2": "string",
            "name": "string"
        },
        "isoCountrySubdivision": "string",
        "lastName": "string",
        "phoneFax": {
            "id": 0,
            "isActive": true,
            "isDefault": true,
            "phoneNumber": "string"
        },
        "phonePrimary": {
            "id": 0,
            "isActive": true,
            "isDefault": true,
            "phoneNumber": "string"
        },
        "phoneSecondary": {
            "id": 0,
            "isActive": true,
            "isDefault": true,
            "phoneNumber": "string"
        },
        "postalCode": "string",
        "state": {
            "abbreviation": "string",
            "name": "string"
        },
        "stateProvinceRegion": "string"
    },
    "addressName": "string",
    "applicationContext": {
        "applicationName": "string",
        "autowireCapableBeanFactory": {},
        "beanDefinitionCount": 0,
        "beanDefinitionNames": [
            "string"
        ],
        "classLoader": {
            "defaultAssertionStatus": true,
            "parent": {}
        },
        "displayName": "string",
        "environment": {
            "activeProfiles": [
                "string"
            ],
            "defaultProfiles": [
                "string"
            ]
        },
        "id": "string",
        "parent": {},
        "parentBeanFactory": {},
        "startupDate": 0
    },
    "archived": {},
    "id": 0
}

```

so for the ${body} you would just have 5 entries like this:

```python
${body}= Create Dictionary address=${address} addressName=string applicationContext=${applicationContext} archived=${archived} id=0

```

Then you just need to construct the dictionaries for ${address} and ${applicationContext}, and ${archived} would be an empty dictionary

I just saw your 3rd post, yes that’s a valid approach too, did it work?

Dave.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [24 May 2021 11:49 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/6 "2021-05-24T11:49:38Z")

</div>

Hi Jonas,

If your PUT On Session failed from the example in your 3rd post, try changing json=${body} to data=${body}

The reason is [Load Json From File](https://robotframework-thailand.github.io/robotframework-jsonlibrary/JSONLibrary.html#Load%20JSON%20From%20File) returns a dictionary object

Another useful trick is to use the [Log](http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Log) keyword in your test case as you are developing the test case e.g.

```python
Log ${json}
Log ${json_object}

```

This way you can confirm what’s inside each variable, once you have the test case working nicely just remove the unnecessary Log steps.

Dave

---

<div class="post-metadata">

**Author:** ![Jonasbr93](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jonasbr93](https://forum.robotframework.org/u/Jonasbr93)\
**Post date:** [24 May 2021 12:06 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/7 "2021-05-24T12:06:52Z")

</div>

Thanks once again Dave !

Its very conforting to see that there is people like you in this word always up to help others.

Unfortonattly it didnt work . Only the way i did on my second post creating a ${inner} e ${array} worked for me , but like i sayd before that was a small body and kinda easy to work with. For the other example i have no idea whats going on but nothing works 😕 even when i try to make the request on the Swagger i get a 500 error. I have no clue what im doing wrong … i’ve tryed what you sayd about changing the data to json also but it didnt worked aswell…

Im smashing this api request for like a week already and i got nowhere.  
I’ll leave here a link of the API if there is anyone up to have a look… i’ve find it very usefull for a test but at the same time im not getting anywhere with this:

> **[BroadleafCommerce/DemoSite](https://github.com/BroadleafCommerce/DemoSite)**
>
> The Broadleaf Heat Clinic Spring Boot application. Contribute to BroadleafCommerce/DemoSite development by creating an account on GitHub.

It’s my first time using robot on a api and i’ve found it very hard to understand to be honest… working direct with websites, xpaths and stuff was so easy but when i got that “test” i’ve learned that i still dosnt know anything about robot. I would love if someone could show me how i could make this work properly since im very noob and cant even make it work from the swagger. Hopefully its just the api that sucks and i might know somenthing. Or not.

Once again im very gratful for you help Dave! that was awesome from you. All the best !

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [24 May 2021 12:46 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/8 "2021-05-24T12:46:24Z")

</div>

Hi Jonas,

Since this is a learning exercise and not an application you need to test for your employer, then I suggest you start with something that has easier to understand documentation.

I usually recommend people start out with [open cart](https://www.opencart.com/) when learning any automation tool, it’s an open source online shopping cart (e-commerce) application with excellent documentation a good web front end and an api that has examples with example data.

- You can download a virtual machine image or docker image (which ever is easier for you) with open cart already setup [from here](https://bitnami.com/stack/opencart) so you don’t need to follow a complex install process
- You can also try out the [live demo here](https://demo.opencart.com/)
- As you can see [here](http://docs.opencart.com/en-gb/system/users/api/) they actually use python requests examples in the documentation (python requests is the python library behind the requestslibrary in robot framework)

The reason I recommend open cart is it has just enough complexity to be a useful “real world” learning tool (the demo applications that come with many test tools are too simple and not realistic of real applications) but it’s simple enough and well documented enough to not discourage people, plus it actually is a real world application used by many online stores.

Don’t be discouraged, keep trying and you’ll get there. I found that Broadleaf/swagger documentation hard to follow too.

Robot framework is one of the easiest test automation tools, but web api’s are one of the hardest types of automation for people without a programming background, one of the best things about Robot framework is the forum community is quite friendly, much better than other tools i’ve used over the years.

Good luck on your learning journey.

Dave.

---

<div class="post-metadata">

**Author:** ![Alaatayran](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/alaatayran/32/2194_2.png) [@Alaatayran](https://forum.robotframework.org/u/Alaatayran)\
**Post date:** [2 January 2023 12:18 UTC](https://forum.robotframework.org/t/put-request-with-long-body/1816/9 "2023-01-02T12:18:50Z")

</div>

hi any update ?  
I’m facing the same issue ☹
