# revoke - API Key Module Reference

This documentation provides a reference to the `revoke` method. This belongs to the API Key Module.

You should only use this methods when implementing complex customizations. For common cases, check out [available workflows instead](https://docs.medusajs.com/medusa-workflows-reference).

## revoke(selector, data, sharedContext?): Promise\<[ApiKeyDTO](https://docs.medusajs.com/var/task/www/apps/resources/references/api_key/interfaces/api_key.ApiKeyDTO)\[]>

This method revokes API keys based on the filters provided.

### Example

```ts
const apiKey = await apiKeyModuleService.revoke(
  {
    id: "apk_123",
  },
  {
    revoked_by: "user_123",
    // 1 minute
    revoke_in: 60,
  }
)
```

### Parameters

- selector: (\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)) The filters to specify which API keys should be revoked.

  - q: (\`string\`) Search through the api key names and redacted keys using this search term.

  - id: (\`string\` \\| \`string\`\[]) The IDs to filter the API keys by.

  - token: (\`string\` \\| \`string\`\[]) The tokens to filter the API keys by.

  - title: (\`string\` \\| \`string\`\[]) The titles to filter the API keys by.

  - type: (\[ApiKeyType]\(../../../types/api\_key.ApiKeyType/page.mdx)) Filter the API keys by their type.

  - revoked\_at: (\[OperatorMap]\(../../../types/api\_key.OperatorMap/page.mdx)\&#60;null \\| Date\&#62;)

    - $and: (\[Query]\(../../../types/api\_key.Query/page.mdx)\&#60;T\&#62;\[])

    - $or: (\[Query]\(../../../types/api\_key.Query/page.mdx)\&#60;T\&#62;\[])

    - $eq: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62; \\| \[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;\[])

    - $ne: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;)

    - $in: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;\[])

    - $nin: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;\[])

    - $not: (\[Query]\(../../../types/api\_key.Query/page.mdx)\&#60;T\&#62;) API wrapper around the remoteQuery

    - $gt: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;)

    - $gte: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;)

    - $lt: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;)

    - $lte: (\[ExpandScalar]\(../../../types/api\_key.ExpandScalar/page.mdx)\&#60;T\&#62;)

    - $like: (\`string\`)

    - $re: (\`string\`)

    - $ilike: (\`string\`)

    - $fulltext: (\`string\`)

    - $overlap: (\`string\`\[])

    - $contains: (\`string\`\[])

    - $contained: (\`string\`\[])

    - $exists: (\`boolean\`)

  - $and: ((\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx) \\| \[BaseFilterable]\(../../../interfaces/api\_key.BaseFilterable/page.mdx)\&#60;\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)\&#62;)\[]) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.

    - q: (\`string\`) Search through the api key names and redacted keys using this search term.

    - id: (\`string\` \\| \`string\`\[]) The IDs to filter the API keys by.

    - token: (\`string\` \\| \`string\`\[]) The tokens to filter the API keys by.

    - title: (\`string\` \\| \`string\`\[]) The titles to filter the API keys by.

    - type: (\[ApiKeyType]\(../../../types/api\_key.ApiKeyType/page.mdx)) Filter the API keys by their type.

    - revoked\_at: (\[OperatorMap]\(../../../types/api\_key.OperatorMap/page.mdx)\&#60;null \\| Date\&#62;)

    - $and: ((\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx) \\| \[BaseFilterable]\(../../../interfaces/api\_key.BaseFilterable/page.mdx)\&#60;\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)\&#62;)\[]) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.

    - $or: ((\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx) \\| \[BaseFilterable]\(../../../interfaces/api\_key.BaseFilterable/page.mdx)\&#60;\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)\&#62;)\[]) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.

  - $or: ((\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx) \\| \[BaseFilterable]\(../../../interfaces/api\_key.BaseFilterable/page.mdx)\&#60;\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)\&#62;)\[]) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.

    - q: (\`string\`) Search through the api key names and redacted keys using this search term.

    - id: (\`string\` \\| \`string\`\[]) The IDs to filter the API keys by.

    - token: (\`string\` \\| \`string\`\[]) The tokens to filter the API keys by.

    - title: (\`string\` \\| \`string\`\[]) The titles to filter the API keys by.

    - type: (\[ApiKeyType]\(../../../types/api\_key.ApiKeyType/page.mdx)) Filter the API keys by their type.

    - revoked\_at: (\[OperatorMap]\(../../../types/api\_key.OperatorMap/page.mdx)\&#60;null \\| Date\&#62;)

    - $and: ((\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx) \\| \[BaseFilterable]\(../../../interfaces/api\_key.BaseFilterable/page.mdx)\&#60;\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)\&#62;)\[]) An array of filters to apply on the entity, where each item in the array is joined with an "and" condition.

    - $or: ((\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx) \\| \[BaseFilterable]\(../../../interfaces/api\_key.BaseFilterable/page.mdx)\&#60;\[FilterableApiKeyProps]\(../../../interfaces/api\_key.FilterableApiKeyProps/page.mdx)\&#62;)\[]) An array of filters to apply on the entity, where each item in the array is joined with an "or" condition.
- data: (\[RevokeApiKeyDTO]\(../../../interfaces/api\_key.RevokeApiKeyDTO/page.mdx)) The details of revoking the API keys.

  - revoked\_by: (\`string\`) Who revoked the API key.

  - revoke\_in: (\`number\`) When to revoke the API key (time in seconds).
- sharedContext: (\[Context]\(../../../interfaces/api\_key.Context/page.mdx)) A context used to share resources, such as transaction manager, between the application and the module.

  - transactionManager: (TManager) An instance of a transaction manager of type \`TManager\`, which is a typed parameter passed to the context to specify the type of the \`transactionManager\`.

  - manager: (TManager) An instance of a manager, typically an entity manager, of type \`TManager\`, which is a typed parameter passed to the context to specify the type of the \`manager\`.

  - isolationLevel: (\`string\`) A string indicating the isolation level of the context. Possible values are \`READ UNCOMMITTED\`, \`READ COMMITTED\`, \`REPEATABLE READ\`, or \`SERIALIZABLE\`.

  - enableNestedTransactions: (\`boolean\`) A boolean value indicating whether nested transactions are enabled.

  - eventGroupId: (\`string\`) A string indicating the ID of the group to aggregate the events to be emitted at a later point.

  - transactionId: (\`string\`) A string indicating the ID of the current transaction.

  - runId: (\`string\`) A string indicating the ID of the current run.

  - messageAggregator: (\[IMessageAggregator]\(../../../interfaces/api\_key.IMessageAggregator/page.mdx)) An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.

  - requestId: (\`string\`) A string indicating the ID of the current request.

  - idempotencyKey: (\`string\`) A string indicating the idempotencyKey of the current workflow execution.

  - parentStepIdempotencyKey: (\`string\`) A string indicating the idempotencyKey of the parent workflow execution.

  - preventReleaseEvents: (\`boolean\`) preventReleaseEvents

  - isCancelling: (\`boolean\`) A boolean value indicating whether the current workflow execution is being cancelled.

  - cancelingFromParentStep: (\`boolean\`) Weither or not a sub workflow cancellation is being triggered from a parent step.
    If true, the parent step will not be triggered by the sub workflow.

### Returns

- Promise: (Promise\&#60;\[ApiKeyDTO]\(../../../interfaces/api\_key.ApiKeyDTO/page.mdx)\[]\&#62;) The revoked API keys.

  - ApiKeyDTO\[]: (\[ApiKeyDTO]\(../../../interfaces/api\_key.ApiKeyDTO/page.mdx)\[])

    - id: (\`string\`) The ID of the API key.

    - token: (\`string\`) The token of the API key.

    - redacted: (\`string\`) The redacted form of the API key's token. This is useful
      when showing portion of the token. For example \`sk\_...123\`.

    - title: (\`string\`) The title of the API key.

    - type: (\[ApiKeyType]\(../../../types/api\_key.ApiKeyType/page.mdx)) The type of the API key.

    - last\_used\_at: (\`null\` \\| \`Date\`) The date the API key was last used.

    - created\_by: (\`string\`) Who created the API key.

    - created\_at: (\`Date\`) The date the API key was created.

    - updated\_at: (\`Date\`) The date the API key was updated.

    - deleted\_at: (\`null\` \\| \`Date\`) The date the API key was deleted.

    - revoked\_by: (\`null\` \\| \`string\`) Who revoked the API key. For example,
      the ID of the user that revoked it.

    - revoked\_at: (\`null\` \\| \`Date\`) The date the API key was revoked.

## revoke(id, data, sharedContext?): Promise\<[ApiKeyDTO](https://docs.medusajs.com/var/task/www/apps/resources/references/api_key/interfaces/api_key.ApiKeyDTO)>

This method revokes an API key based on the ID provided.

### Example

```ts
const apiKey = await apiKeyModuleService.revoke("apk_123", {
  revoked_by: "user_123",
  // 1 minute
  revoke_in: 60,
})
```

### Parameters

- id: (\`string\`) The ID of the API key to revoke.
- data: (\[RevokeApiKeyDTO]\(../../../interfaces/api\_key.RevokeApiKeyDTO/page.mdx)) The details of revoking the API key.

  - revoked\_by: (\`string\`) Who revoked the API key.

  - revoke\_in: (\`number\`) When to revoke the API key (time in seconds).
- sharedContext: (\[Context]\(../../../interfaces/api\_key.Context/page.mdx)) A context used to share resources, such as transaction manager, between the application and the module.

  - transactionManager: (TManager) An instance of a transaction manager of type \`TManager\`, which is a typed parameter passed to the context to specify the type of the \`transactionManager\`.

  - manager: (TManager) An instance of a manager, typically an entity manager, of type \`TManager\`, which is a typed parameter passed to the context to specify the type of the \`manager\`.

  - isolationLevel: (\`string\`) A string indicating the isolation level of the context. Possible values are \`READ UNCOMMITTED\`, \`READ COMMITTED\`, \`REPEATABLE READ\`, or \`SERIALIZABLE\`.

  - enableNestedTransactions: (\`boolean\`) A boolean value indicating whether nested transactions are enabled.

  - eventGroupId: (\`string\`) A string indicating the ID of the group to aggregate the events to be emitted at a later point.

  - transactionId: (\`string\`) A string indicating the ID of the current transaction.

  - runId: (\`string\`) A string indicating the ID of the current run.

  - messageAggregator: (\[IMessageAggregator]\(../../../interfaces/api\_key.IMessageAggregator/page.mdx)) An instance of a message aggregator, which is used to aggregate messages to be emitted at a later point.

  - requestId: (\`string\`) A string indicating the ID of the current request.

  - idempotencyKey: (\`string\`) A string indicating the idempotencyKey of the current workflow execution.

  - parentStepIdempotencyKey: (\`string\`) A string indicating the idempotencyKey of the parent workflow execution.

  - preventReleaseEvents: (\`boolean\`) preventReleaseEvents

  - isCancelling: (\`boolean\`) A boolean value indicating whether the current workflow execution is being cancelled.

  - cancelingFromParentStep: (\`boolean\`) Weither or not a sub workflow cancellation is being triggered from a parent step.
    If true, the parent step will not be triggered by the sub workflow.

### Returns

- Promise: (Promise\&#60;\[ApiKeyDTO]\(../../../interfaces/api\_key.ApiKeyDTO/page.mdx)\&#62;) The revoked API key.

  - id: (\`string\`) The ID of the API key.

  - token: (\`string\`) The token of the API key.

  - redacted: (\`string\`) The redacted form of the API key's token. This is useful
    when showing portion of the token. For example \`sk\_...123\`.

  - title: (\`string\`) The title of the API key.

  - type: (\[ApiKeyType]\(../../../types/api\_key.ApiKeyType/page.mdx)) The type of the API key.

  - last\_used\_at: (\`null\` \\| \`Date\`) The date the API key was last used.

  - created\_by: (\`string\`) Who created the API key.

  - created\_at: (\`Date\`) The date the API key was created.

  - updated\_at: (\`Date\`) The date the API key was updated.

  - deleted\_at: (\`null\` \\| \`Date\`) The date the API key was deleted.

  - revoked\_by: (\`null\` \\| \`string\`) Who revoked the API key. For example,
    the ID of the user that revoked it.

  - revoked\_at: (\`null\` \\| \`Date\`) The date the API key was revoked.


---

The best way to deploy Medusa is through Medusa Cloud where you get autoscaling production infrastructure fine tuned for Medusa. Create an account by signing up at cloud.medusajs.com/signup.
