0
votes

I created a service account, instead of using the default one, under my google cloud project and I enabled dwd.

I then enabled Google Apps Marketplace API from the google cloud console.

Then I published a marketplace app as available only to users of my GSuite domain with api_console_project_id in manifest.json set to my project's id.

The status in the developer dashboard is

Published
GAM: Pending

I then had my domain admin install the app.

I believe I am now all set to use the appsmarket v2 Python client to verify license of my domain for the app now.

Below is how I am doing it

from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build


path_to_key = 'path/to/my/service_account_key.json'
scopes = ['https://www.googleapis.com/auth/appsmarketplace.license']
APPLICATION_ID = 'xxxxxxxxxxxx'
domain = 'xxxxxx.com'

credentials = ServiceAccountCredentials.from_json_keyfile_name(
            path_to_key, scopes)
authorized_http = credentials.authorize(Http())
appsmarket_api_client = build(
     'appsmarket', 'v2',   http=authorized_http)
appsmarket_license_info = appsmarket_api_client.customerLicense().get(
            applicationId=APPLICATION_ID, customerId=domain).execute()
domain_is_licensed = (appsmarket_license_info['state'] == 'ACTIVE')

But my code breaks at

appsmarket_license_info = appsmarket_api_client.customerLicense().get(
    applicationId=APPLICATION_ID, customerId=domain).execute()

with HttpError 403 when requesting https://www.googleapis.com/appsmarket/v2/customerLicense/xxxxxxxxxxxx/xxxxxx.com?alt=json returned "Not authorized to access the application ID

I am unable to debug why this is happening.

1
ask your domain admin to check whether the application name and scope are appearing under the Manage API client access page? Path under admin console Security - Advance setting - API client access page. - Bravin Balasubramaniam
@Bravin they do appear. - Afzal S.H.
Then go to Apps > Marketplace apps > Your application and check under Data access is in granted state with your scope? - Bravin Balasubramaniam
@Bravin The error message says Not authorized to access the application ID, so I am assuming something's wrong went with the service account being auto authorized when my admin installed the app. what could it be though? - Afzal S.H.
Did you enabled both Marketplace SDK and Marketplace API in the developer console? - Bravin Balasubramaniam

1 Answers

2
votes

What I missed was that I didn't add the service account as a member of the project and give it edit access to the project. Now it's working.