I am trying to make an API call to Paystack API. I am using Axios package for node.js. I can't seems to get it to work.
Here is my code:
const response = await axios({
method: 'post',
url:'https://api.paystack.co/transaction/initialize',
data: paymentDetails,
headers : {
Authorization: 'mysecretKey',
'content-type': 'application/json',
'cache-control': 'no-cache'
},
})
return res.json(response)
On postman, I simply provided the payment details via the body as requested by Paystack:
"id": 1,
"username": "kings",
"email": "emailaddress",
"amount": 100
I am getting this error: AxiosError: Request failed with status code 401
You probably have the
Authorizationwrong.Try this:
Notice the
Authorization: Bearer {secret}https://paystack.com/docs/api/#authentication