# Galaxy API 101 - Used variables | AssertionError: expected -1 to be above -1

**URL:** <https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [December 4, 2022, 10:36am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738 "2022-12-04T10:36:33Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larry\_O](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@Larry\_O](https://community.postman.com/u/Larry_O)\
**Post date:** [December 4, 2022, 10:36am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/1 "2022-12-04T10:36:33Z")

</div>

Hello there, I keep having this test fail on the Galaxy API 101 training. I have done it over and over. I have checked my variables just to be sure I did not miss anything. Please can point me in the right direction on how to go about this.

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

Here is a public link to this collection:  
[https://documenter.getpostman.com/view/21279818/2s8YzMXk2c](https://documenter.getpostman.com/view/21279818/2s8YzMXk2c)

.

---

<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:** [December 4, 2022, 10:45am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/2 "2022-12-04T10:45:05Z")

</div>

Can you show where you’re using the `{{var_name}}` syntax in a URL for that Collection, please?

---

<div class="post-metadata">

**Author:** ![Larry\_O](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@Larry\_O](https://community.postman.com/u/Larry_O)\
**Post date:** [December 4, 2022, 10:47am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/3 "2022-12-04T10:47:43Z")

</div>

Hello danny, Do you mean something like this

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

---

<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:** [December 4, 2022, 10:59am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/4 "2022-12-04T10:59:26Z")

</div>

Do you have that variable set at the environment level and in both the initial and current fields?

I’m not familiar with that collection as I didn’t write it but there is a comment in the test script, that mentions it can only check the environment level.

---

<div class="post-metadata">

**Author:** ![Larry\_O](https://avatars.discourse-cdn.com/v4/letter/l/a9adbd/32.png) [@Larry\_O](https://community.postman.com/u/Larry_O)\
**Post date:** [December 4, 2022, 11:03am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/5 "2022-12-04T11:03:12Z")

</div>

No, I currently don’t have my variables saved as environment variables.  
They were saved to the collection.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/a/ba30652edec5a2dcb0fdb178ce4dbd2b30b92a7b.png)

---

<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:** [December 4, 2022, 12:54pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/6 "2022-12-04T12:54:46Z")

</div>

OK, try them in the environment variables instead and see if that has any impact on the results.

---

<div class="post-metadata">

**Author:** ![mpantir](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@mpantir](https://community.postman.com/u/mpantir)\
**Post date:** [December 13, 2022, 6:25pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/7 "2022-12-13T18:25:17Z")

</div>

I have the same issue, I tried to save it to the env as well, without success.

---

<div class="post-metadata">

**Author:** ![swapnil1pardeshi](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@swapnil1pardeshi](https://community.postman.com/u/swapnil1pardeshi)\
**Post date:** [December 14, 2022, 8:04am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/8 "2022-12-14T08:04:39Z")

</div>

i am also facing same issue. tried environment as well. but issue persist

---

<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:** [December 14, 2022, 6:07pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/9 "2022-12-14T18:07:33Z")

</div>

I have this training modules (and its still passing).

It doesn’t need to be environment variables. Mine are set at the collection level.

It looks like the test is failing on this element (not the line posted in the original screenshot).

```auto
    //auth should also use var
    pm.expect(encodeURI(authObj.apikey.value).indexOf('%7B%7B')).to.be.above(-1);

```

Suspect this is looking at the authentication which is set at the collection level and is using the email\_key variable. (It should be set at the collection level, not the ‘Learn APIs’ folder level).

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/d/cd4c6481e094496345bfdd99a18dda9169e99efc.png)

When you run the collection status request, it logs a fair bit of into to the console.log.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/0/b0d23fb85b21eabf37769d3db5ac2d0c26f179a8.png)

The first entry shows the auth settings. Can you confirm if the value is set to the email\_key variable?

---

<div class="post-metadata">

**Author:** ![swapnil1pardeshi](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@swapnil1pardeshi](https://community.postman.com/u/swapnil1pardeshi)\
**Post date:** [December 15, 2022, 4:00am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/10 "2022-12-15T04:00:40Z")

</div>

![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/5/b5d39b05b8f72cc5c702018388121977d1d6c3de.png)  
here it is creating two.

---

<div class="post-metadata">

**Author:** ![spacecraft-engineer4](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@spacecraft-engineer4](https://community.postman.com/u/spacecraft-engineer4)\
**Post date:** [December 15, 2022, 12:01pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/11 "2022-12-15T12:01:13Z")

</div>

Have you already sorted it out, cause I’m also struggling with the same problem. Apparently, we are not using the variables correctly, but other than that the internet seems to not have a solution for the problem.

---

<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:** [December 15, 2022, 12:02pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/12 "2022-12-15T12:02:52Z")

</div>

@swapnil1pardeshi

Which I suspect is incorrect.

It should be the one entry.

I suspect you have authentication at the collection (Galaxy APIs 101) and also the folder level (Learn APIs).

You probably need to remove it from the folder level.

---

<div class="post-metadata">

**Author:** ![swapnil1pardeshi](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@swapnil1pardeshi](https://community.postman.com/u/swapnil1pardeshi)\
**Post date:** [December 16, 2022, 3:08am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/13 "2022-12-16T03:08:16Z")

</div>

at folder level it is inherited from parent. i.e. (Galaxy APIs 101).  
and if i removed it from folder level , then it also throws some more test to be failed. like saying auth error. 😑

---

<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:** [December 16, 2022, 9:50am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/14 "2022-12-16T09:50:42Z")

</div>

@swapnil1pardeshi

Leave the inherit from parent on the folder. It should be inherit from parent everywhere else apart from the collection.

I can only assume that you have this set somewhere else. You’ll need to check each request an folder and ensure they are all set to inherit from parent.

---

<div class="post-metadata">

**Author:** ![timrohweder](https://avatars.discourse-cdn.com/v4/letter/t/4da419/32.png) [@timrohweder](https://community.postman.com/u/timrohweder)\
**Post date:** [December 20, 2022, 1:02am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/15 "2022-12-20T01:02:27Z")

</div>

I think the test contains an error.

It currently has this: pm.expect(encodeURI(authObj.apikey.value).indexOf(‘%7B%7B’)).to.be.above(-1);

But authObj.apikey contains an array, not an object. It appears the intent of the test is to ensure that there are {{ contained in the value of apikey to indicate that a variable is used rather than a hardcoded value. I believe the test should instead be this:

pm.expect(encodeURI(authObj.apikey[1].value).indexOf(‘%7B%7B’)).to.be.above(-1);

---

<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:** [December 20, 2022, 10:44am UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/16 "2022-12-20T10:44:58Z")

</div>

@timrohweder

I’ve still got this saved in my collections and although I loathe to say it, it works for me.

The `indexOf()` method returns the position of the first occurrence of a value in a string.

The `indexOf()` method returns -1 if the value is not found.

The `indexOf()` method is case sensitive

I still think that its because the candidates have the authentication set in more than one place, where it should be at the collection level and inherit from parent should be set everywhere else.

There should only be one apikey in the response and it should be set to {{email\_key}}

It shouldn’t be returning more than one element. Therefore authObj.apikey.value should normally work.

%7B in an URL is converted to {

So the test is basically testing to see if the authObj.apikey.value contains {{

---

<div class="post-metadata">

**Author:** ![chris-mccandless](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chris-mccandless](https://community.postman.com/u/chris-mccandless)\
**Post date:** [December 30, 2022, 8:12pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/17 "2022-12-30T20:12:30Z")

</div>

Did anyone figure out exactly what is causing this issue? I just finished the Galaxy API 101 training and, but im getting this error. Please help.

---

<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:** [January 1, 2023, 3:34pm UTC](https://community.postman.com/t/galaxy-api-101-used-variables-assertionerror-expected-1-to-be-above-1/41738/18 "2023-01-01T15:34:04Z")

</div>

@chris-mccandless

There is another thread for this, where I’ve detailed what is causing it.

> [@Collection status: Used variables | AssertionError: expected -1 to be above -1](https://community.postman.com/t/collection-status-used-variables-assertionerror-expected-1-to-be-above-1/41972/2):
>
> This seems to be catching a few people out, so I’ll try and explain what is happening. This is the test that is failing. pm.expect(encodeURI(authObj.apikey.value).indexOf('%7B%7B')).to.be.above(-1) authObj relates to the authentication. The indexOf() method returns the position of the first occurrence of a value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive %7B in an URL is converted to { This is what the encodeURI is doing…
