curl -H "Authorization: Token token=sfg999666t673t7t82" -H "Content-Type: application/json" -d '{"phone_call": { "call_direction": true, "targetable_type": "contact", "targetable": { "id": "1", "first_name": "Jane", "last_name": "Sampleton (sample)", "work_number ":"5304915427", "mobile_number ":"11919457004 " }, "note ": { "description": "Sample note"} }}' -X POST https://domain.myfreshworks.com/crm/sales/api/phone_calls
When ı do this request ı succesfully get the response, but ı just want to same request with axios. How can I do that ? I try this but not works ı get'a cors error.
const headers = {
'Content-Type': 'application/json',
Authorization: 'Token sfg999666t673t7t82',
};
var dataString =
'{"phone_call": { "call_direction": true, "targetable_type": "contact", "targetable": { "id": "1", "first_name": "Jane", "last_name": "Sampleton (sample)", "work_number ":"5304915427", "mobile_number ":"11919457004 " }, "note ": { "description": "Sample note"} }}';
Axios.post('https://domain.myfreshworks.com/crm/sales/api/phone_calls', dataString, {
headers: headers,
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
``
The headers seem incorrect in your axios version.
Authorization: Token token=sfg999666t673t7t82 is not the same as Authorization: 'Token sfg999666t673t7t82'.
Try changing Authorization: 'Token sfg999666t673t7t82' to Authorization: 'Token token=sfg999666t673t7t82' so that the requests are equivalent.