---
id: api-key-update
title: "Update an API key"
description: "Updates an API key by ID."
sidebar_label: "Update an API key"
hide_title: true
hide_table_of_contents: true
api: eJzdWe9u28gRf5XFfmkCUBLlWMmVQA7Q2VecemjOsGXctbZhrLkjas/kLrN/rKiCvvV7X6d9nb5AX6GYXVIkJSVSguR6d4JBi9T+mfnN/GZmhyvKwaRalFYoSRN6XXJmwRAmyfhiQh5hSR6WZHLev5U0oqoEzXDkhNOEslLcP8IycX4OjaiB1GlhlzS5WdEHYBr02Nk5TW7u1ncRtSwzNLmh1cKG3kW0ZJoVYEEbP0myAmhCBacRFShPyeycRltCTudAnBRvHRDBQVoxE6DJTGli51DLHSTW8NYJDZwmVjuIqEnnUDCarKhdln4raSEDTdcRhXesKHOgyfDkxSkKjJPB2G8UX+KMVEkL0uJXVpa5SD0Ug58NCrVqLV1qBMoKMHgXdNpsaKwWMtvRaUw2909AcM6OQihjppm0prUc05otd1Y7h5mQaMY0BWNImOUXbAwbABIWivZ66uFnSC3aWsIPM2+U7V8aTG+o1B5llcO9yV3mTdrVXsvDyqNB31y+IWrmFdZglNMpkMUcNLQx+IMhuBcRhjBjRCaB92nLclTpjEnxd2+Z18OEpaly0r4eJoioKVkK+LSx3utTRLWR/yhRceRGVhSnloVY1Za2sqAwqFz/Vt7Kr8kbZSEhVwDk5lLlYO6eDbhKzYA5O1e6knyAq5rnfn6hNBAhZ6p/K7/2Jmu0LVg6FxKSVND1OqJWWP84mBuXv0Kd1tHRNhT8t2xBwfcQe5+kk/Nfg/lexfGL4atXo5f7bTfhdH3nf/Jx8wDjpyzziKpUMAucLISdk6VyugkfHyB71+KPsDzC4izzIB3as7Hs2QQt9cRyd0Q8xOX90I/YoGBC0jV+GjyrJPWjFhZaQd7rWdv5WRUfnREyI5tg8BzHbMStUlOx7FWs65VaYXTt2TmzvYXI814Itz3p8rzMmZ0pXdAmZt9UXPoUF+/EqA7vm8RaGa7+lW6wppj7Kmf6gM6C/wo1Rk4PvxqNXr46OXkZf5y2wRM0m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4DAhWjVUvdx0Q+iUfXlT3U+/fOPU58okX+XTUv92xqKTadhg+yX7ZhEn6cr0bTvdpsSZ5NWPyKcde7W+EpjpnyLBbQJXjPsx/2YNkXEuN1HRP8rlbEFky2Uwiua1qln2xVbbyoOvM+pDGnhnR2UeXVM916yqvzppm6g0YgmoTs8V8biD6vVAzNwrfP1Gh+/daDxzc8dKq5FKNVuVpQLg985TWYsN9uFW1vWZ5dV+H1OPuINz14d6pOkXLbsQKPKOoIHc8yBcdBtswVZelOc3kzcSSLoQmHGOE2htB8ce9ci68V4evYdMqR6pVT4SE01W6BnsUWQUnlwPPH8sxXNmcycD0M0LIp8Yl06btGv/eqmi8NqFUZM1SPI9XoDi8X70Dj7Hx55md0=
sidebar_class_name: "patch api-method"
info_path: docs/api/authorization
custom_edit_url: null
---

import MethodEndpoint from "@theme/ApiExplorer/MethodEndpoint";
import ParamsDetails from "@theme/ParamsDetails";
import RequestSchema from "@theme/RequestSchema";
import StatusCodes from "@theme/StatusCodes";
import OperationTabs from "@theme/OperationTabs";
import TabItem from "@theme/TabItem";
import Heading from "@theme/Heading";

<Heading
  as={"h1"}
  className={"openapi__heading"}
  children={"Update an API key"}
>
</Heading>

<MethodEndpoint
  method={"patch"}
  path={"/api_key/{id}"}
  context={"endpoint"}
>
  
</MethodEndpoint>



Updates an API key by ID.


<Heading
  id={"request"}
  as={"h2"}
  className={"openapi-tabs__heading"}
  children={"Request"}
>
</Heading>

<ParamsDetails
  parameters={[{"name":"id","in":"path","description":"The unique identifier for the API key.\n","required":true,"schema":{"type":"integer"},"example":1234}]}
>
  
</ParamsDetails>

<RequestSchema
  title={"Body"}
  body={{"content":{"application/json":{"schema":{"properties":{"name":{"type":"string","description":"A descriptive name for the API key."},"grants":{"type":"array","description":"Defines access grants for an API key.\n","items":{"type":"object","oneOf":[{"type":"object","required":["nrn","role_slug"],"properties":{"nrn":{"type":"string","description":"The NRN of the resource where the API key's role is assigned.","example":"organization=1:account=1:namespace=1:application=4"},"role_slug":{"type":"string","description":"The slug of the role assigned to the API key for this NRN.\n\n> Note: See [Roles](/docs/authorization/roles) for more info.\n>\n","example":"machine:ci"}},"title":"grantsRoleSlug"},{"type":"object","required":["nrn","role_id"],"properties":{"nrn":{"type":"string","description":"The NRN of the resource where the API key's role is assigned.","example":"organization=1:account=1:namespace=1:application=4"},"role_id":{"type":"integer","description":"The ID of the role assigned to the API key for this NRN.\n\n> Note: See [Roles](/docs/authorization/roles) for more info.\n>\n","example":700317756}},"title":"grantsRoleId"}]}},"tags":{"type":"array","description":"Tags associated with your API key.","items":{"type":"object","properties":{"key":{"type":"string","description":"Tag key associated with your API key.","example":"CI"},"value":{"type":"string","description":"Tag value associated with your API key.","example":"main"}}}}},"title":"api_keyWrite"},"examples":{"API key (grants using role_slug)":{"value":{"name":"my-machine-process-that-will-access-nullplatform","grants":[{"nrn":"organization=1:account=1:namespace=1:application=4","role_slug":"machine:ci"}],"tags":[{"key":"machine","value":"true"}]}},"API key (grants using role_id)":{"value":{"name":"my-machine-process-that-will-access-nullplatform","grants":[{"nrn":"organization=1:account=1:namespace=1:application=4","role_id":1855672260}],"tags":[{"key":"machine","value":"true"}]}}}}}}}
>
  
</RequestSchema>

<StatusCodes
  id={undefined}
  label={undefined}
  responses={{"200":{"description":"The operation was successful.","content":{"application/json":{"schema":{"type":"object","required":["id","name","tags","grants","created_at","updated_at"],"properties":{"id":{"type":"integer","description":"Unique ID for the API key.","example":1234},"name":{"type":"string","description":"The descriptive name given to the API key.","example":"CI/CD Main"},"masked_api_key":{"type":"string","description":"Your masked API key.","example":"AAAA.xxxxxxxxxxxxxxxxxxxxxPTs=","nullable":true},"tags":{"type":"array","description":"Array of tags associated with your API key.\n\nℹ️ If no tags are found, we return an empty array.\n","items":{"type":"object","required":["key","value"],"properties":{"key":{"type":"string","description":"Tag key associated with your API key.","example":"CI"},"value":{"type":"string","description":"Tag value associated with your API key.","example":"main"}}}},"grants":{"type":"array","description":"Defines access grants for an API key.","items":{"type":"object","required":["nrn","role_id","role_slug"],"properties":{"nrn":{"type":"string","description":"The NRN of the resource where the API key's role is assigned.","example":"organization=1:account=1:namespace=1:application=4"},"role_id":{"type":"integer","description":"The ID of the role assigned to the API key for this NRN.","example":1855672260},"role_slug":{"type":"string","description":"The slug of the role assigned to the API key for this NRN.","example":"machine:ci"}}}},"owner_id":{"type":"integer","description":"The unique ID of the user that creates the API key.","example":1595},"last_used_at":{"type":"string","description":"The ISO-8601 UTC timestamp of when the API key was last used.","nullable":true,"format":"date-time","example":"2021-01-02T00:00:00Z"},"created_at":{"type":"string","description":"The ISO-8601 UTC timestamp of when the API key was created.","format":"date-time","example":"2021-01-02T00:00:00Z"},"updated_at":{"type":"string","nullable":true,"description":"The ISO-8601 UTC timestamp of when the API key was last updated.","format":"date-time","example":"2021-01-02T00:00:00Z"}},"title":"apiKeyResponse"}}}},"4XX":{"description":"Client error responses due to invalid input or missing parameters.","content":{"application/json":{"schema":{"type":"object","required":["statusCode","error","message"],"properties":{"statusCode":{"type":"integer","description":"HTTP status code representing the specific client error (e.g., 400, 401, 403, 404).","example":400},"code":{"type":"string","description":"A machine-readable error code that categorizes the server failure.","example":"bad_request"},"error":{"type":"string","description":"A brief, human-readable description of the error type (e.g., \"Bad Request\", \"Unauthorized\").","example":"Bad Request"},"message":{"type":"string","description":"Additional details about the error.","example":"The request was malformed or contained invalid parameters."}}}}}},"5XX":{"description":"Server error responses indicating an issue on the API side.","content":{"application/json":{"schema":{"type":"object","required":["statusCode","error","message"],"properties":{"statusCode":{"type":"integer","description":"HTTP status code representing the specific server error (e.g., 500, 502, 503).","example":500},"code":{"type":"string","description":"A machine-readable error code that categorizes the server failure.","example":"internal_server_error"},"error":{"type":"string","description":"A brief, human-readable description of the error type (e.g., \"Internal Server Error\", \"Service Unavailable\").","example":"Internal Server Error"},"message":{"type":"string","description":"Additional details about the error.","example":"An unexpected error occurred. Please try again later."}}}}}}}}
>
  
</StatusCodes>


      