How to format JSON params for Transloadit API using UrlFetchApp

182 Views Asked by At

I am attempting to create a transloadit New Assembly using their API detailed here (https://transloadit.com/docs/api/#assemblies-post) with a google apps script UrlFetchApp post.

When running, i receive: Request failed for https://api2.transloadit.com/assemblies returned code 400. Truncated server response: {"error":"INVALID_PARAMS_FIELD","message":"Bad params field provided, it contains invalid json."}

How should the params object be created to become valid json?

function Run_Transloadit_Assembly(){

  var data = {"params":{
                "template_id":"...ID...",
                "auth":{
                  "key":"...KEY..."
                }
              }
             }
  var payload = JSON.stringify(data);

  var options = {
    'method' : 'post',
    'contentType': 'application/json',
    'payload' : payload
  };

  var api_url = 'https://api2.transloadit.com/assemblies'
  var response = UrlFetchApp.fetch(api_url,options);

  Logger.log(response)

}
0

There are 0 best solutions below