# Query String from API

**URL:** <https://community.hubspot.com/t/query-string-from-api/69690>\
**Category:** APIs & Integrations\
**Created:** [November 21, 2022, 5:58pm UTC](https://community.hubspot.com/t/query-string-from-api/69690 "2022-11-21T17:58:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chrouglas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrouglas/32/196621_2.png) [@Chrouglas](https://community.hubspot.com/u/Chrouglas)\
**Post date:** [November 21, 2022, 5:58pm UTC](https://community.hubspot.com/t/query-string-from-api/69690/1 "2022-11-21T17:58:58Z")

</div>

Quick question and hopefully a simple one.

I have an API call that returns a list of contacts in a particular list.

vidoffset = data.response[‘vid-offset’];

[https://mydomain.com/\_hcms/api/getcontacts?voff='+vidoffset](https://mydomain.com/_hcms/api/getcontacts?voff='+voff)

But how do I get the value of voff (vid\_offset from the returned json data) from within my function…

var vidOffset = voff;

[https://api.hubapi.com/contacts/v1/lists/‘+listID+’/contacts/all?count=‘+numContacts+vidOffset+’&property=associatedcompanyid&property=firstname&property=lastname](https://api.hubapi.com/contacts/v1/lists/'+listID+'/contacts/all?count='+numContacts+vidOffset+'&property=associatedcompanyid&property=firstname&property=lastname)’

… so i can use it in subsequent calls?

Thanks in advance!

C

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [November 21, 2022, 7:26pm UTC](https://community.hubspot.com/t/query-string-from-api/69690/2 "2022-11-21T19:26:11Z")

</div>

Hey @Chrouglas,

In the response body of that API request, you should find a “has-more” and a “vid-offset” attribute at the end of it [as seen here.](https://legacydocs.hubspot.com/docs/methods/lists/get_list_contacts)

 ![tominal_0-1669058751522.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/9/9353e259468bf14f3cd93f59a995a55851518159.png)

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Chrouglas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrouglas/32/196621_2.png) [@Chrouglas](https://community.hubspot.com/u/Chrouglas)\
**Post date:** [November 21, 2022, 7:34pm UTC](https://community.hubspot.com/t/query-string-from-api/69690/3 "2022-11-21T19:34:27Z")

</div>

Thanks for the quick response. I dont think I was clear in my question 🙂

I got that part and im grabbing it with

vidoffset = data.response[‘vid-offset’];

My question is if I make a second call with that vid-offset as a query string param, how do I use access that value inside the serverless function.

I.e.

const contacts = ‘[https://api.hubapi.com/contacts/v1/lists/1/contacts/all?count=50&property=associatedcompanyid&property=firstname&property=lastname&vidOffset=HOW-DO-I-GET-THIS-FROM-THE-PREVIOUS-API-CALL](https://api.hubapi.com/contacts/v1/lists/1/contacts/all?count=50&property=associatedcompanyid&property=firstname&property=lastname&vidOffset=HOW-DO-I-GET-THIS-FROM-THE-PREVIOUS-API-CALL)’;

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [November 21, 2022, 7:58pm UTC](https://community.hubspot.com/t/query-string-from-api/69690/4 "2022-11-21T19:58:24Z")

</div>

Oh I see! Your question is more syntax than HubSpot. I missed the line where you mentioned your vidoffset variable.

Apologies in advance if I am still not understanding your question.

Are you trying to perform a loop? You could store the vidOffset in a separate variable outside the loop then update it on every response.

```auto
let vidOffset = 0;
while(vidOffset !== 0) {
 // perform API request
 // on response, update the vidOffset value
 // if the response' has-more is false, set the vidOffset to 0 to break the loop
}

```

If you are asking how to simply add the value of your response in the string, there are a couple ways:

Using `:

`/contacts/v1/lists/1/contacts/all?count=50&property=associatedcompanyid&property=firstname&property=lastname&vidOffset=${vidoffset}`

Normal quotes:

`"/contacts/v1/lists/1/contacts/all?count=50&property=associatedcompanyid&property=firstname&property=lastname&vidOffset=" + vidoffset`

I would also double check your variable spelling. In your post you are storing it as “vidoffset” but in your URI that you posted it is “vidOffset”.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Chrouglas](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrouglas/32/196621_2.png) [@Chrouglas](https://community.hubspot.com/u/Chrouglas)\
**Post date:** [November 22, 2022, 12:26pm UTC](https://community.hubspot.com/t/query-string-from-api/69690/5 "2022-11-22T12:26:48Z")

</div>

Thanks for the suggestions. Ive gotten it working and it was indeed just a syntax thing. I was literally just looking for how to access a query string parameter from inside the function and while it was in fact [staring me in the face](https://developers.hubspot.com/docs/cms/data/serverless-functions/reference#serverless-json)…

 ![contextdotparams.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/2X/d/d71b64c28c53af62f66c96b6796f7c4672410b15.jpeg)

… I was getting so many errors that I attributed to how i was calling for the variable.

Here is how it ended up…

 ![getparam.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/e/2/e25cf85ae2e02e9958fcdee78406df802ad0e444.jpeg)

context.params.paramname

Thanks again for your help. I’m sure I’ll be asking for it again some time 🙂

---

<div class="post-metadata">

**Author:** ![tominal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tominal/32/73018_2.png) [@tominal](https://community.hubspot.com/u/tominal)\
**Post date:** [November 22, 2022, 7:32pm UTC](https://community.hubspot.com/t/query-string-from-api/69690/6 "2022-11-22T19:32:50Z")

</div>

Awesome! I’m happy you got it all sorted out 😁
