title: Google Play Developer API - Query purchase token returns Invalid Value
body: <p>I am trying to set up a web service to query Google Play purchases.  We store the order information for customers and this service would call Google Play API to query the subscription details.</p>
  
  <p>Every time i try to query a purchase, it gives me the error:</p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  {  
     "error":{  
        "errors":[  
           {  
              "domain":"global",
              "reason":"invalid",
              "message":"Invalid Value"
           }
        ],
        "code":400,
        "message":"Invalid Value"
     }
  }
  </code></pre>
  
  <p>Here is what I tried:</p>
  
  <ul>
  <li>Created a project in <a href="https://console.developers.google.com" rel="nofollow noreferrer">https://console.developers.google.com</a> enabled the "Google Play Android Developer API"</li>
  <li>Created an oAuth 2.0 client_id and client_secret for type Web application</li>
  <li>Logged in as the account owner, I generated a refresh_token</li>
  <li>In <a href="https://play.google.com/apps/publish" rel="nofollow noreferrer">https://play.google.com/apps/publish</a> I went to Settings -> API Access and linked the the project to my app</li>
  </ul>
  
  <p>Code wise, I used the refresh_token to get an access_token:</p>
  
  <pre><code>String refreshToken = "1/ljll6d9ME3Uc13jMrBweqXugV4g4timYcXXXXXXXXX";
  HttpPost request = new HttpPost("https://accounts.google.com/o/oauth2/token");
  List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
  params.add(new BasicNameValuePair("client_id", client_id));
  params.add(new BasicNameValuePair("client_secret", client_secret));
  params.add(new BasicNameValuePair("refresh_token", refreshToken));
  params.add(new BasicNameValuePair("grant_type", "refresh_token"));
  request.setEntity(new UrlEncodedFormEntity(params));
  
  HttpResponse response = httpClient.execute(request);
  HttpEntity entity = response.getEntity();
  String body = EntityUtils.toString(entity);
  JSONObject json = new JSONObject(body);
  String accessToken = json.getString("access_token");
  </code></pre>
  
  <p>The access_token from this works because i can call this API with it and get the response back:</p>
  
  <pre><code>String url = String.format("https://www.googleapis.com/androidpublisher/v2/applications/%s/inappproducts/%s", packageName, productId);
  HttpClient client = new DefaultHttpClient();
  HttpGet get = new HttpGet(url);
  get.setHeader("Authorization", "Bearer " + accessToken);
  HttpResponse response = client.execute(get);
  // parse response etc...
  </code></pre>
  
  <p>This returns:</p>
  
  <pre><code>{  
      "packageName":"com.my.app",
      "sku":"com.my.app.premium",
      "status":"active",
      "purchaseType":"subscription",
      "defaultPrice":{  
      //...
  }
  },
      "listings":{  
      "en-US":{  
      "title":"My App Premium",
      "description":"My App"
  }
  },
      "defaultLanguage":"en-US",
      "subscriptionPeriod":"P1Y"
  }
  </code></pre>
  
  <p>Now, I want to get informatoin about a purchase.  I have a information from a purchase as such:</p>
  
  <pre><code>{  
  "orderId":"GPA.1111-1111-1111-11111",
  "packageName":"com.my.app",
  "productId":"com.my.app.premium",
  "purchaseTime":1452801843877,
  "purchaseState":0,
  "developerPayload":"XXXXXXXd9261023a407ae5bb6ab8XXXXXXX",
  "purchaseToken":"xxxxxxxxxxxxxx.YY-J123o12-xxxxxxxxxxxxxxxmYRk2itBkNdlXhyLMjXsxxxxxxxxxxxxLfBxabaAjKbeBC0PVhHnHd1DDbFkgZtbQxxk5pDIAH3xBHu8HrcWfRgewAYnFeW9xxxxxxxxxxxxxC5TDjcBL8fhf",
  "autoRenewing":true
  }
  
  String url = String.format("https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/products/%s/tokens/%s",packageName, productId, purchaseToken);
  HttpClient client = new DefaultHttpClient();
  HttpGet get = new HttpGet(url);
  get.setHeader("Authorization", "Bearer " + accessToken);
  HttpResponse response = client.execute(get);
  // parse response etc...
  </code></pre>
  
  <p>Since the packageName / productId and access_token seem to work for the first call, and the purchaseToken is right out of the order info.  What is giving the invalid value error?</p>
  
  <p>Any help appreciated - not sure what else to try.  Thanks!</p>
  
  <p>UPDATE:
  I went through and validated all the package names and account setup
  The real issue seemed to be the service i was hitting.  I switched it to:
  <a href="https://www.googleapis.com/androidpublisher/v2/applications/packageName/purchases/subscriptions/subscriptionId/tokens/purchaseToken" rel="nofollow noreferrer">https://www.googleapis.com/androidpublisher/v2/applications/packageName/purchases/subscriptions/subscriptionId/tokens/purchaseToken</a></p>
  
  <p>I also swapped to use the Google Client API as it was much cleaner looking that manually creating requests.</p>
  
  <p>Thanks for help and replies</p>