I am trying to call an API from draftable.com (https://api.draftable.com/v1/comparisons) using Google App Script. The API takes two files and returns a string. I have made the GET and DELETE functions which are working fine, but when I run a POST function I am getting an error at the
UrlFetchApp.fetch("URL",object);
Error: Request failed for https://api.draftable.com/v1/comparisons returned code 400. Truncated server response: {"left":["This field is required."],"right":["This field is required."]}
I am passing a JSON like the code below:
function POST() {
var options = {
"method": "POST",
"headers": {
"Content-Type": "multipart/form-data",
"Accept": "application/json",
"Authorization": "Token {iputmytokenhere}",
},
"left": {
"source_url": "https://api.draftable.com/static/test-documents/paper/left.pdf",
"display_name": "old-example.docx",
"file_type": "pdf"
},
"right": {
"source_url": "https://api.draftable.com/static/test-documents/paper/right.pdf",
"display_name": "newer-example.docx",
"file_type": "pdf"
}
};
var result = UrlFetchApp.fetch("https://api.draftable.com/v1/comparisons", options);
var params = JSON.parse(result.getContentText());
Logger.log(params.identifier);
}
}
Can anyone tell me why is the error coming.