# How to get data from header 'location'

**URL:** <https://community.postman.com/t/how-to-get-data-from-header-location/40399>\
**Category:** Help Hub\
**Tags:** response, headers\
**Created:** [October 24, 2022, 7:36pm UTC](https://community.postman.com/t/how-to-get-data-from-header-location/40399 "2022-10-24T19:36:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jadrissi](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jadrissi](https://community.postman.com/u/jadrissi)\
**Post date:** [October 24, 2022, 7:36pm UTC](https://community.postman.com/t/how-to-get-data-from-header-location/40399/1 "2022-10-24T19:36:35Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-just-getting-started-category/37) before creating a new topic.**

> Here’s an outline with best practices for making your inquiry.

_My question_:  
My issue is that I want to extract an url from header response (location): the response show 2 times the same url: exp: [https://pro.uat.test/https:/cam.testcase/test/](https://pro.uat.test/https:/cam.testcase/test/)

_Details (like screenshots)_:

How to get only thr second part of the header response : https:/cam.test.testcase/PRODUCR221333  
Or only the id PRODUCR221333 ?

_How I found the problem_:

Is there a solution ? Many thanks  
_I’ve already tried_:

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [October 24, 2022, 8:28pm UTC](https://community.postman.com/t/how-to-get-data-from-header-location/40399/2 "2022-10-24T20:28:30Z")

</div>

Hi @jadrissi

You could save the value returned in the header as a variable and then use slice to remove characters as needed.

Example;

```auto
let URL = 'https://cam.uat.commercial.io/https:/cam.uat.commercial.io/v0/P221333/info';
console.log(URL.slice(62, -5));

```

Output;

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/9/4/94ff090c9553eaaf72472b3ed3e8a10528dcfb4b.png)

* * *

OR …

You could use a RegEx

Example:

```auto
let URL = 'https://cam.uat.commercial.io/https:/cam.uat.commercial.io/v0/P221333/info';
var array = new RegExp("/v0/(.*?)/info").exec(URL);
    if(array!=null && array.length>0 && array[1]!=null){
        //pm.globals.set("secret", ""+array[1]);
        console.log(array[1]);
    }

```

Output:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/9/f908569bbae84a982e01968bd967c632fce966ca.png)

---

<div class="post-metadata">

**Author:** ![jadrissi](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jadrissi](https://community.postman.com/u/jadrissi)\
**Post date:** [October 24, 2022, 8:32pm UTC](https://community.postman.com/t/how-to-get-data-from-header-location/40399/3 "2022-10-24T20:32:28Z")

</div>

Hi @w4dd325 thank you so much I will try it and let you know

---

<div class="post-metadata">

**Author:** ![jadrissi](https://avatars.discourse-cdn.com/v4/letter/j/49beb7/32.png) [@jadrissi](https://community.postman.com/u/jadrissi)\
**Post date:** [October 25, 2022, 4:54pm UTC](https://community.postman.com/t/how-to-get-data-from-header-location/40399/4 "2022-10-25T16:54:47Z")

</div>

Thank you very much it works fine 👌

---

<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:** [August 31, 2023, 3:21pm UTC](https://community.postman.com/t/how-to-get-data-from-header-location/40399/5 "2023-08-31T15:21:50Z")

</div>

Closed on August 31, 2023, 3:21pm UTC

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