Challenge: I have received response.data from the Figma API, and my objective is to extract the “id” values from the nested structure. I am creating a Google Apps Script plugin that should generate slides in Google Slides for every page in Figma, each associated with their corresponding IDs.
Extracting Figma data:
var data = {
"file": {
"pages": [{
"id": "1:2",
"name": "Homepage",
"type": "CANVAS"
}]
}
}
var pages = data.file.pages;
var pagesArray = [];
for (var index in pages) {
pagesArray.push(pages[index].id);
}
var pageIDs = pagesArray;
Generating slides with Google Apps Script:
function createSlide(presentationId) {
var slideId = JSON.stringify(pageIDs[0]);
var requests = [{
'createSlide': {
'objectId': slideId,
'insertionIndex': 0,
'slideLayoutReference': {
'predefinedLayout': 'BLANK'
}
}
}];
var response = Slides.Presentations.batchUpdate({ 'requests': requests }, presentationId);
console.log('Slide created with ID: ' + response.replies[0].createSlide.objectId);
}
I tried using the push method to retrieve only the ID values but faced multiple errors. I’m not quite sure which method to use.
Additionally, I attempted to filter the IDs with the pageIDs.filter() method, which ran but created issues in my array manipulations, and I’m still unable to pass the slideId into my slide creation variable.
The Google Apps Script error I’m encountering is:
TypeError: Cannot call method “push” of undefined at function2(script:45)