I'm trying to use the resmush.it API from Apps Script and I'm struggling when making the request with UrlFetch
.
From their documentation, I understand they need a files array, in a multipart/form-data request.
What I'm doing so far (the images come from a Google Slides)
function myFunction() {
const OPTIMIZER_URL = "http://api.resmush.it/ws.php"
let slides = SlidesApp.openById("1TUZSgG_XXX_ni6VhdbE5usRyMc");
let pages = slides.getSlides();
pages.forEach((page) => {
let images = page.getImages();
images.forEach(image => {
let payload = {
files: [{
file: image.getBlob()
}]
}
let options = {
method: "POST",
payload: payload,
muteHttpExceptions : true
}
let response = UrlFetchApp.fetch(OPTIMIZER_URL, options)
let jsonResponse = JSON.parse(response.getContentText())
console.log(jsonResponse);
})
})
}
I also tried with payload = { file: image.getBlob() }
but no success.
I get this error everytime:
{ error: 400,
error_long: 'No file or url provided',
generator: 'reSmush.it rev.3.0.4.20210124' }
Can you see what is wrong ?
Thank you