Example API Calls - Android Pay

This article provides examples with context for making certain common API calls for creating Android Pay passes. For a complete set of examples relating to Android Pay, please see the Wallet API documentation for Passes

Making API calls via curl to generate Android Pay passes

The below example API call will create a single pass object and provide a returned block of HTML which can be used to generate an Add to Android Pay button:

 

curl -X POST https://reach-api.urbanairship.com/v1/pass/123/saveToWallet \
    -H "Content-Type: application/json" \
    -H "Authorization: Basic <Base64 key>" \
    -H "Api-Revision: 1.2" \
    -d '{
          "fields": {
            "Points": {
              "value": "600"
            }
          },
          "tag": "abc",
          "externalId": "UserName",
          "onSuccess": "mySuccessFunc",
          "onFail": "myFailureFunc"
        }'

 

The above API call returns the following data:

<script src="https://apis.google.com/js/plusone.js" type="text/javascript"></script>
<script type="text/javascript">
function urban_airship_callback(path) {
    var script = document.createElement('script');
    script.src = path
    document.getElementsByTagName('head')[0].appendChild(script);
}
var successHandler = function (params) { urban_airship_callback('https://wallet-api.urbanairship.com/v1/card/register/<passUUID>?externalId=1234IDeclareAThumbWar') mySuccessFunc } var failureHandler = function (params) { urban_airship_callback('https://wallet-api.urbanairship.com/v1/card/register/<passUUID>?externalId=1234IDeclareAThumbWar') myFailureFunc } </script> <g:savetowallet jwt="eyJhbGciOiJSUzI1N/.../zZUp7PCdGrI33cmT0" onsuccess="successHandler" onfailure="failureHandler" size="small" theme="gray"></g:savetowallet>

 

 

In the above example, the mySuccessFunc and myFailureFunc functions can be used to set up callbacks for analytics or other additional functions. 

 

The above code is intended to be inserted into a page already authorized using the Save to Wallet Origin URL:

Screen_Shot_2016-04-25_at_9.32.38_PM.png

An example html page with the above code might look like this:   

<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>title</title>
      <link rel="stylesheet" href="style.css">
      <script src="script.js"></script>
   </head>
   <body>
 <script src="https://apis.google.com/js/plusone.js" type="text/javascript"></script>
<script type="text/javascript">
function urban_airship_callback(path) {
    var script = document.createElement('script');
    script.src = path
    document.getElementsByTagName('head')[0].appendChild(script);
}
var successHandler = function (params) {
    urban_airship_callback('https://wallet-api.urbanairship.com/v1/card/register/<passUUID>?externalId=1234IDeclareAThumbWar')

    mySuccessFunc
}
var failureHandler = function (params) {
    urban_airship_callback('https://wallet-api.urbanairship.com/v1/card/register/<passUUID>?externalId=1234IDeclareAThumbWar')

    myFailureFunc
}
</script>
<g:savetowallet jwt="eyJhbGciOiJSUzI1N/.../zZUp7PCdGrI33cmT0"
                onsuccess="successHandler"
                onfailure="failureHandler" size="small" theme="gray"></g:savetowallet>
   </body>
</html>

 

The above code will generate a Save to Android Pay button within the body of the page.

Screen_Shot_2016-04-25_at_9.53.12_PM.png

Clicking that button will offer you the option to add the pass to your Android Pay account.

 

Related Content:

 

Was this article helpful?
0 out of 0 found this helpful
Submit a request