Using the API

Whitelisting Accounts

To gain access to the API:

  1. Create a corp email account with 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 an email to your Google TAM to whitelist this account.

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, create a project:

  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.

First, create a project in Google Developers Console. You can customize the language to use in the project.

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

curl -s -k -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

curl -X POST -T /work/preload.apk
https://androidpartner.googleapis.com/upload/v1/media/901a81db-b219-43c1-bddf-39a22e7f2ebf?upload_type=media

Download an APK

Method

curl
https://androidpartner.googleapis.com/v1/media/901a81db-b219-43c1-bddf-39a22e7f2ebf?alt=media
### List carriers Clients must also get the list of carriers before calling to create the Play Auto Install. #### Method
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

curl -s -k -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/901a81db-b219-43c1-bddf-39a22e7f2ebf/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
curl -s -k -H "Authorization: Bearer my_oauth_token" -H "X-GFE-SSL: yes"
https://androidpartner.googleapis.com/v1/playAutoInstalls/21166C6E

Download an APK from an existing Play Auto Install

Get a reference to the APK

Method
curl -s -k -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=21166C6E

Download

Method
curl
https://androidpartner.googleapis.com/v1/media/b501a9e1-21ce-42d7-a58b-8399a89aec4b?alt=media

Publish

Method
curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization:
Bearer
ya29.YgKvVYk3E-itQt6cPds35r8mXGsg13GZ6oMiXMtWppcFecTsCp5XumbwECLJDPEB6ZULVOtfVRrvljBz1VmpXw"
-H "X-GFE-SSL: yes" -d "" https://androidpartner.googleapis.com/v1/playAutoIn\
stalls/4CD5B9FE:publish

Delete

Method
curl -s -k -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/21166C6E