Skip to main content
Question

How to get data from table with javascript

  • September 5, 2024
  • 4 replies
  • 102 views

What we need to do:

Foreach Line item  in order do a lookup in table to find matching rows and return that rows as result

 

When we do a test run we receive following output: 

ID

AD5l9WavzQVmPkPbzEhp8B7baTLu129E

runtime_meta

Runtime Meta Memory Used Mb

77

Runtime Meta Duration Ms

392

Runtime Meta Logs

Runtime Meta Async

true

 

The code used is : 

const nameToLookup = inputData.Name;

async function repeat(nameToLookup) {
  const result = []
  nameToLookup.split(",").forEach(function (item) {
      const response =  fetch(`https://api.zapier.com/v1/tables/01J6VZ03B4FTXXN29VTZTHW9P8/rows?filter[Product]=${encodeURIComponent(item)}`, {
        method: 'GET',
        headers: {
          'Authorization': `Bearer ${process.env.ZAPIER_API_KEY}`,
          'Content-Type': 'application/json'
        }
      }).then(
        data => {
          result.push(data.json())
        }
      )
  });

  return result;
}

const data = await repeat(nameToLookup);

output = data.length > 0 ? data[0] : {};

 

Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30739 replies
  • September 5, 2024

Hi @Wemessage 

Help links for using Code Zap app: https://zapier.com/apps/code/help

Output needs to be like this:

 


  • Author
  • Beginner
  • 2 replies
  • September 6, 2024

Hi @Troy Tessalone,

 

i think we have problem with missing API key .. can’t find where we can get one.

 

That is why we get no answer back.


Troy Tessalone
Forum|alt.badge.img+14
  • Zapier Expert
  • 30739 replies
  • September 6, 2024

@Wemessage 

Are you using a Code step in a Zap OR are you trying to build a Zap app integration using the Zapier Developer Platform?


  • Author
  • Beginner
  • 2 replies
  • September 9, 2024

Hi @Troy Tessalone ,

 

we are using code builder in ZAP.