最近の検索


最近の検索はありません

Search API for custom records using "contains"



投稿日時:2022年3月28日

Hi,

I have an API call to the search endpoint of the custom objects API (https://developer.zendesk.com/api-reference/custom-data/custom-objects-api/search/). I want to return records using a "like" sentence and my understanding from documentation is that you must use "contains" for that (https://developer.zendesk.com/api-reference/custom-data/custom-objects-api/search/#comparison-object). But in my case, it works as "eq". Example: The field to search is an string that can contains numbers so I want to return all records that have a number 2 in that string (e.g. AB2, 2AB...). If I use "$contains": "2", it returns no records. If I use "$contains": "AB2" or "$contains": "2AB", it returns one record.

Is that the expected behavior? If so, is there any way to get records back using a "like" instruction in a field that just contains one string?

Thanks.

Regards,

Lydia 


0

4

4件のコメント

      Hi Lydia!
       
      Thank you for clarifying and following up. Appreciate you sharing your findings and providing that documentation link. Glad you were able to get that clarity!
       
      Best, 
       
      Erica 

      0


      Update: That's the intended behavior as explained here: https://developer.zendesk.com/documentation/custom-data/custom-objects/searching-object-records/#building-a-basic-query

      For more information about the operators, see Comparison Object in the API reference. For example, despite its name, the $contains operator looks for whole word matches. If you search for "sig", the response will not contain any instances of "sign".

      0


      Hi Erica,

      The field that I'm using for querying is a string so if I remove the quotes I get an error:

      {
          "errors": [
              {
                  "code": "BadRequest",
                  "status": "400",
                  "title": "Bad Request",
                  "detail": "query $and: ref_number: $contains: Cannot pass NUMBER type as a value with '$contains' operator"
              }
          ]
      }

       

      Regards,

      Lydia

      0


      Hi Lydia,
       
      Have you tried searching for 2 without the quotes? I believe that when you place the query value in quotes it treats it as a phrase search instead of a prefix search. It ends up looking for a phrase where the full value is 2 instead of just part of it. 
       
      Hope this helps!
       
      Best,
       
      Erica 

      0


      サインインしてコメントを残します。

      お探しのものが見つかりませんか?

      新規投稿