0

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.

Eddie
  • 26,593
  • 6
  • 36
  • 58
  • Possible an API interaction issue? – Jack Bashford Apr 19 '19 at 08:48
  • *Equivalent curl code:* `curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Token iputmytokenhere' -F left.source_url=https://api.draftable.com/static/test-documents/paper/left.pdf -F left.display_name=a1 -F left.file_type=pdf -F right.source_url=https://api.draftable.com/static/test-documents/paper/right.pdf -F right.display_name=a2 -F right.file_type=pdf -F public=false 'https://api.draftable.com/v1/comparisons' ` – Aakash Tripathi Apr 19 '19 at 08:56
  • Possible duplicate of [Mobiledevices: action missing](https://stackoverflow.com/questions/53416512/mobiledevices-action-missing) – TheMaster Apr 19 '19 at 10:49

0 Answers0