How to make a GET request that takes oauth1 authentication

167 views Asked by At

I am trying to fetch some available slots for an appointment booking application using Axios and GET request in node.js.

i have tested the endpoint in postman and it works flawlessly, i copied the generated code for the request from postman, but it gives me a 401 Authentication error.

app.get("/slots", (req, res) => {
    getAvailableSlots(res);
})
const getAvailableSlots = (res) => {
    let config = {
      method: 'get',
      maxBodyLength: Infinity,
      url: '<url>&oauth_consumer_key=<key>&oauth_token=<token>&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1680087781&oauth_nonce=AKuBSQsiXz1&oauth_version=1.0&oauth_signature=nRiByohboigwEbDuqr0yDzy%2BHjw%3D',
      headers: { 
        'Cookie': 'session_id=fd65f21c120061ce905241be94d10f0fd807cf48'
      }
    };
    
    axios.request(config)
    .then((response) => {
      res.send(JSON.stringify(response.data));
    })
    .catch((error) => {
      res.send(error);
    });

}

this is the error that i got

{"message":"Request failed with status code 401","name":"AxiosError","stack":"AxiosError: Request failed with status code 401\n    at settle (/Users/admin/projects/professionals-appointment-booking-widget/node_modules/axios/dist/node/axios.cjs:1900:12)\n    at IncomingMessage.handleStreamEnd (/Users/admin/projects/professionals-appointment-booking-widget/node_modules/axios/dist/node/axios.cjs:2952:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1359:12)\n    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)","config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"adapter":["xhr","http"],"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":null,"env":{},"headers":{"Accept":"application/json, text/plain, */*","Authorization":"OAuth oauth_consumer_key=\"j5r7K9FLCRbuli9w4Z4Ddyq6pnYY1ooc\",oauth_token=\"IK4BaunTMgBRk9J9wVLsUZW4eHjPZyYY\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1680087105\",oauth_nonce=\"O5XKmWv8pS6\",oauth_version=\"1.0\",oauth_signature=\"WxrQNOA9rM7mNePuju8jGoM%2BF4Y%3D\"","Cookie":"session_id=fd65f21c120061ce905241be94d10f0fd807cf48","User-Agent":"axios/1.3.4","Accept-Encoding":"gzip, compress, deflate, br"},"method":"get","url":"https://crm.cadabams.com/restapi/1.0/object/slot.booking?domain=[(%27doctor_id%27,%20%27=%27,5314),%20(%27availability%27,%20%27=%27,%20%27open%27)]&fields=[%27doctor_id%27,%20%27start_datetime%27,%20%27stop_datetime%27,%27id%27%20]"},"code":"ERR_BAD_REQUEST","status":401}
0

There are 0 answers