I am trying to make use of existing sample code for PassKit to create a JWT token with "Run JavaSript by Zapier". But the Zapier does not recognized the btoa function.
ReferenceError: btoa is not defined
According to this website, this function can be called directly. Any idea?
var b64data = btoa("this is my string to turn into base64");
Below is the code that I have written.
var Zap = {
base64url:function(input){
var base64String = btoa(input); //<--error here
return urlConvertBase64(base64String);
},
urlConvertBase64:function(input){
var output = input.replace(/=+$/, '');
output = output.replace(/\+/g, '-');
output = output.replace(/\//g, '_');
return output;
},
generateJWT:function(key){
var header = {
"alg": "HS256",
"typ": "JWT"
};
var time_now = Math.floor(new Date().getTime()/1000);
var exp = time_now + 30;
var body = {
"exp": exp,
"key": key
};
var token = [];
token[0] = Zap.base64url(JSON.stringify(header));
return body;
}
};
output = [{body: Zap.generateJWT(inputData.Api_key)}]