# Failed to associate api key with usage plan (Invalid API Identifier)

**URL:** <https://forum.serverless.com/t/failed-to-associate-api-key-with-usage-plan-invalid-api-identifier/16031>\
**Category:** Serverless Framework\
**Tags:** aws, lambda, api-gateway\
**Created:** [October 6, 2021, 10:54pm UTC](https://forum.serverless.com/t/failed-to-associate-api-key-with-usage-plan-invalid-api-identifier/16031 "2021-10-06T22:54:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpiv400](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@bpiv400](https://forum.serverless.com/u/bpiv400)\
**Post date:** [October 6, 2021, 10:54pm UTC](https://forum.serverless.com/t/failed-to-associate-api-key-with-usage-plan-invalid-api-identifier/16031/1 "2021-10-06T22:54:49Z")

</div>

Hi Serverless community,

I’m trying to add an API key to an api gateway activated lambda function, but I run into an error related to using an “Invalid API Identifier”. More below.

I’ve followed [this documentation](https://www.serverless.com/plugins/serverless-add-api-key) exactly, but my `serverless deploy` fails with the following error when I attempt to deploy:

```auto
AddApiKey: Creating new api key UnrestrictedUsageKey
AddApiKey: Created new api key UnrestrictedUsageKey:9mp219azw3
AddApiKey: Creating new usage plan UnrestrictedUsageKey-usage-plan
AddApiKey: Associating api key 9mp219azw3 with usage plan 1o93l4
AddApiKey: Failed to associate api key with usage plan. Error Invalid API identifier specified 425359244402:null
AddApiKey: Failed to add api key the service. Error Invalid API identifier specified 425359244402:null
AddApiKey: UnrestrictedUsageKey - hKSp8MQW6t5WXLGyAXUXD3oIyouVsBeJrUrbSsq7

```

I’m not sure where this API identifier is coming from. I’ve tried running `serverless remove` and re-executing to start from scratch, but I get the same error (with the same API identifier). It successfully deploys the new API and the function works as expected, but it still succeeds when I call it without an API key.

This is the relevant snippet from my `serverless.yaml`:

```auto
plugins:
  - serverless-add-api-key

custom:
  apiKeys:
    - name: UnrestrictedUsageKey

```

Any ideas to solve would be very much appreciated!

---

<div class="post-metadata">

**Author:** ![haochang](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/haochang/32/6790_2.png) [@haochang](https://forum.serverless.com/u/haochang)\
**Post date:** [April 29, 2022, 10:41am UTC](https://forum.serverless.com/t/failed-to-associate-api-key-with-usage-plan-invalid-api-identifier/16031/2 "2022-04-29T10:41:13Z")

</div>

Checked the code which needs `ServiceEndpoint` as output in the yml  
example

```auto
  Outputs:
    ServiceEndpoint:
      Description: API endpoint
      Value:
        Fn::Join:
        - ''
        - - 'https://'
          - Ref: ApiGatewayRestApi
          - '.execute-api.'
          - ${self:provider.region}
          - '.amazonaws.com/'
          - ${self:provider.stage}

```

---

<div class="post-metadata">

**Author:** ![pauldigz](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pauldigz](https://forum.serverless.com/u/pauldigz)\
**Post date:** [September 21, 2023, 8:05am UTC](https://forum.serverless.com/t/failed-to-associate-api-key-with-usage-plan-invalid-api-identifier/16031/3 "2023-09-21T08:05:27Z")

</div>

Hi, did you found the solution on this issue?
