0

Currently I am working on an app for Active Collab with ionic (AngularJS). When I tracked some time I want to post this time, so that I'll have this time in Active Collab. But when I tried to do that, I got an 500 Internal Server Error. This is my Code (I used the data from the Active Collab API Documentation, to test):

var postData = {
       "value": 1.5,
       "user_id": 1,
       "job_type_id": 1,
       "record_date": "2014-05-14",
       "billable_status": 0
};

$http.post(baseUrl+'/projects/' + projectId +'/time-records/', postData, { headers: { 'Content-Type': 'application/json' }}).then(function(res){ ... }

The post request work for getting the token (issue-token). So I have no idea what the problem is. I hope anyone can help me?

To make the token-post working I had to add some lines to api.php. Wouldn't this be good to be there per default?

if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  // return only the headers and not the content
  if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
      header('Access-Control-Allow-Headers: X-Requested-With');
  }
  exit;
}

Thanks in advance!

Y.B.
  • 3,526
  • 14
  • 24
Sarah
  • 1
  • 1
  • Your question does not contain enough info. First, what's the value of `baseUrl`? Second, do you send token to the server? Without token, your request will be rejected. Also, you did not include the response message from the server. 500 is just the status, but Active Collab will always provide a bit more info to help you see what went wrong (it provides a lot of info when you put the app in debug mode). – Ilija Jul 06 '16 at 21:17
  • Also, you don't need to change the Active Collab code to get API to work. Version 5 backend is one big API, and it is used by 4 first party apps, plus many third party apps, without a single code modification. If you need to patch the code, there's a problem in approach. – Ilija Jul 06 '16 at 21:20

1 Answers1

0

I am currently running Active Collab locally. So baseUrl is: http://my-ip-address/mypath-to-ac/api/v5/projects/56/time-records/ . I do have an authInterceptor, so token should be appended. I also tried to send it within the post-request, but got same error.

Now I debugged it a little more and it says that some fields are null. But I definitely filled those fields and sent them.

This is the logged Data, that I'll send with the request:

{"value":"1.5","user_id":10,"job_type_id":"0","record_date":1467965415.184,"billable_status":0}

And this is the error, I'll get: debugged error as screenshot

Sarah
  • 1
  • 1
  • Based on the error message, Active Collab does not receive any of the data that you sent (it just is not there because you get validation error that says that values for required fields are not provided). Make sure that payload that you described in your message actually gets sent as body of POST request (you are hitting the correct method and URL). – Ilija Jul 16 '16 at 21:06