I am converting this cURL code to javascript.
curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \
-X POST https://api.razorpay.com/v1/customers \
-H "Content-Type: application/json" \
-d '{
"name": "Gaurav Kumar1"
"email": "gaurav.kumar+1@example.com"
"contact": "9123456781"
}'
<script>
function createCustomer() {
console.log("createCustomer");
const url="https://api.razorpay.com/v1/customers";
fetch(url, {
method: 'post',
headers: {
"x-api-key": "MY_KEY_ID",
"content-type": "application/json",
"cache-control": "no-cache"
},
body: {
"name": "Gaurav Kumar1",
"email": "gaurav.kumar+1@example.com",
"contact": "9123456781"
}
})
.then(response => response.json())
.then((data) => {
console.log("data",data)
})
}
</script>
when i check this in postman it is giving the correct response. But when i use this in my site it is giving the error.
POST https://api.razorpay.com/v1/customers 401 (Unauthorized) data : error: {code: "BAD_REQUEST_ERROR", description: "Please provide your api key for authentication purposes."}