Q:

How to cancel User subscription user google-api-python-client

I want to cancel user subscription from my server side code with python. I already have used google API for verifying user subscription. The API endpoint looks like this.

GET https://www.googleapis.com/androidpublisher/v2/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}

I implemented this in python like this
service = build(serviceName='androidpublisher', version='v2', credentials=cred)
response = service.purchases().subscriptions().get(
            packageName=receipt_json.get('packageName'),
            subscriptionId=receipt_json.get('productId'),
            token=receipt_json.get('purchaseToken')).execute()

The endpoint for canceling subscription looks like this.

POST https://www.googleapis.com/androidpublisher/v2/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}:cancel

How can I implement this :cancel in google-api-python-client?

A:

I did it like this
service = build(serviceName='androidpublisher', version='v2', credentials=cred) 
response = service.purchases().subscriptions().cancel(
            packageName=receipt_json.get('packageName'),
            subscriptionId=receipt_json.get('productId'),
            token=receipt_json.get('purchaseToken')).execute()

