Jump to content


Click here to lend your support to: Traq and make a donation at pledgie.com !
Photo

Traq 3.1: The API


  • Please log in to reply
No replies to this topic

#1 Jack

Jack

    Project Founder

  • Administrators
  • 673 posts
  • LocationAustralia

Posted 05 February 2013 - 08:31 AM

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/...ickets/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:
$ 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
$ 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:
$ 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.
$ 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").


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users