I am trying to dynamically generate checkout on the Coinbase Commerce API. I am following the documentation found here and porting into a javascript website using axios to make requests.
It seems like their setup requires authentication to be passed in the header of the requests, which I am doing but for some reason it is not working correctly. Their example works in curl directly on terminal, but something appears to be busted in my axios code. Could you kindly let me know how I can fix this?
Working Curl Request
curl https://api.commerce.coinbase.com/checkouts \
-X POST \
-H 'Content-Type: application/json' \
-H "X-CC-Api-Key: <Your API Key>" \
-H "X-CC-Version: 2018-03-22" \
-d '{
"name": "The Sovereign Individual",
"description": "Mastering the Transition to the Information Age",
"local_price": {
"amount": "100.00",
"currency": "USD"
},
"pricing_type": "fixed_price",
"requested_info": ["email"]
}'
Javascript / Axios Script
let amount = 10;
try {
let options = {
headers: {
"Content-Type": "application/json",
"x-api-key": "<Your API Key>",
"X-CC-Version": "2018-03-22"
}
}
let data = {
"name": "US$" + amount + " Credit Refill",
"description": "Credit refill",
"local_price": {
"amount": amount,
"currency": "USD"
},
"pricing_type": "fixed_price"
};
let response = await axios.post('https://api.commerce.coinbase.com/checkouts', data, options);
console.log(response.data);
} catch (error) {
console.log(error)
}
Error
Error 401 / authorization_error