+1

API: How to add custom fields for classic projects (type: selection)

Juan (Comunica Translations) 1 year ago in API updated by Nate 1 year ago 6

Hello:

I was wondering if you could help me and give me an example on how to add a custom field to a project for a custom field of the type: SELECTION through the API.

In the API documentation I can see that this is the schema for the endPoint (PUT): /projects/{projectId}/customFields

[
  {
    "type": "TEXT",
    "name": "string",
    "key": "string",
    "value": {}
  }
]

But I don't really know what to set for the "value" property.
The custom field is a Single Selection type.

Thanks a lot.
My best regards.

Hi Juan,

You should just be able to put in the name of the option in the value field. So if your selection custom field has an option called "Active", and you'd like to assign the value "Active" for that custom field, your request body should look like this:

[
  {
    "type": "SELECTION",
    "name": "Status", // name of the custom field
    "key": "Status", // name of the custom field, again
    "value": "Active" // name of the option you'd like to select
  }
]

Let me know if this works for you 🙂

Thanks a lot for your answer, ecamci.
Really appreciate you took your time to answer me.

That totally worked!


Sharing my specific case just in case is useful for someone else.

So let's imagine we have a custom field called "CAT Tool", that is a selection type custom field.
Inside we have three different options: MemoQ, Phrase and Across. 

In order to choose Across:

[
{
"type": "SELECTION",
"name": "CAT Tool", // name of the custom field
"key": "CAT Tool", // name of the custom field, again
"value": "Across" // name of the option you'd like to select
}
]

Please notice that you need to send to the API an array of objects, if you just send one object, the API will give you a 400 error.
So you can set/change one or several custom fields in the same query:

[
{
"type": "SELECTION",
"name": "CAT Tool",
"key": "CAT Tool",
"value": "Across"
}, { "type": "SELECTION", "name": "Assistant PM", "key": "Assistant PM", "value": "Juan" }
]

Wish API implementation was similar to smart projects, where custom fields must be set one at a time and cannot be sent in an array of multiple objects.

I don't see it that bad.
If they were set one by one it would mean an API call for each one, which means $$$ 😜

I said that backwards. What I meant to say is I wish the smart project API implementation was similar to the classic projects. You're right, sending an array is better.