google-apps-scriptfetch-apiurlfetch

Fetch data from API CLEARBIT with GOOGLE APP SCRIPTS -


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."

Before writing this post I tried to search online but couldn't find the answer.

I share with you 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
}

Does anyone have a clue ?

Thank you for your help.


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))
    
    }