Developer Discussions

Ask a Question
Back to All

I am having trouble authenticating with maya checkout. Help me.

I got this public key "pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah" from the provided sandbox API keys.

I converted the string "pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah:" to base64 using btoa and the result is : "cGstWjBPU3pMdkljT0kyVUl2RGhkVEdWVmZSU1NlaUdTdG5jZXF3VUU3bjBBaDo="

My code looks like this.

key = "pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah"

function convertToBase64(key) {
console.log(key + ':');
return btoa(key + ':');
}

const instance = axios.create({
headers: {
Authorization: 'Basic ' + convertToBase64(key),
},
});

instance
.get(url)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.log(error);
});