# From string to int

**URL:** <https://community.postman.com/t/from-string-to-int/13347>\
**Category:** Help Hub\
**Created:** [June 12, 2020, 11:24am UTC](https://community.postman.com/t/from-string-to-int/13347 "2020-06-12T11:24:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [June 12, 2020, 11:24am UTC](https://community.postman.com/t/from-string-to-int/13347/1 "2020-06-12T11:24:09Z")

</div>

I am attempting to retrieve an int from a json array, then use that as a variable in my request body.

This is what i have so far:

```
const jsonData = pm.response.json();

const tempId = jsonData['Content']['2020-06-12']['15'][8]['Id'];

parseInt(pm.environment.get('test-tempId', tempId));

```

> [id] is an int i.e 123456

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 12, 2020, 11:49am UTC](https://community.postman.com/t/from-string-to-int/13347/2 "2020-06-12T11:49:38Z")

</div>

> [@armygrad24](#):
>
> parseInt(pm.environment.get(‘test-tempId’, tempId));

This doesn’t look quite right to me.

To set the value you would just do this:

`pm.environment.set('test-tempId', tempId);`

To parse that stored variable string value to an Int, you would need to get it like this:

`parseInt(pm.environment.get('tempId'));`

---

<div class="post-metadata">

**Author:** ![armygrad24](https://avatars.discourse-cdn.com/v4/letter/a/919ad9/32.png) [@armygrad24](https://community.postman.com/u/armygrad24)\
**Post date:** [June 12, 2020, 12:51pm UTC](https://community.postman.com/t/from-string-to-int/13347/3 "2020-06-12T12:51:29Z")

</div>

in the following what does pm stand for

`pm.environment.set('test-tempId', tempId);`

How is the response called i.e the call that gets the data is called Request

this is the Test script now

```
const jsonData = pm.response.json();

const tempId = jsonData['Content']['2020-06-12']['15'][8]['Id'];
parseInt(pm.environment.get('tempId'));
pm.environment.set('test-tempId', tempId);
```

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 12, 2020, 4:18pm UTC](https://community.postman.com/t/from-string-to-int/13347/4 "2020-06-12T16:18:34Z")

</div>

The `pm.*` API is a set of global functions that can be used with the sandbox environment.

In your case, you are using `pm.environment` but you could use `pm.globals` or `pm.collectionVariables` depending on what you’re trying to achieve.

These are just a few of the functions that are available but the full list can be found here:

[https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/](https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/)

For your issue - This code, in a Test Script, would be getting the full JSON response body and then extracting the `Id` value from that part of the data and storing it as an environment variable.

```
const jsonData = pm.response.json();

const tempId = jsonData['Content']['2020-06-12']['15'][8]['Id'];
pm.environment.set('test-tempId', tempId);

```

 ![Screenshot 2020-06-12 at 17.05.53](https://us1.discourse-cdn.com/getpostman/original/2X/c/cc0fc3d6f3fcc38ee237039b1878d72214e1bcca.png)

You could just use that stored variable, in a request body like this:

```
{
    "test-id": {{test-tempId}}
}

```

If you add quotes around the `"{{...}}"` it would send that as a string but as you haven’t it should just send that as an `Int`
