Having trouble with the Custom Object Record Search API | Community
Skip to main content

Having trouble with the Custom Object Record Search API

  • August 14, 2025
  • 1 reply
  • 0 views

I find the examples in the API documentation lacking and I've spent all morning trying to implement a search of my custom object records using the API.  I've tried the curl example in the docs (modified with my subdomain, custom object type and a relevant search query, of course.  Also, I found I needed to add -g to get curl to ignore the [ and ] globbing characters ) and got back “Invalid search: Unable to execute search request”. Is there something wrong with this?

curl --request GET https://$ZENDESK_SUBDOMAIN.zendesk.com/api/v2/custom_objects/type_of_custom_object/records/search\?page\[after\]\=\&page\[before\]\=\&page\[size\]\=100\&query\=usb\&sort\= --header "Content-Type: application/json" -u "$ZENDESK_EMAIL/token:$ZENDESK_API_TOKEN" -g

The environment variables are set up correctly and other API calls work just fine using them in this way.

 

I think it's also worth noting this. I've also tried in a node script that just tries the call the search endpoint, using node-fetch.  Code is also copied from the docs page, and modified with my relevant details and also to use node-fetch.  My code ended up looking like this:

var fetch = require('node-fetch');
const params = new URLSearchParams({
  "page[after]": "",
  "page[before]": "",
  "page[size]": "",
  query: "usb",
  sort: "",
});
const url = `https://${process.env.ZENDESK_SUBDOMAIN}.zendesk.com/api/v2/custom_objects/xyz/records/search?${params.toString()}`;
var config = {
  method: "GET",
  headers: {
    "Content-Type": "application/json",
    Authorization:
        Buffer.from(`Basic ${process.env.ZENDESK_EMAIL}/token:${process.env.ZENDESK_API_TOKEN}`).toString(
        "base64"
      ),
  },
};

fetch(url, config).then(function (response) {
  return response.text();
}).then(j => {
  console.log(j);
}).catch(function (error) {
  console.log(error);
});

And I get back “You passed an invalid value for the page.size attribute. Invalid parameter: page.size must be an integer from api/v2/custom_object_records/search”. Seems like the examples could be made to be more accurate? Also not sure why I get that error with the same URL in Node, vs not with curl.  Anyway, when I set “page[size]”: “100”,I again get “Invalid search: Unable to execute search request”

 

I've tried switching to the POST method, and adding a body to the options passed into fetch: 

  body: JSON.stringify({
    filter: {
      "custom_object_fields.myId": { $eq: 123 },
    },
  },

(The myId field is a number type). But still I'm getting the Invalid search: Unable to execute search request.

 

I'd appreciate any help. I'm probably just missing something simple, but these examples are pretty much just straight out of the API doc examples.

1 reply

  • September 2, 2025

Hi Dru,

For the curl search request at least, the query parameters should be url-encoded. It should look something like this:

curl -G "https://example.zendesk.com/api/v2/custom_objects/type_of_custom_object/records/search" \
    --data-urlencode "query=jdoe" \
    --header "Content-Type: application/json" \
    -u "$ZENDESK_EMAIL/token:$ZENDESK_API_TOKEN"

We'll update the examples.