Data fetch through api

I am trying to fetch all the details from CRM. I am using a fetch command in NodeJs but didn’t receive any response and also my status code is undefined.

const api = 'xxxxxxxxxxx'
const url = `https://bamboobox.myfreshworks.com/crm/sales/${api}/contacts/`

fetch(url, {

    method: 'GET',

    Authorization: `Token: token=${api}`,

    headers: {

        Accept: 'application/json'

    }

})

.then( res => {

    

    if(res.ok) {

        return res.json()

    } else {

        throw new Error('Bad http request made')

    }

})

.then ( jsondata => {

    console.log(jsondata)

})

.catch( e => {

    console.log({error: e.message})

})

Hi @adityagupta002,
Welcome to the Developer Community :tada:

Are you using fetch - npm? If so, that library is not updated in past 5 years. Can you please try with inbuild request ( Request Method ) and let us know if it worked.

1 Like

when I am using the below command I am getting an HTML file with unknown values.



const request = require('request')

const api = 'xxxxxxxxxxxxx'

const url = `https://bamboobox.myfreshworks.com/crm/sales/${api}/contacts`

const options = {

        url,

        Authorization: 'Token token=xxxxxxxxxxx',

        method: 'GET',

        Accept: 'application/json'   

}

function callback(error, res, body) {

    if(error) {

        console.log(error)

    } else {

        console.log(body.json())

    }

}

request(options, callback)

Hey @adityagupta002

I think you missed api in the url that you are making request. api here is a string and not a variable to be templatized. Check this :link: Freshworks CRM | Refreshingly new CRM & Deal Management Software

const url = https://bamboobox.myfreshworks.com/crm/sales/api/contacts
2 Likes

Also, kindly refrain from exposing your domain and API key in the public forum for the obvious security concerns :smiley:

1 Like