[FIXED] How to get the enterpriseToken when creating an enterprise with the Android Management API?

Issue

I’m trying to create a new enterprise using api method.
First I maked signupUrls.create with request parameters projectId and callbackUrl. In field callbackUrl, I put my Google Cloud platform admin url.
And I got a response

{
  "name": "signupUrls/C78787fa85be23de9f",
  "url": "https://play.google.com/work/adminsignup?token=SAEQ6V4kHngQPk5wCSl37KkZPlfw-wJtlVHndDfsmH1R1twiXM1LC6FpYFSndpEaw2mbsmqd3T5eBaRWtQPrVClngJHZcKaGc0V_4dOhz-F8D0vSjb_1MnxRheUP0Ij8el6zNE5GYYA1LOECCUFLip8kcg6e99_3DfNbmutqHONjhdi8hQBQUa0Q5nWN-nMRF3EUgffvLk1zo4BAA0AUscQ"
}

The next point is method: enterprises.create with projectId, signupUrlName and enterpriseToken parameters.

And then I send request I get erorr:

"message": "The enterprise token is invalid: SAEQ6V4kHngQPk5wCSl37KkZPlfw-wJtlVHndDfsmH1R1twiXM1LC6FpYFSndpEaw2mbsmqd3T5eBaRWtQPrVClngJHZcKaGc0V_4dOhz-F8D0vSjb_1MnxRheUP0Ij8eCUFLip8kcg6e99_3DfNbmutqHONjhdi8hQBQUa0Q5nWN-nMRF3EUgffBWwGHSA8AkFWvLk1zo4BAA0AUscQ",
    "status": "INVALID_ARGUMENT"

In the field enterpriseToken I put token values from signupUrls.create url response.

Solution

To obtain the enterpriseToken you (or your customer) need to go through the enterprise sign-up flow by visiting the url returned by signupUrls.create, which looks like https://play.google.com/work/adminsignup?token=... (the token in this URL is not the enterpriseToken).

Upon completing the sign-up flow you will be redirected to the callbackUrl passed in signupUrls.create, with the enterpriseToken appended as a parameter. So if you set the callbackUrl to https://example.com/mycallback you will be redirected to a URL like https://example.com/mycallback?enterpriseToken=....

You then need to extract the enterpriseToken and pass it to enterprises.create.

So if you create the enterprise yourself you can set any callbackUrl, even an invalid one, and just copy the enterpriseToken manually. However if you want your customer to create the enterprise then the callbackUrl should point to your server so you can retrieve the enterpriseToken, you may also want to pass an additional token in the callbackUrl so you can identify your customer.

More details in the guide for creating an enterprise.

Answered By – Fred

Answer Checked By – Timothy Miller (FixeMe Admin)

Leave a Reply

Your email address will not be published.