Creating App Engine Applications with the Admin API

Region ID

The REGION_ID is an abbreviated code that Google assigns based on the region you select when you create your app. The code does not correspond to a country or province, even though some region IDs may appear similar to commonly used country and province codes. For apps created after February 2020, REGION_ID.r is included in App Engine URLs. For existing apps created before this date, the region ID is optional in the URL.

Learn more about region IDs.

Use the App Engine Admin API to programmatically create App Engine applications in new Google Cloud projects. By using both the Admin API along with the Cloud Resource Manager API, you are able to programmatically manage Google Cloud projects and App Engine applications.

Creating an App Engine application creates an Application resource for a target Google Cloud project in the specified location.

To manually create an App Engine application in a Google Cloud project, see the Managing Projects, Applications, and Billing topic for your language in either the standard environment or flexible environment.

Before you begin

You must meet the following prerequisites before you can create an App Engine application using the Admin API:

  • You must create or have an existing Google Cloud project.
  • You must be the owner of the target Google Cloud project.
  • You must be able to access the Admin API.

Before any other user account can perform tasks on an App Engine application, the Google Cloud project owner must first create the Application resource. For example, you must create the App Engine application before a user account with the App Engine Deployer role can deploy an app using a service account.

To create a Google Cloud project:

API

To programmatically create a Google Cloud project, you can use the Cloud Resource Manager API, see Creating a New Project for details. See a short example.

Console

To create create a Google Cloud project using the Google Cloud console:

Go to the Projects page

gcloud

After installing the Google Cloud CLI, you can run the following command of the gcloud CLI to create a Google Cloud project:

gcloud projects create

If you choose to use an existing Google Cloud project, you must ensure that the project does not already contain the Application resource because projects support only a single App Engine application. To check if your Google Cloud project already contains the Application resource, you can use either the apps.get method or run the gcloud app describe command.

Creating an App Engine application

To create an App Engine application with the Admin API:

  1. Authorize your HTTP requests, for example obtain an access token.

    Authorizing access to the Admin API can be accomplished with different OAuth flows depending on the needs of your API app. For more information, see Accessing the API.

  2. Send an HTTP POST request using your access token and the Admin API to create an App Engine application.

    You define the Application resource and target Google Cloud project in the HTTP POST request, for example:

    POST https://appengine.googleapis.com/v1/apps { "id": "[MY_PROJECT_ID]", "locationId": "[MY_APP_LOCATION]" }
    

    Required HTTP request fields:

    • id: The project ID of the target Google Cloud project in which you want to create an App Engine application.

    • locationId: The name of the geographic region in which the App Engine application is located as listed in App Engine Locations, for example us-east1.

      For a complete list of supported locations, you can use the apps.locations.list method.

      Example: Authorize and execute this example request in the APIs Explorer to view a current list of supported locations.

    See Application resource for the complete list of field options.

    Example cURL command:

    curl -X POST -d "{ 'id': '[MY_PROJECT_ID]', 'locationId': '[MY_APP_LOCATION]' }" -H "Content-Type: application/json" -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://appengine.googleapis.com/v1/apps
    

    Where:

    • [MY_PROJECT_ID] is the ID of target project where you want to create your App Engine application.
    • [MY_APP_LOCATION] is the location where you want to create your App Engine application.
    • [MY_ACCESS_TOKEN] is the access token that you obtained to authorize your HTTP requests.

    Example response:

    {
      "name": "apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450f",
      "metadata": {
        "@type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1",
        "method": "google.appengine.v1.Applications.CreateApplication",
        "insertTime": "2016-10-03T20:48:02.099Z",
        "user": "me@example.com",
        "target": "apps/[MY_PROJECT_ID]"
      }
    }
    
  3. Verify that your App Engine application was created:

    1. View the status of the actual creation operation:

      The HTTP POST request that you used in the previous step returned the operation name in the name field, which you use with the GET method of the apps.operations collection to check the status of the creation operation.

      For example, if the name field of the response is:

      "name": "apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450f"
      

      Then you send the following HTTP GET request:

      GET https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450f
      

      Example cURL command:

      curl -X GET -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450f
      

      Where [MY_ACCESS_TOKEN] is your access token and [MY_PROJECT_ID] is the ID of target project.

      Example response:

      {
        "name": "apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450f",
        "metadata": {
          "@type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1",
          "method": "google.appengine.v1.Applications.CreateApplication",
          "insertTime": "2016-10-03T20:48:02.099Z",
          "endTime": "2016-10-03T20:48:18.272Z",
          "user": "me@example.com",
          "target": "apps/[MY_PROJECT_ID]"
        },
        "done": true,
        "response": {
          "@type": "type.googleapis.com/google.appengine.v1.Application",
          "id": "[MY_PROJECT_ID]",
          "locationId": "[MY_APP_LOCATION]"
        }
      }
      
    2. Verify that the App Engine application was created in your project:

      To view details about the version, you use the GET method of the apps collection. You must specify the project that you deployed in the HTTP GET request, for example:

      GET https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]
      

      Example cURL command:

      curl -X GET -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/
      

      Where [MY_ACCESS_TOKEN] is your access token and [MY_PROJECT_ID] is the ID of target project.

      Example response:

      {
        "name": "apps/[MY_PROJECT_ID]",
        "id": "[MY_PROJECT_ID]",
        "authDomain": "gmail.com",
        "locationId": "us-central",
        "defaultHostname": "[MY_PROJECT_ID].[REGION_ID].r.appspot.com",
        "defaultBucket": "[MY_PROJECT_ID].[REGION_ID].r.appspot.com"
      }
      

      The REGION_ID is an abbreviated code that Google assigns based on the region you select when you create your app. The code does not correspond to a country or province, even though some region IDs may appear similar to commonly used country and province codes. For apps created after February 2020, REGION_ID.r is included in App Engine URLs. For existing apps created before this date, the region ID is optional in the URL.

What's next