# Magento Postman Soap Login get sesssionId in Pre-request Script

**URL:** <https://community.postman.com/t/magento-postman-soap-login-get-sesssionid-in-pre-request-script/495>\
**Category:** Help Hub\
**Tags:** soap, magento, login, sessionid\
**Created:** [December 16, 2017, 5:58pm UTC](https://community.postman.com/t/magento-postman-soap-login-get-sesssionid-in-pre-request-script/495 "2017-12-16T17:58:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![clokers80](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clokers80](https://community.postman.com/u/clokers80)\
**Post date:** [December 16, 2017, 5:58pm UTC](https://community.postman.com/t/magento-postman-soap-login-get-sesssionid-in-pre-request-script/495/1 "2017-12-16T17:58:04Z")

</div>

I can use pm.sendRequest to make an XML request.

For example with magento to use soap I have to login to receive an id session

url magento request soap  
`http://127.0.0.1/magento-1.9.3.7/api/v2_soap`

request

> ```
> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
> <Body>
> <login xmlns="urn:Magento">
> <username>xxxx</username>
> <apiKey>xxxxx</apiKey>
> </login>
> </Body>
> </Envelope>
> 
> ```

response

> ```
> <SOAP-ENV:Body>
> <ns1:loginResponse>
> <loginReturn xsi:type="xsd:string">8292295363d53a2ca209dc4a8457da77</loginReturn>
> </ns1:loginResponse>
> </SOAP-ENV:Body>
> 
> ```

can I create a pre-request script using pm.sendRequest, pars the answer and just take the session id (loginReturn) to insert in another request (doing it all in one step)?

---

<div class="post-metadata">

**Author:** ![mshakeel](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@mshakeel](https://community.postman.com/u/mshakeel)\
**Post date:** [May 31, 2018, 11:15pm UTC](https://community.postman.com/t/magento-postman-soap-login-get-sesssionid-in-pre-request-script/495/2 "2018-05-31T23:15:29Z")

</div>

In Tests tab

```
var responseJson = xml2Json(responseBody);
postman.setEnvironmentVariable("sessionId", responseJson['SOAP-ENV:Envelope']['SOAP-ENV:Body']['ns1:loginResponse']['loginReturn']['_']);

```

- It will set sessionId variable within environment and you can use it for other calls {{sessionId}}
