Muitos dos comandos gcloud mostrados exigem que você especifique o ID da API, no formato: API_ID.
A API Gateway aplica os seguintes requisitos aos IDs da API:
Os valores têm comprimento máximo de 63 caracteres.
Use somente letras minúsculas, números ou hifens
Não pode começar com um traço.
Não pode conter um sublinhado.
Como criar uma API
Para criar uma API:
Valide o código do projeto retornado do seguinte comando para garantir que o serviço não seja criado no projeto incorreto.
gcloud config list project
Se você precisar mudar o projeto padrão, execute o seguinte comando
e substitua PROJECT_ID pelo ID do projeto Google Cloud
em que você quer criar o serviço:
gcloud config set project PROJECT_ID
Se o ID do projeto contiver dois pontos (:), consulte
Projetos com escopo de domínio para mais detalhes sobre como criar uma
API no projeto.
A CLI do Google Cloud usa muitas opções, incluindo as descritas na
Referência do gcloud. Além disso,
para o gateway de API, é possível definir as seguintes opções ao criar uma API:
--async: retorna o controle para o terminal imediatamente, sem aguardar a conclusão da operação.
--display-name=NAME: especifica o nome de exibição da API, o que significa o nome mostrado na IU. Não use espaços no nome. Use hifens e sublinhados. O valor padrão é API_ID.
--labels=KEY1=VALUE1,KEY2=VALUE2,...: especifica rótulos associados à configuração da API.
--managed-service: especifica um serviço gerenciado preexistente (por exemplo, um serviço do Endpoints) para a API
Projetos de escopo de domínio
Se o projeto tiver escopo para seu domínio, o código do projeto incluirá o nome do domínio seguido por dois pontos (::example.com:my-project). É preciso fornecer um serviço gerenciado válido ao criar uma API em um projeto com escopo de domínio.
Se estiver usando gcloud, forneça o nome do serviço gerenciado com a sinalização --managed-service, conforme descrito em opções do gcloud.
Como listar APIs
Liste todos os jobs de um projeto.
gcloud api-gateway apis list --project=PROJECT_ID
Esse comando retorna a saída no formato:
NAME DISPLAY_NAME MANAGED_SERVICE STATE
projects/PROJECT_ID/locations/global/apis/API_IDAPI_IDMANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog ACTIVE
Use o ID do projeto e o ID da API para receber informações detalhadas sobre ela:
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-03 UTC."],[[["\u003cp\u003eBefore creating an API, ensure your development environment is properly configured and meets the API ID requirements, which include a maximum length of 63 characters, lowercase letters, numbers, or dashes, and no starting dashes or underscores.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003egcloud api-gateway apis create API_ID --project=PROJECT_ID\u003c/code\u003e command to create a new API, where you specify the desired API ID and the Google Cloud project ID.\u003c/p\u003e\n"],["\u003cp\u003eAfter creation, the API's display name and labels can be updated using the \u003ccode\u003egcloud api-gateway apis update\u003c/code\u003e command with options like \u003ccode\u003e--display-name\u003c/code\u003e, \u003ccode\u003e--update-labels\u003c/code\u003e, \u003ccode\u003e--clear-labels\u003c/code\u003e, and \u003ccode\u003e--remove-labels\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo delete an API, you must first delete all associated API configs using \u003ccode\u003egcloud api-gateway api-configs delete\u003c/code\u003e, and then delete the API itself with \u003ccode\u003egcloud api-gateway apis delete\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eListing all the existing APIs within a project can be done with the following command \u003ccode\u003egcloud api-gateway apis list --project=PROJECT_ID\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Creating an API\n===============\n\nPrerequisites\n-------------\n\nBefore you can create an API on API Gateway, ensure that you have:\n\n- Prepared your development environment as described in [Configuring your development environment](/api-gateway/docs/configure-dev-env).\n\nAPI ID requirements\n-------------------\n\nMany of the `gcloud` commands shown require you to specify the ID of the API, in the form: \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e.\nAPI Gateway enforces the following requirements for the API ID:\n\n- Must have a maximum length of 63 characters.\n- Must contain only lowercase letters, numbers, or dashes.\n- Must not start with a dash.\n- Must not contain an underscore.\n\nCreating an API\n---------------\n\nTo create an API:\n\n1. Validate the project ID returned from the following command to make sure that\n the service isn't created in the wrong project.\n\n ```\n gcloud config list project\n ```\n\n If you need to change the default project, run the following command\n and replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with the Google Cloud project ID\n in which you want to create the service:: \n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n If your project ID contains a colon (`:`), see\n [Domain-scoped projects](#domain) for additional details about creating an\n API in your project.\n2. View help for the `apis create` command:\n\n ```\n gcloud api-gateway apis create --help\n ```\n3. Run the following command to create the API:\n\n ```\n gcloud api-gateway apis create API_ID --project=PROJECT_ID\n ```\n\n where:\n - \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e specifies the ID of the new API. See [API ID requirements](#api-id-requirements) for API naming guidelines.\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e specifies the Google Cloud project ID.\n\n As it is creating the API, API Gateway outputs information to the terminal.\n4. On successful completion, you can use the following command to view details about the new API:\n\n ```\n gcloud api-gateway apis describe API_ID --project=PROJECT_ID\n ```\n\n This command returns the following: \n\n ```scdoc\n createTime: '2020-02-29T21:52:20.297426875Z'\n displayName: API_ID\n managedService: MANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog\n name: projects/PROJECT_ID/locations/global/apis/API_ID\n state: ACTIVE\n updateTime: '2020-02-29T21:52:20.647923711Z'\n ```\n\n### gcloud options\n\nThe Google Cloud CLI takes many options, including those described in the\n[gcloud Reference](/sdk/gcloud/reference). In addition,\nfor API Gateway, you can set the following options when creating an API:\n\n- `--async`: Return control to the terminal immediately, without waiting for the operation to complete.\n- `--display-name=`\u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e: Specifies the display name of the API, meaning the name shown in the UI. Do not use spaces in the name. Use hyphens and underscores instead. The default value is \u003cvar translate=\"no\"\u003eAPI_ID\u003c/var\u003e.\n- `--labels=`\u003cvar translate=\"no\"\u003eKEY1\u003c/var\u003e`=`\u003cvar translate=\"no\"\u003eVALUE1\u003c/var\u003e`,`\u003cvar translate=\"no\"\u003eKEY2\u003c/var\u003e`=`\u003cvar translate=\"no\"\u003eVALUE2\u003c/var\u003e`,...`: Specifies labels associated with the API config.\n- `--managed-service`: Specifies a pre-existing managed service (for example, an existing Endpoints service) for the API.\n\n### Domain-scoped projects\n\nIf your project is scoped to your domain, the project ID includes the name of\nthe domain followed by a colon (`:`), for example, `example.com:my-project`. You\nmust provide a valid managed service when creating an API in a domain-scoped\nproject.\n\nIf using `gcloud`, provide the managed service name using the\n`--managed-service` flag, as described in\n[gcloud options](#gcloud-options).\n| **Note:** Scoping projects to a domain is a legacy feature. You cannot create new domain-scoped projects.\n\nListing APIs\n------------\n\nTo list all APIs in a project: \n\n```\ngcloud api-gateway apis list --project=PROJECT_ID\n```\n\nThis command returns output in the form: \n\n```scdoc\nNAME DISPLAY_NAME MANAGED_SERVICE STATE\nprojects/PROJECT_ID/locations/global/apis/API_ID API_ID MANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog ACTIVE\n```\n\nUse the project ID and API ID to obtain detailed information about the API: \n\n```\ngcloud api-gateway apis describe API_ID --project=PROJECT_ID\n```\n\nUpdating an API\n---------------\n\nAfter creation, you can update the labels and display name of an existing API.\nUse the following `gcloud` options to update an existing API:\n\n- `--display-name`\n- `--update-labels`\n- `--clear-labels`\n- `--remove-labels`\n\nFor example: \n\n```\ngcloud api-gateway apis update API_ID --project=PROJECT_ID \\\n --update-labels=a=1,b=2\n```\n\nUse the following command to view all update options: \n\n```\ngcloud api-gateway apis update --help\n```\n\nDeleting an API\n---------------\n\nTo delete an API you must:\n\n- Delete the API configs associated with the API.\n- Delete the API.\n\n| **Note:** If you deployed an API config to a gateway, then deleting the API causes the gateway to stop serving traffic. However, you are not required to delete the gateway. Instead, you can deploy an API config from a different API to the gateway.\n\nTo delete an API:\n\n1. Determine the list of API configs associated with the API:\n\n ```\n gcloud api-gateway api-configs list --api=API_ID --project=PROJECT_ID\n ```\n2. Delete each API config associated with the API:\n\n ```\n gcloud api-gateway api-configs delete CONFIG_ID --api=API_ID --project=PROJECT_ID\n ```\n3. Delete the API:\n\n ```\n gcloud api-gateway apis delete API_ID --project=PROJECT_ID\n ```\n\nWhat's next\n-----------\n\n- [Creating an API config](/api-gateway/docs/creating-api-config)"]]