Use the Google App Engine Admin API to programmatically create App Engine applications in new Google Cloud Platform projects. By using both the Admin API along with the Cloud Resource Manager API, you are able to programmatically manage Cloud Platform projects and App Engine applications.
Creating an App Engine application creates an
Application resource
for a target Cloud Platform project in the specified
location.
To manually create an App Engine application in a Cloud Platform project, see the Managing Projects, Applications, and Billing topic for your language in either the standard environment or flexible environment.
Before you begin
Before you can create an App Engine application, you must be able to authorize
your HTTP requests and have or create a Cloud Platform project. A
project can contain only a single App Engine application. Therefore, a new
App Engine application can be created only in a project that does not already
contain an Application resource. You can use either the
apps.get method
or the Cloud Platform Console to check
if a project already contains an Application
resource.
To create a Cloud Platform project:
API
To programmatically create a Cloud Platform 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 Cloud Platform project using the Cloud Platform Console:
gcloud
After installing the Google Cloud SDK, you can run the
following alpha command of the gcloud tool to create a
Cloud Platform project:
gcloud alpha projects create
Creating a new Cloud Platform project with the Cloud Resource Manager API
-
Before you can send requests with Google Cloud Resource Manager, you must enable that API in the Cloud Platform project from which you want the ability to create other Cloud Platform projects. Enable the Cloud Resource Manager API in the Google Cloud Platform Console
-
Send an HTTP
POSTrequest using your access token:POST https://cloudresourcemanager.googleapis.com/v1/projects/ { "projectId": "[MY_PROJECT_ID]", "name": "[MY_PROJECT_NAME]" }Example cURL command:
curl -X POST -d "{ 'projectId': '[MY_PROJECT_ID]', 'name': '[MY_PROJECT_NAME]' }" -H "Content-Type: application/json" -H "Authorization: Bearer [MY_ACCESS_TOKEN]" https://cloudresourcemanager.googleapis.com/v1/projects/
For more information, see the Creating a New Project topic of the Cloud Resource Manager.
Creating an App Engine application
To create an App Engine application with the Admin API:
-
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.
-
Send an HTTP
POSTrequest using your access token and the Admin API to create an App Engine application.You define the
Applicationresource and target Cloud Platform project in the HTTPPOSTrequest, 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 Cloud Platform project in which you want to create an App Engine application. -
locationId: This is the geographic region in which the App Engine application is located and runs, for example:us-centralus-east1europe-west- Supports standard environment only.asia-northeast1
For a complete list of supported locations, you can use the
apps.locations.listmethod.Example: Authorize and execute this example request in the APIs Explorer to view a current list of supported locations.
See
Applicationresource 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/appsWhere:
[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": "[email protected]", "target": "apps/[MY_PROJECT_ID]" } } -
-
Verify that your App Engine application was created:
-
View the status of the actual creation operation:
The HTTP
POSTrequest that you used in the previous step returned the operation name in thenamefield, which you use with theGETmethod of theapps.operationscollection to check the status of the creation operation.For example, if the
namefield of the response is:"name": "apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450f"Then you send the following HTTP
GETrequest:GET https://appengine.googleapis.com/v1/apps/[MY_PROJECT_ID]/operations/0a37a032-be3f-4c20-98b4-e3300447450fExample 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-e3300447450fWhere
[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": "[email protected]", "target": "apps/[MY_PROJECT_ID]" }, "done": true, "response": { "@type": "type.googleapis.com/google.appengine.v1.Application", "id": "[MY_PROJECT_ID]", "locationId": "[MY_APP_LOCATION]" } } -
Verify that the App Engine application was created in your project:
To view details about the version, you use the
GETmethod of theappscollection. You must specify the project that you deployed in the HTTPGETrequest, 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].appspot.com", "defaultBucket": "[MY_PROJECT_ID].appspot.com" }
-