Google Play Developer API - 400 Invalid Value - InAppPurchases

11k views Asked by At

My question is similar to this one. However, I am using the API Java Client Library with a service account, making calls to the API from my server.

My code is following this guide, which is very simple. However, I can't seem to get an appropriate error for my request. This is how I build my AndroidPublisher:

val credential = GoogleCredential.fromStream(FileInputStream(
        "/path/to/json"
)).createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))

androidPublisher = AndroidPublisher.Builder(httpTransport, JSON_FACTORY, credential)
        .setApplicationName(packageName)
        .build()

Where the JSON is generated from the Developer Console, under Service Accounts. This is how I make my request:

androidPublisher.purchases().subscriptions().get(packageName, "valid-sku", "invalid-token").execute()

My subscription ID is valid but my token is invalid. I expect an error such as "invalid token" in the response. However, what I get is:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid Value",
    "reason" : "invalid"
  } ],
  "message" : "Invalid Value"
}

Is that a generic error because of the invalid token or is it an authentication issue? If it an authentication issue, how do I solve it? If it is an invalid token issue, how am I supposed to know?

Some more information:

  • I get the same error when trying to make that call from the API Explorer as well (this time using a Client ID and API Key instead of Service Account).
  • I have not delegated domain-wide access to the service account. Do I have to for some reason?
  • I can successfully make other calls to the API such as inappproducts.list
5

There are 5 answers

1
pavlos163 On BEST ANSWER

So, the reason that happened was just because the purchaseToken I was using was wrong.

I did not expect that to be the reason as I thought that in the case of an invalid token, I would receive a "token invalid" error (or something similar). As it turns out, the responses given by Google are pretty inconsistent (a 404 could also be given for an invalid token).

1
Isaac Martin Otim On

Scratched my head for a few hours, ALL my parameters were correct, and then well.. I realized that I was barking up the wrong tree (endpoint)

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

is not this

https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/products/{productId}/tokens/{token}

/purchases/subscriptions/.. vs /purchases/products/..

2
Ardito ITA On

For all those who run into this problem, 99% of you need to publish the application for internal testers.

Follow this guide: https://support.google.com/googleplay/android-developer/answer/6062777?hl=en

enter image description here

1
Mr Stanev On

In my case the problem was that I was calling:

purchases.products.get

Instead of:

purchases.subscriptions.get
9
Berkay Turancı On

From my experiences, if you have HTTP 400 error with Invalid Value then that purchase or subscription is FRAUD.

You can check out Order Id part of those purchases. Probably in the format of XXXXXXXXXXXX.XXXXXXXXXXXX which is wrong and should be GPA.XXXX.XXXXX.XXXXX.XXX

  • I don't really count the X char number. I just added to show the logic.