googleapis / google-api-python-client

🐍 The official Python client library for Google's discovery based APIs.
https://googleapis.github.io/google-api-python-client/docs/
Apache License 2.0
7.69k stars 2.4k forks source link

Issue With Patch Request - Google Play Developer API #2025

Closed Kareem-2000 closed 1 year ago

Kareem-2000 commented 1 year ago

I'm trying to use the google play developer API to patch a subscription and change its price for all the countries, but I'm getting the following error and have no clue why:

in execute raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 500 when requesting https://androidpublisher.googleapis.com/androidpublisher/v3/applications/-/subscriptions/-?alt=json&regionsVersion.version=2022/01&updateMask=basePlans returned "Internal error encountered.". Details: "Internal error encountered.">

The following is the code I have written.

subscription = {
    "packageName": package_name,
    "productId": subscription_id,
    "basePlans": {
        "basePlanId": "test",
        "regionalConfigs": {
            "regionCode": "US",
            "newSubscriberAvailability": True,
            "price":{
                "currencyCode": "USD",
                "units": "4",
                "nanos": "990000000"
            }
        }
    },
    "listings":{
        "languageCode": "en-US",
        "title": "test"
    }
    }

request = service.monetization().subscriptions().patch(packageName=package_name, productId=subscription_id, body=subscription)
request.uri += "&regionsVersion.version=2022/01"
request.uri += "&updateMask=basePlans"
response = request.execute()

Can someone please point out what is wrong here? I have tried to test it on the "Try it" section of the documentation but it still does not work.

aria1991 commented 1 year ago

Hi @Kareem-2000 . Could you verify that the regionsVersion.version and updateMask parameters in the request URI are correctly formatted ?

Kareem-2000 commented 1 year ago

Hi @aria1991, yes they were correctly formatted. I got it to wok by including all the required and non-required parameters. However, i'm facing another issue as follows:

HttpError: <HttpError 400 when requesting https://androidpublisher.googleapis.com/androidpublisher/v3/applications/app/subscriptions/hashtest1?alt=json&regionsVersion.version=2022/01&updateMask=basePlans returned "Invalid currency for region code HR at the specified regions version RegionLaunchVersionId{versionId=202201}.". Details: "Invalid currency for region code HR at the specified regions version RegionLaunchVersionId{versionId=202201}.">

Further on, upon removing that country from the list I want to update, im getting this error: Details: "6months-7g-hashtest: Regional configs were removed from the base plan: HR"> I have double and triple checked the country's currency on Google Play Console, and it is in EUR, and EUR is what im sending in the API call.

Why does it need all the countries in the body in order to update the base plan? Won't it work if I just need to update a single price for example?

Kareem-2000 commented 1 year ago

For anyone facing a similar issue, you simply need to change the currency code of HR to "HRK" and not "EUR". Although the currency on play console is in euros, the API still hasn't been updated it seems.

jsarson commented 1 year ago

I also have a problem with changing subscriptions using the PATCH. Getting a subscription using GET or LIST works fine.

This is working fine:

subscriptionFromAPI = androidpublisher.monetization().subscriptions().get(
    packageName=PACKAGE_NAME,
    productId=SUBSCRIPTION_ID
).execute()

However, when I call PATCH:

request = androidpublisher.monetization().subscriptions().patch(    
    packageName=PACKAGE_NAME,
    productId=SUBSCRIPTION_ID,
    body=subscriptionFromAPI
)

request.uri += "&regionsVersion.version=2022/01"
request.uri += "&updateMask=basePlans"
request.execute()

It returns this: HttpError 404 when requesting https://androidpublisher.googleapis.com/androidpublisher/v3/applications/PACKAGE_NAME/subscriptions/SUBSCRIPTION_ID?alt=json&regionsVersion.version=2022/01&updateMask=basePlans returned "Subscription not found for package name 'PACKAGE_NAME' and subscription ID 'SUBSCRIPTION_ID'"

Has anyone had a similar issue?

ghost commented 1 year ago

Hi @aria1991, yes they were correctly formatted. I got it to wok by including all the required and non-required parameters. However, i'm facing another issue as follows:

would you mind elaborating on your solution? You included ALL parameters and then it worked? I am facing the same issue. Just getting Error 500 without any further details.

Kareem-2000 commented 1 year ago

Hi @aria1991, yes they were correctly formatted. I got it to wok by including all the required and non-required parameters. However, i'm facing another issue as follows:

would you mind elaborating on your solution? You included ALL parameters and then it worked? I am facing the same issue. Just getting Error 500 without any further details.

Yes, I simply included all the fields. One simple way of doing this would be to use the API to get the existing prices for the subscription, then edit that json response with the prices you want to alter, and then patch that subscription.

ghost commented 1 year ago

Thanks @Kareem-2000 that's how I am doing it now and it is working.

vchudnov-g commented 1 year ago

Seems like this issue is resolved. Closing.

djkad commented 3 months ago

Sorry, i have a question if you can help me: When i have created the subscription and activate the base plan, i have forgot to specify the node "regionalConfigs". In order to make it available in all countries, do i have to specify "every" regional code and price for all countries or i can just specify US and IT ? Thanks