Loading...
 
Skip to main content

Features / Usability


Creating and modifying tracker items via API

posts: 3 Catalan Countries

Hello.
I need to create and modify tracker items from an external program in Linux environment.
I've correctly set up the API access with its bearer token and I'm able to read tracker items and to change their status, via API, but I can not modify them or create new items. API is throwing this response all the times:

{"code":400,"errortitle":"Tracker item could not be created.","message":"Tracker item could not be created."}


I think the format of the request body I'm sending is not accepted by the API. I can not find any example in the doc API page 2 or in the forums on how to build the request although I've found this example 1 and used that format but it didn't work.

The format I'm using with API page and with curl as well is:

"fields": {

"logName": 1,
"logInterface": 2,
"logUser": "jdoe",
"logIP": "1.1.1.1",
"logMAC": "ffffffff",
"logHostname": "joesmacbook",
"logAction": "INIT",

}


Which is the same than the 1 example:

"fields": {

"newsTitle": "a test title",
"newsURL": "https://tiki.org",
"newsSummary": "a test news summary",
"newsDate": now,

}


Which is the correct request body format to, in this case, modify a tracker item?
Also, which is the correct one to create new items?

It would be nice to have some examples in the doc page 2.

Thank you.

F. Ken

1 https://dev.tiki.org/API-Access-Example
2 https://doc.tiki.org/API

posts: 1 Democratic Republic of the Congo
F. Ken wrote:

Hello.
I need to create and modify tracker items from an external program in Linux environment.
I've correctly set up the API access with its bearer token and I'm able to read tracker items and to change their status, via API, but I can not modify them or create new items. API is throwing this response all the times:

{"code":400,"errortitle":"Tracker item could not be created.","message":"Tracker item could not be created."}


I think the format of the request body I'm sending is not accepted by the API. I can not find any example in the doc API page 2 or in the forums on how to build the request although I've found this example 1 and used that format but it didn't work.

The format I'm using with API page and with curl as well is:

"fields": {

"logName": 1,
"logInterface": 2,
"logUser": "jdoe",
"logIP": "1.1.1.1",
"logMAC": "ffffffff",
"logHostname": "joesmacbook",
"logAction": "INIT",

}


Which is the same than the 1 example:

"fields": {

"newsTitle": "a test title",
"newsURL": "https://tiki.org",
"newsSummary": "a test news summary",
"newsDate": now,

}


Which is the correct request body format to, in this case, modify a tracker item?
Also, which is the correct one to create new items?

It would be nice to have some examples in the doc page 2.

Thank you.

F. Ken

1 https://dev.tiki.org/API-Access-Example
2 https://doc.tiki.org/API


Hello F. Ken,
I understand your concerns about the API documentation. We are actively working to improve it for better clarity and ease of use.

In the meantime, here's how you can create and update items in a tracker.

Creating an Item:
Use the fields' permanent names. For example, if your tracker is named "news" and you have fields like Title, URL, Summary, and Date, it will look like this:

Image

Here's the curl request to create an item:

curl
Copy to clipboard
curl -X 'POST' \   'http://example.com/api/trackers/58/items' \   -H 'Authorization: Bearer YOUR_API_TOKEN' \   -H 'accept: application/json' \   -H 'Content-Type: application/x-www-form-urlencoded' \   -d 'fields[newTitle]=Tiki trackers&fields[newURL]=https://tikitrackers.org&fields[newSummary]=assist workflows by tracking tasks&fields[newDate]=1718825506'


Updating an Item:
To update an item, include the item ID in the request. For example, with item ID 338:

curl
Copy to clipboard
curl -X 'POST' \   'http://example.com/api/trackers/58/items/338' \   -H 'Authorization: Bearer YOUR_API_TOKEN' \   -H 'accept: application/json' \   -H 'Content-Type: application/x-www-form-urlencoded' \   -d 'fields[newTitle]=Tiki trackers&fields[newURL]=https://tikitrackers.org&fields[newSummary]=act as expanded polls, surveys or quizzes&fields[newDate]=1718825591'


I hope this helps! Feel free to reach out if you have any more questions.

posts: 3 Catalan Countries

Hello Bruno,
thank you for your reply! Now I can insert and update items via API instead of calling (and approving each time) PluginListExecute, which is a big step forward. It also helps me to log external events to a tracker. Very very useful.

These two examples would be very helpful if they were placed in the API doc page. I know it's not an easy job to keep the doc updated. You make a great work. Thank you!

Ken