I have a NodeJS app I am writing that will manipulate slides in my Google Slides Presentation. I am trying to reorder all the slides in my Google Slides presentation at one time. I keep getting this error: reason: GaxiosError: Invalid requests[0].updateSlidesPosition: The slides should be in presentation order, with no duplicates.
I don't even know what "in presentation order" means.
I have 11 slides in my presentation with ID's looking like "Sermon-Slide-9","Sermon-Slide-3","Sermon-Slide-0", "Sermon-Slide-1", etc
. And I wanted them placed in numerical order so Sermon-Slide-0, Sermon-Slide-1, Sermon-Slide-2, etc
.
Here is the function that is doing the reordering:
const reorderSlidesNumerically = async (slideCount, slidesApi, fileID) => {
let slideObjectIds = [];
for (let i = 0; i < slideCount; i++) {
slideObjectIds.push('Sermon-Slide-' + i);
}
console.log({ slideObjectIds });
const requests = [{
"updateSlidesPosition": {
"slideObjectIds": [...slideObjectIds],
"insertionIndex": 0
}
}];
console.log({requests});
const batchUpdateRequest = { requests };
await slidesApi.presentations.batchUpdate({
presentationId: fileID,
requestBody: batchUpdateRequest,
});
};
And here is part of the response I am receiving back:
body: '{"requests":[{"updateSlidesPosition":{"slideObjectIds":["Sermon-Slide-0","Sermon-Slide-1","Sermon-Slide-2","Sermon-Slide-3","Sermon-Slide-4","Sermon-Slide-5","Sermon-Slide-6","Sermon-Slide-7","Sermon-Slide-8","Sermon-Slide-9","Sermon-Slide-10"],"insertionIndex":0}}]}',
responseType: 'json',
retryConfig: {
currentRetryAttempt: 0,
retry: 3,
httpMethodsToRetry: [Array],
noResponseRetries: 2,
statusCodesToRetry: [Array]
}
},
code: 400,
errors: [
{
message: 'Invalid requests[0].updateSlidesPosition: The slides should be in presentation order, with no duplicates.',
domain: 'global',
reason: 'badRequest'
}
]
}
Invalid requests[0].updateSlidesPosition: The slides should be in presentation order, with no duplicates.
and your request body, I thought that the reason for your current issue is due to that all slides are inserted to one index of "insertionIndex": 0
. I thought that the slide of the index of 0
is included in slideObjectIds
in your situation. In this case, it seems that when your request body is used, such an error occurs.In order to avoid this, how about the following modification?
const requests = [{
"updateSlidesPosition": {
"slideObjectIds": [...slideObjectIds],
"insertionIndex": 0
}
}];
const requests = slideObjectIds.reverse().map((e) => ({
updateSlidesPosition: { slideObjectIds: [e], insertionIndex: 0 },
}));