Bei vielen der unten aufgeführten gcloud-Befehle müssen Sie die ID der API im folgenden Format angeben: API_ID.
In API Gateway gelten folgende Anforderungen für die API-ID:
Muss eine maximale Länge von 63 Zeichen haben.
Darf nur Kleinbuchstaben, Ziffern oder Bindestriche enthalten.
Er darf nicht mit einem Bindestrich beginnen.
Er darf keinen Unterstrich enthalten.
API erstellen
So erstellen Sie eine API:
Überprüfen Sie anhand der Projekt-ID, die vom folgenden Befehl zurückgegeben wurde, ob der Dienst im richtigen Projekt erstellt wird.
gcloud config list project
Wenn Sie das Standardprojekt ändern müssen, führen Sie den folgenden Befehl aus und ersetzen Sie PROJECT_ID durch die ID des Google Cloud Projekts, in dem Sie den Dienst erstellen möchten:
gcloud config set project PROJECT_ID
Wenn die Projekt-ID einen Doppelpunkt (:) enthält, finden Sie unter Auf Domains beschränkte Projekte weitere Informationen zum Erstellen einer API in Ihrem Projekt.
Hier erhalten Sie Hilfe zum Befehl apis create:
gcloud api-gateway apis create --help
Führen Sie den folgenden Befehl aus, um die API zu erstellen:
Die Google Cloud CLI hat viele Optionen, einschließlich der in der gcloud-Referenz beschriebenen. Darüber hinaus können Sie für API Gateway beim Erstellen einer API die folgenden Optionen festlegen:
--async: Gibt die Steuerung sofort an das Terminal zurück, ohne auf den Abschluss des Vorgangs zu warten.
--display-name=NAME: Gibt den Anzeigenamen der API an, d. h. den in der Benutzeroberfläche angezeigten Namen. Verwenden Sie keine Leerzeichen im Namen. Verwenden Sie stattdessen Bindestriche und Unterstriche. Der Standardwert ist API_ID.
--labels=KEY1=VALUE1,KEY2=VALUE2,...: Gibt Labels an, die der API-Konfiguration zugeordnet sind.
--managed-service: Gibt einen bereits verwalteten Dienst für die API an, z. B. einen vorhandenen Endpoints-Dienst.
Auf Domains beschränkte Projekte
Wenn Ihr Projekt auf eine Domain beschränkt ist, umfasst die Projekt-ID den Namen der Domain mit einem Doppelpunkt (:), z. B. example.com:my-project. Sie müssen einen gültigen verwalteten Dienst angeben, wenn Sie eine API in einem Projekt auf Domainebene erstellen.
Wenn Sie gcloud verwenden, geben Sie den Namen des verwalteten Dienstes mit dem Flag --managed-service an, wie in den gcloud-Optionen beschrieben.
Listing APIs
So listen Sie alle APIs in einem Projekt auf:
gcloud api-gateway apis list --project=PROJECT_ID
Dieser Befehl gibt die folgende Ausgabe zurück:
NAME DISPLAY_NAME MANAGED_SERVICE STATE
projects/PROJECT_ID/locations/global/apis/API_IDAPI_IDMANAGED_SERVICE_NAME.apigateway.PROJECT_ID.cloud.goog ACTIVE
Verwenden Sie die Projekt- und API-ID, um detaillierte Informationen zur API zu erhalten:
Nach dem Erstellen können Sie die Labels und den Anzeigenamen einer vorhandenen API aktualisieren.
Verwenden Sie die folgenden gcloud-Optionen, um eine vorhandene API zu aktualisieren:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)"]]