google-apps-scriptfetch-apiurlfetch

Fetching data from the Clearbit API returns an Exception: The parameters don't match the method signature for UrlFetchApp.fetch


I was trying to fetch data from Clearbit API and I get this message:

Exception: The parameters (String,(class),(class)) don't match the method signature for UrlFetchApp.fetch.

My code:

function linkedInUrl(domain) {
  let url = `https://company.clearbit.com/v2/companies/find?domain=${domain}`
  const api_keys = ""
  const header = {
    method: 'GET',
    headers: {'Authorization':'Bearer ' + api_keys}
  }
  options = {muteHttpExceptions: true};
var response = UrlFetchApp.fetch(url,header,options)
var data = JSON.parse(response.getContentText())

return "https://www.linkedin.com/"+data.linkedin.handle
}


function techUsed(domain) {
  let url = `https://company.clearbit.com/v2/companies/find?domain=${domain}`
  const api_keys = ""
  const header = {
    method: 'GET',
    headers: {'Authorization':'Bearer ' + api_keys}
  }
  options = {muteHttpExceptions: true};
var response = UrlFetchApp.fetch(url,header,options)
var data = JSON.parse(response.getContentText())
tech = ""
for(let i = 0; i < data.tech.length; i++) {
  tech += data.tech[i] +","
}
return tech
}

Why am I getting this error?


Solution

  • You can try this :

    function linkedInUrl(domain) {
      let url = `https://company.clearbit.com/v2/companies/find?domain=${domain}`
      const api_keys = ""
      const header = {
         method: 'GET',
        headers: {'Authorization':'Bearer ' + api_keys}
      }
      options = {muteHttpExceptions: true};
      var res
      fetch(url,header,options)           //api for the get request
      .then(response => response.json())
      .then(data => console.log('response',data))
    
    }