Traq 3.1: The API

Development related discussion.
Post Reply
User avatar
Jack
Advanced Member
Posts: 668
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Traq 3.1: The API

Post by Jack » Tue Feb 05, 2013 7:31 pm

Traq 3.0 has a ready-only API which can be accessed by appending ".json" to some of the URLs, like so: http://bugs.traq.io/traq/tickets/115.json



This API is being extended in 3.1 to allow creating, editing and deleting.



Here's an example, let's say an admin wants to create a new project, they'll first need to create their API key by going to the UserCP.



They API key needs to be sent along with all API requests that require the user to be authenticated.



Here's an example using cURL:

Code: Select all


$ curl http://path.to/traq/admin/projects/new -d access_token=api_key_here



{"status":0,"errors":{"name":"Name cannot be blank","slug":"Slug cannot be blank"}}



As we can see here, our project wasn't created, we forgot to set the name and slug.



Let's try again

Code: Select all


$ curl http://path.to/traq/admin/projects/new -d access_token=api_key_here -d name=Test -d slug=test



{"status":1,"project":{"name":"Test","slug":"test","codename":null,"info":null,"enable_wiki":0,"id":"2"}}



It worked, the API also passed us back the project we created.



Updating via the API works pretty much the same, let's update a user:

Code: Select all


$ curl http://path.to/traq/admin/users/2/edit -d access_token=api_key_here -d group_id=1



{"status":1,"user":{"id":"3","username":"tester","password_ver":"crypt","name":"Tester","group_id":"1",

"locale":null,"options":null,"created_at":"2013-02-05 19:24:05"}}



The only difference is that we only specify the fields we want to change, like the group_id.



Deleting is the simplest of all API calls, but be careful, it cannot be undone.

Code: Select all


$ curl http://path.to/traq/admin/projects/2/delete -d access_token=api_key_here



{"status":1}



One thing that is common in all API calls is that the returned message contains a status, this is always be either a 1 or 0.



If the request completed successfully, status would be 1, if there are errors, then it would be 0, if there are any error messages, they will be in the "errors" array.



Setting the API key (access_token) can be done two ways, by sending it as request/post data ("access_token=api_key") or by sending it as a header ("Access-token: api_key").
Last edited by Jack on Thu Feb 07, 2013 1:08 am, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests