# How to capture field value from text response

**URL:** <https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201>\
**Category:** Help Hub\
**Tags:** tests, scripts\
**Created:** [September 9, 2024, 2:58pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201 "2024-09-09T14:58:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramofficial1](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@ramofficial1](https://community.postman.com/u/ramofficial1)\
**Post date:** [September 9, 2024, 2:58pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/1 "2024-09-09T14:58:14Z")

</div>

Hi, I need to capture the value of a token from a text response. I am able to capture the whole response using “var responseText = pm.response.text();”. In that i need to capture the access\_token value. Can someone please guide me as to how i can get the access\_token value?

Response:

```auto
**access_token** =XXX&expires_in=600&token_type=Bearer&scope=trapi.data.wealth-clients.advisor_dashboard&refresh_token=79a8d6db-4052-4301-88f3-95ce4eb0521e

```

---

<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:** [September 9, 2024, 4:09pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/2 "2024-09-09T16:09:45Z")

</div>

Hey @ramofficial1 👋

You use something like this:

```auto
let str = pm.response.text(),
    accessToken = str.split('&').find(param => param.startsWith('access_token')).split('=')[1];

console.log(accessToken); 

```

There are a few other ways that you could do it and i’m sure others will respond on the topic telling you another way but if you wanted something quick, that should do.

---

<div class="post-metadata">

**Author:** ![ramofficial1](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@ramofficial1](https://community.postman.com/u/ramofficial1)\
**Post date:** [September 10, 2024, 4:58am UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/3 "2024-09-10T04:58:45Z")

</div>

Thanks Danny. I am able to extract the access token using the code provided.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 10, 2024, 1:43pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/4 "2024-09-10T13:43:53Z")

</div>

@danny-dainton

Do you know why we can’t use URLSearchParams?

The Sandbox documentation says that the url nodeJS library is available to use in the Sandbox, so this method should be available??

[https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#using-external-libraries](https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#using-external-libraries)

You get a reference error if you try to use it.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/1/61618f313c5f85bb2842348370d5745eea5957aa.png)

Is the library not fully implemented?

---

<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:** [September 10, 2024, 1:59pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/5 "2024-09-10T13:59:36Z")

</div>

Is that relevant to the topic here? Did you need that to provide a solution?

I don’t know what is and isn’t exactly part of those external libraries - Some of them are not the full library due to various reasons related to the sandbox environment.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [September 10, 2024, 7:17pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/6 "2024-09-10T19:17:07Z")

</div>

Yes, it would have allowed you to parse the query parameters in the string.

Never mind if its not supported in the sandbox.

---

<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:** [September 10, 2024, 9:13pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/7 "2024-09-10T21:13:16Z")

</div>

As I mentioned, there would be many different ways to achieve the same outcome. 😁

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [September 13, 2024, 9:14pm UTC](https://community.postman.com/t/how-to-capture-field-value-from-text-response/68201/8 "2024-09-13T21:14:11Z")

</div>

Closed on September 13, 2024, 9:14pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
