Search code examples
androidgoogle-app-enginecurlgoogle-apiandroid-pay

How to update a wallet object in Android Pay?


I'm working with "Save to Android Pay" API and I'm trying to update one of my objects. According to Google's API.

One way to achieve it is by using the cURL commands and follow these steps:

  1. Get a token

java -jar TokenUtil.jar serviceAccountEmailAddress pathToPrivateKey

  1. Save the specific object to a text file

curl -X GET https://www.googleapis.com/walletobjects/v1/walletObjectType/resourceId -H "Authorization: Bearer bearerToken" > myobjectfile.txt

  1. make the changes I wish to make in the file (and increase the version value by 1)
  2. Push the updated file back to the server.

curl -X PUT https://www.googleapis.com/walletobjects/v1/walletObjectType/resourceId -H "Authorization: Bearer bearerToken" -H "Content-Type: application/json" -d myobjectfile.txt

Steps 1 - 3 work fine but when I try to push the object back to the server I get the following error:

{
"error": {
         "errors": [
                   {
                   "domain": "global",
                   "reason": "parseError",
                   "message": "Parse Error"
                   }
                   ],
         "code": 400,
         "message": "Parse Error"
         }
}

Since all I changed in the file is the version (and maybe one character in some title, just to see change) I do not understand why am I getting a parse error as myobjectfile.txt came from the server and its internal structure was not built by me.


Solution

  • It took them a while but Google finally solved their bug and shared their solution with me (hopefully they will update their API soon, too):

    • The file should be a .json file rather than a .txt file.

    • There should be an @ sign before the file name in the PUT command:

    curl -X PUT https://www.googleapis.com/walletobjects/v1/walletObjectType/resourceId -H "Authorization: Bearer bearerToken" -H "Content-Type: application/json" -d @myobjectfile.json

    After applying these changes, I was able to update my object.