# Getting the "Invalid ApiKey for given resource" error

**URL:** <https://discuss.google.dev/t/getting-the-invalid-apikey-for-given-resource-error/4298>\
**Category:** Apigee\
**Tags:** api-runtime\
**Created:** [February 1, 2018, 6:09am UTC](https://discuss.google.dev/t/getting-the-invalid-apikey-for-given-resource-error/4298 "2018-02-01T06:09:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adevegowda](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/adevegowda/32/93606_2.png) [@adevegowda](https://discuss.google.dev/u/adevegowda)\
**Post date:** [February 1, 2018, 6:09am UTC](https://discuss.google.dev/t/getting-the-invalid-apikey-for-given-resource-error/4298/1 "2018-02-01T06:09:59Z")

</div>

We are getting the 401 Unauthorized response code with the below error:

```auto
{"fault":
   {
    "faultstring":"Invalid ApiKey for given resource",
    "detail":
       {
          "errorcode":"oauth.v2.InvalidApiKeyForGivenResource"
       }
   }
}

```

The curl command used is as follows:

```auto
curl -X GET "https://myorg-test.apigee.net/v1/profit_centers?page=2&size=25" -H "accept: application/json" -H "bypass-cache: false" -H "ApiKey: <API-Key>"

```

I have confirmed that the APIKey is correct.

---

<div class="post-metadata">

**Author:** ![adevegowda](https://d3byx8b92xw3lq.cloudfront.net/user_avatar/discuss.google.dev/adevegowda/32/93606_2.png) [@adevegowda](https://discuss.google.dev/u/adevegowda)\
**Post date:** [February 1, 2018, 6:46am UTC](https://discuss.google.dev/t/getting-the-invalid-apikey-for-given-resource-error/4298/2 "2018-02-01T06:46:17Z")

</div>

1. Checked the base path of the API and found that it was “/v1/profit\_centers”

2. Next looked into the VerifyAPIKey policy and confirmed that the ApiKey was accepted as a header.

```auto
<APIKey ref="request.header.ApiKey"/>

```

1. Checked the API Product associated with the specific API Proxy and found the following issues:

**Issue #1**

The API Product allow the requests only for the “dev” environment. But the calls were made to “test” environment.

**Solution:**

Modified the API Product to allow the API calls for “test” environment.

**Issue #2**

The Resource Path in the API Product was incorrectly set as follows:

```auto
"/v1/profit_centers**" 

```

Please note the Resource Path applies to the path suffix after the base path. Since the basepath of the API Proxy is “/v1/profit\_centers”, we don’t need to include in the Resource Path.

**Solution:**

Modify the Resource Path to include what you want to allow in the path after the base path.

For ex:  
We could set the Resource Path as “/”, this will allow the base path /v1/profit\_centers followed by anything like the ones shown below in your URL

```auto
/v1/profit_centers
/v1/profit_centers/
/v1/profit_centers/1 

```

For more details on how to set the Resource Path, refer to the below link

[https://docs.apigee.com/developer-services/content/create-api-products#configuring-the-behavior-of-a-resource-path-of](https://docs.apigee.com/developer-services/content/create-api-products#configuring-the-behavior-of-a-resource-path-of)

After making the above modifications, the API started giving successful results.
