Can't set values of custom fields via the API?

Support for Traq 3.x
Post Reply
User avatar
harinder
Newbie
Posts: 4
Joined: Mon Jun 20, 2016 7:54 am

Can't set values of custom fields via the API?

Post by harinder » Mon Jun 20, 2016 8:26 am

Hi!
 
Are we able to set/modify the values of custom fields via the API?
 
Using the API, I am able to insert new tickets. But it looks like the API won't set values of my custom fields.
Here is the image (http://imgur.com/fAnRxDs) which shows one of my custom fields. When I add a new ticket, the summary and description are set just fine, but my custom field doesn't get set.
 
This custom field is of type select, I also tried to set a free form field but was unable to.
 
POST http://<hostname>.com/traq/<project>/tickets/new HTTP/1.1
summary=My Summary&description=My description&ig_device=Android
 
Looking forward to you resposne.
 
 
EDIT:  Here is me doing the same with cygwin
 
$ curl http://<hostname>.com/traq/<project>/tickets/new -d access_token=0f9503b6729eaaa5c0ec23f7fc5d6861a9065768 -d summary="Testing" -d description="New Description" -d ig_device="Android" -d from="email@something.com"

{"status":1,"version":"1.0","ticket":{"extra":[],"tasks":"[]","summary":"Testing","body":"New Description","ticket_id":"15","is_closed":1,"created_at":"NOW()","id":"15","votes":0,"project":{"id":"1","name":"iGurbani"},"user":{"id":"1","username":"admin","name":"Administrator"},"assigned_to":null,"milestone":null,"version":null,"component":null,"status":null,"priority":null,"severity":null,"type":{"id":"1","name":"Defect"}}}

 
 
EDIT2: Fix link to the image
 
Thank you!
Harinder
Last edited by harinder on Tue Jun 21, 2016 8:16 am, edited 1 time in total.

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Can't set values of custom fields via the API?

Post by Jack » Tue Jun 21, 2016 10:22 pm

Setting the value of a custom field is different than other fields, it's also a little weird.
 
The current way is instead of using the custom fields "slug", you need to pass "custom_field[x]", where "x" is, is the custom fields ID.
 
For example, if we had a custom field named "PHP version" and its ID is 3, we'd set the value of it like so:

Code: Select all

POST http://my.site/traq/project/tickets/new
custom_fields[3]=7.0
Last edited by Jack on Wed Jun 22, 2016 5:22 am, edited 1 time in total.
Reason: Fix typo

User avatar
harinder
Newbie
Posts: 4
Joined: Mon Jun 20, 2016 7:54 am

Re: Can't set values of custom fields via the API?

Post by harinder » Wed Jun 22, 2016 4:54 am

Thank you for your response Jack. That way actually didn't work me. So I manually updated a ticket while Firebug was up hoping that you use the API as well. That's when I saw that there was a slight typo in your response. It's custom_fields, you were missing the trailing 's'.
 
Now I'm using custom_fields[id] and it is working well. Thanks for your help!

User avatar
Jack
Advanced Member
Posts: 666
Joined: Fri Mar 27, 2009 7:37 pm
Location: Australia

Re: Can't set values of custom fields via the API?

Post by Jack » Wed Jun 22, 2016 5:26 am

[quote="harinder"]
That's when I saw that there was a slight typo in your response. It's custom_fields, you were missing the trailing 's'.
[/quote]
 
Ah, my bad, thanks for pointing out the typo.
 
In Traq 4.0, setting custom field values will be easier, they'll use the 'slug' field instead. This may also be done for Traq 3.7, but at the moment I'm focusing on 4.0.

User avatar
harinder
Newbie
Posts: 4
Joined: Mon Jun 20, 2016 7:54 am

Re: Can't set values of custom fields via the API?

Post by harinder » Wed Jun 22, 2016 6:56 am

I'm tied to a hosting environment which only gives v3.6. Likely won't be able to upgrade anytime soon :-(

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests