# How I use same session or form-data in RequestsLibrary

**URL:** <https://forum.robotframework.org/t/how-i-use-same-session-or-form-data-in-requestslibrary/5761>\
**Category:** Libraries\
**Created:** [30 May 2023 18:45 UTC](https://forum.robotframework.org/t/how-i-use-same-session-or-form-data-in-requestslibrary/5761 "2023-05-30T18:45:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![netospt](https://avatars.discourse-cdn.com/v4/letter/n/bc8723/32.png) [@netospt](https://forum.robotframework.org/u/netospt)\
**Post date:** [30 May 2023 18:45 UTC](https://forum.robotframework.org/t/how-i-use-same-session-or-form-data-in-requestslibrary/5761/1 "2023-05-30T18:45:00Z")

</div>

Guy’s, I’ve got a problem with a POST in robot.  
I’m sending a GET in a URL , this URL I get a Token and put it inside a variable to use the variable in my POST sending inside form-data.  
I need to get a token before sending the POST using form-data.  
but the response of the POST , always is error because the token.  
This token needs to be kept in the same session to work.

How do I do? It’s correct the sending form-data or doesn’t is it the same session?

My code:

```python
Create Session StartAPI ${URL_LOGINSHOW} verify=true
${response} Get ${URL_LOGINSHOW}
${response_body} Set Variable ${response.content} # Store the response body in a variable
${response_str} Convert To String ${response_body}  
${value} Get Lines Containing String ${response_str} dynamic-csrf-token
${csrf_token} Get Substring ${value} 70 250
Log ${csrf_token} # Print the extracted value
Set Global Variable ${csrf_token} **//here I got the token**

```

Create Session StartAPI ${URL\_SUBMITREGISTRATION} verify=true  
${HEADERS}= Create Dictionary  
#… Content-Type=${CONTENT\_TYPE}  
#… User-Agent=RobotFramework  
#… Accept=_/_  
… Authorization=Basic ${auth\_data}  
${payload} Create Dictionary  
… dwfrm\_profile\_customer\_firstname Newton  
… dwfrm\_profile\_customer\_lastname Newton  
… dwfrm\_profile\_customer\_cpf 096.344.033-11  
… dwfrm\_profile\_customer\_birthdate 13/04/1992  
… dwfrm\_profile\_customer\_email [newton.test@gmail.com](mailto:newton.test@gmail.com)  
… dwfrm\_profile\_customer\_phone (81) 99291-8155  
… dwfrm\_profile\_login\_password Teste@123  
… dwfrm\_profile\_login\_passwordconfirm Teste@123  
… csrf\_token ${csrf\_token} **//here I use the token**  
${RESPONSE}= POST On Session StartAPI ${URL\_SUBMITREGISTRATION} data={${payload}} headers=${HEADERS} expected\_status=Anything  
Log ${RESPONSE.json()}

---

<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:** [30 May 2023 23:22 UTC](https://forum.robotframework.org/t/how-i-use-same-session-or-form-data-in-requestslibrary/5761/2 "2023-05-30T23:22:18Z")

</div>

Hi Newton,

Sime suggestions to try:

- before the POST, add a Log of the ${payload} variable (just to check it’s what you expected it to be
- it could be your formatting when you pasted in the forum, but you do have 2+ spaces between csrf\_token and ${csrf\_token}, etc?
- I’ve seen the `... ` syntax turn each line into a list item, so i’m concerned that `Create Dictionary` is getting a list of lists, perhaps try changing to the `=` style like you did for the headers (i.e. `dwfrm_profile_customer_firstname=Newton`, etc)
- I’m guessing that "` //here I use the token`" is not in your robot file? if it is try changing it to ` #here I use the token`
- I’ve not seen this `data={${payload}}` syntax before perhaps it should be `data=${payload}` ?

Hopefully one or a couple of these will help,

Dave.
