Search code examples
google-apps-scriptactivecollab

Which calls need an access token in ActiveCollab v5 API


I'm playing with Google Apps Script utilizing the ActiveCollab HTTPS API as a way to link Google Forms to specific projects. I can't figure out where to use the access token in the HTTP request when creating a Task in a project.

Maybe I'm missing it, but which API calls in the documentation require the access token as part of the POST request?

The most basic POST request I've sent was:

var token = // token from authentication

{
  "name": "Test task",
  "token": token
}

...and it returned a 401 error, saying I wasn't authenticated.

So, I tried:

var token = // token from authentication

{
  "name": "Test task",
  "username": // my username,
  "password": // my password,
  "token": token
}

...with the same result. So, which calls require a token and does the token go in the POST payload? Or should it be in the POST options?

Update 3/10/2016

I have added the Authorization parameter to the POST request and am now receiving an invalid token error in the response. I've cleared my cache and reauthorized successfully. My test function is below.

function postTicket() {

  // Retrieve the stored token after a successful authorization
  var token = PropertiesService.getScriptProperties().getProperty("token");

  var data = {
    "name": "Testing task"
  }

  var headers = { 
    Authorization: 'Bearer ' + token
  };

  var options = {
    "method": "post",
    "contentType": "application/json",
    "headers": headers,
    "payload": JSON.stringify(data)
  }

  try {
    var url = BASE_URL + "/projects/8/tasks";
    var response = UrlFetchApp.fetch(url, options);
    var json = response.getContentText();
    var data = JSON.stringify(json)

    Logger.log(data);
  } catch (e) {
    Logger.log(e);
  }
}

The logged error is:

returned code 500.{"type":"ActiveCollab\Authentication\Exception\InvalidTokenException","message":"Authorization token is not valid","code":0


Solution

  • I had the same problem, but after checking Active Collab SDK code i figured out, that we should use these headers:

    var headers = { 
      'X-Angie-AuthApiToken': token
    };
    

    By using this code i'm allowed to create tasks via API.