Help

Frame Links to AirTable -> Creating New Records

Topic Labels: Scripting extentions
1580 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Nancy_Melchert
4 - Data Explorer
4 - Data Explorer

Hello,
I’m quite the novice to javascript and have been trying to brute force my way into this script. I have a script set up to pull information from frame.io and that part works great. I can push the information I’m looking for to the console, but I want to create a table with the information in it. I believe I need to use createRecordsAsync but I get a little stuck. This is the code I have:

//Get Review Links

const projectId = '664531da-96f3-4e72-8577-4acb703daddc';
const resp = await fetch(
  `https://api.frame.io/v2/projects/${projectId}/review_links`,
  {
    method: 'GET',
    headers: {
      Authorization: 'Bearer REDACTED'
    }
  }
);

const data = await resp.json();
console.log(data[0]);

let table = base.getTable("ALL FRAME LINKS");
let linkyLink = await input.recordAsync("pick a record", table);

let assetName = table.getField("Asset Name");
let reviewLinkID = table.getField("ReviewLinkID");
let linktype = table.getField("TypeofLink");
for (i = 0; i < data.length; i++){
    console.log(data[i].short_url, data[i].name, data[i].id, data[i]._type);
    //await table.updateRecordAsync(linkyLink, {"URL": data[i].short_url});
    await table.createRecordAsync(data[i].short_url);
    // await table.updateRecordAsync(assetName, {"Asset Name": data[i].name});
    // await table.updateRecordAsync(reviewLinkID, {"ReviewLinkID": data[i].id});
    // await table.updateRecordAsync(linktype, {"TypeofLink": data[i]._type});

}


The first commented out command of updateRecordAsync went through the loop and put the URL in each one, but of course did not create new records, which is what led me to createRecordAsync. I seem to be missing a concept about objects and strings, or perhaps where to put this command within (or outside) the loop. Any guidance would be greatly appreciated. Thanks.

1 Reply 1
Nancy_Melchert
4 - Data Explorer
4 - Data Explorer

I figured it out a little while after posting this!

await table.createRecordsAsync([
      {fields: {
        "Asset Name": data[i].name,
        "URL": data[i].short_url,
        "ReviewLinkID": data[i].id,
        "TypeofLink": data[i]._type,
      }}
    ]);

Thanks API documentation!