REST2 - Get custom field values when listing tickets/transactions

I’m having trouble including the ‘CustomFields’ child block when using the GET /tickets and GET /transactions REST2 endpoints. If I wanted to include the creator of each ticket/transaction and their name (which is not included by default), I can do this using the fields parameter:

?fields=Creator&fields[Creator]=RealName

This would return the following block for each result in the collection:

"Creator": {
    "type": "user",
    "RealName": "John Doe",
    "_url": "https://my-rt/REST/2.0/user/johndoe",
    "id": "johndoe"
},

However, using a ?fields=CustomFields query parameter doesn’t work. Each result in the collection just contains "CustomFields": "" (an empty string).

Am I using the wrong query parameter, or is retrieving custom field values when listing tickets/transactions not currently possible via the REST2 API?

You cannot get all customfields, you have to list the wanted ones with fields=Creator,CF-CFNAME1,CF-CFNAME2 …

Thanks for the suggestion. I’m still not having any luck, though. I’ll go into more detail on what I’ve tried. All the examples below use the following POST body:

[
	{
		"field": "Created",
		"operator": ">=",
		"value": "2019-10-01T00:00:00Z"
	}
]

When I make the following API call:

POST /REST/2.0/transactions

I get:

{
  "per_page": 20,
  "page": 1,
  "total": 2,
  "count": 2,
  "items": [
    {
      "type": "transaction",
      "id": "741",
      "_url": "https://rt.example.com/REST/2.0/transaction/741"
    },
    {
      "type": "transaction",
      "id": "742",
      "_url": "https://rt.example.com/REST/2.0/transaction/742"
    }
  ]
}

If I want to get the time taken for each transaction, I can add a fields=TimeTaken parameter:

POST /REST/2.0/transactions?fields=TimeTaken

{
  "per_page": 20,
  "total": 2,
  "page": 1,
  "count": 2,
  "items": [
    {
      "type": "transaction",
      "id": "741",
      "TimeTaken": "30",
      "_url": "https://rt.example.com/REST/2.0/transaction/741"
    },
    {
      "type": "transaction",
      "_url": "https://rt.example.com/REST/2.0/transaction/742",
      "TimeTaken": "0",
      "id": "742"
    }
  ]
}

Trying to add a custom field in the same way isn’t working, though. I’ve got a custom field called Mute (ID 4), and none of the following work:

/REST/2.0/transactions?fields=TimeTaken,Mute
/REST/2.0/transactions?fields=TimeTaken,CF-Mute
/REST/2.0/transactions?fields=TimeTaken,CF-4
/REST/2.0/transactions?fields=TimeTaken,CustomFields&fields[CustomFields]=Mute

I just get a field in each response with the name of whatever I tried putting in fields, containing an empty string. For example:

POST /REST/2.0/transactions?fields=TimeTaken,Mute

{
  "total": 2,
  "per_page": 20,
  "count": 2,
  "page": 1,
  "items": [
    {
      "Mute": "",
      "type": "transaction",
      "TimeTaken": "30",
      "_url": "https://rt.example.com/REST/2.0/transaction/741",
      "id": "741"
    },
    {
      "TimeTaken": "0",
      "type": "transaction",
      "Mute": "",
      "_url": "https://rt.example.com/REST/2.0/transaction/742",
      "id": "742"
    }
  ]
}

Any suggestions about what might be wrong?

I would assume only core fields are supported, I believe you need to follow the link for the custom field to get the actual value.

I’ve just written the code this evening to support this feature (just thought I’d skim through the forums), please see my branch here:

1 Like