Using the API

Why Use API

Android Partner API is the backend API for a series of frontend portals, e.g. Android Partner Approval Portal, Android Device Config Portal, etc. Partners can use API to:

  1. Perform tasks in bulk with local script, etc.
  2. Directly connect their own existing or new systems to automate the interactions instead of manually performing them through the websites.

Getting access

Android Partner API is a Google Cloud Project API (https://cloud.google.com/docs/authentication/) that supports two types of principals: user accounts and service accounts.

Individual access

  1. Create your company's Google Cloud Project at Google APIs Console. You can customize the language to use in the project.
  2. Send the following information to your Google TAM to access:
    1. Google Cloud Project Name and ID:
    2. All user emails that will call the Android Partner API
    3. Functionalities to use: For example, View, Upload Report, PAI, GOTA.
    4. Expected QPS.

System access

Accessing API with a system requires the same steps as Individual access above, but you must create headless account or service account for accessing API. We recommend:

  1. Create the account using the format android-partner-api@company.com.
  2. Create a Google account with this corporate email address via this link. Do not associate any Gmail accounts to this newly created account.
  3. Send this acount as part of other GCP info to your Google TAM.

Registering applications

All requests to the Android Partner API must be made via an authenticated user (i.e., android-partner-api@company.com). The Android Partner API uses OAuth 2.0 as the authorization mechanism. As a developer, you must register your application in the Google APIs Console and register for an OAuth 2.0 token in order to make authorized requests.

In the Google APIs Console, select your project created in step 1:

  1. Select APIs & auth>APIs.
  2. Search for “Android Partner API” and enable it.

    XXX image

  3. Select APIs & auth>Credentials>Create new Client ID.

  4. In the dialog, select Application type>installed application.

  5. In the Configure consent screen, enter the whitelisted email address from the previous step and fill in your product name, etc.

  6. Click Save.

    XXX image

    After saving, a new dialog is shown.

  7. Select Application type>installed application>other.

  8. Select Create Client ID.

Now you have a new Client ID resembling .... .apps.googleusercontent.com and a client secret. Use these to obtain authentication credentials for users at your company.

Registering Deployments

Access to each deployment is restricted to individual users. On the deployment, to exercise the APIs the user account must be whitelisted. This step is performed by your Google TAM.

Example

This section provides a thorough, simple example of using the Play Auto Install service in the Android Partner API.

The following example uses curl to simulate the usage of Play Auto Install service methods. You can use different but equivalent language methods in your client software.

Since the Play Auto Install service requires authentication, client software must first retrieve an OAuth token. For details, refer to https://developers.google.com/identity/protocols/OAuth2.

This example assumes your client software has already retrieved an OAuth token string, my_oauth_token.

Start upload

Method

Replace "my_oauth_token" with your oauth token.

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer my_oauth_token" \
  -H "X-GFE-SSL: yes" -d "" \
https://androidpartner.googleapis.com/v1/playAutoInstalls/apk:startUpload
Return Value

The returning message should contain a session id. The following is an example of returned message:

{
  "ref": {
    "name": "901a81db-b219-43c1-bddf-39a22e7f2ebf"
  }
}

In this example, 901a81db-b219-43c1-bddf-39a22e7f2ebf is the upload session id that will be needed for uploading the APK.

Upload an APK

Method

Replace "my_session_id" with your upload session id.

curl -X POST \
  -T /work/preload.apk \
https://androidpartner.googleapis.com/upload/v1/media/my_session_id?upload_type=media

Download an APK

Method

Replace "my_session_id" with your upload session id.

curl
https://androidpartner.googleapis.com/v1/media/my_session_id?alt=media
### List carriers Clients must also get the list of carriers before calling to create the Play Auto Install. #### Method Replace "my_oauth_token" with your oauth token.
curl --header "Authorization: Bearer my_oauth_token"
https://androidpartner.googleapis.com/v1/playAutoInstallsCarriers

Return Value

{
  "carrier": [
    {
      "countryCode": "US",
      "id": "1",
      "name": "T-Mobile - US"
    },
    {
      "countryCode": "GB",
      "id": "2",
      "name": "EE"
    },
    ... ... ...
  ]
}

Create a new Play Auto Install

Clients must first prepare an Android APK that contains a Play Auto Install configuration.

Method

Replace "my_oauth_token" with your oauth token.

Replace "my_session_id" with your upload session id.

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer my_oauth_token" \
  -H "X-GFE-SSL: yes" \
  -d '{ config : { name : "mytest", product_id : "4CD5B9FE", build_fingerprint :"apfe_oem/Superphone1000DE/Superphone1000" , country_code : ["US
", "CN"], carrier_id : [1761, 454, 1884], enabled : true, evaluation_order :1 } }' \
https://androidpartner.googleapis.com/v1/playAutoInstalls/my_session_id/playAutoInstall

Return Value

{
  "name": "901a81db-b219-43c1-bddf-39a22e7f2ebf",
  "id": "21166C6E",
  "config": {
    "name": "mytest",
    "productId": "4CD5B9FE",
    "buildFingerprint": "apfe_oem/Superphone1000DE/Superphone1000",
    "countryCode": [
      "US",
      "CN"
    ],
    "carrierId": [
      "1761",
      "454",
      "1884"
    ],
    "enabled": true,
    "evaluationOrder": 8
  },
  "application": [
    {
      "packageName": "com.ubercab"
    },
    {
      "packageName": "com.nianticlabs.pokemongo"
    },
    {
      "packageName": "com.facebook.katana"
    },
    {
      "packageName": "com.zed.TrdWapLauncher"
    },
    {
      "packageName": "com.slacker.radio"
    }
  ]
}

In this example, id is the unique ID of the Play Auto Install you just created, and productId is the unique ID of product the Play Auto configuration belongs to. ### Retrieve a Play Auto Install #### Method Replace "my_oauth_token" with your oauth token. Replace "my_pai_id" with the your productId.
curl -s -H "Authorization: Bearer my_oauth_token" \
  -H "X-GFE-SSL: yes" \
https://androidpartner.googleapis.com/v1/playAutoInstalls/my_pai_id

Download an APK from an existing Play Auto Install

Get a reference to the APK

Method

Replace "my_oauth_token" with your oauth token.

Replace "my_pai_id" with the your productId.

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer my_oauth_token" \
  -H "X-GFE-SSL: yes" -d "" \
https://androidpartner.googleapis.com/v1/playAutoInstalls/apk:download?id=my_pai_id

Download

Method

Replace "my_session_id" with your upload session id.

curl
https://androidpartner.googleapis.com/v1/media/my_session_id?alt=media

Publish

Method

Replace "my_oauth_token" with your oauth token.

Replace "my_product_id" with the your productId.

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer my_oauth_token" \
  -H "X-GFE-SSL: yes" -d "" \
https://androidpartner.googleapis.com/v1/playAutoInstalls/my_product_id:publish

Delete

Method

Replace "my_oauth_token" with your oauth token.

Replace "my_pai_id" with the your productId.

curl -s -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer my_oauth_token" \
  -H "X-GFE-SSL: yes" -d "" \
https://androidpartner.googleapis.com/v1/playAutoInstalls/my_pai_id