Legacy Dev Forum Posts

 View Only

Sign Up

API - Seach within externals contacts by "Middle name" as input

  • 1.  API - Seach within externals contacts by "Middle name" as input

    Posted 06-05-2025 18:42

    Mostafa_OUDDERHEM | 2021-02-05 15:15:48 UTC | #1

    Hi,

    I have configure a custom data action that is working fine and search by phone number to retrieve data about the contact. Now we want to create another custom data action that search on the externals contacts through the Middle name field instead of phone number.

    Is it possible to create it ? if yes, how we can do it ?

    Thank you in advance


    Jerome.Saint-Marc | 2021-02-05 15:55:27 UTC | #2

    Hello,

    I assume you are using this API request to search for an external contact based on a phone number: GET /api/v2/externalcontacts/contacts?pageSize=100&q=ThePhoneNumber

    You can use the same API request to search an external contact based on a middle name: GET /api/v2/externalcontacts/contacts?pageSize=100&q=TheMiddleName

    The same limitation applies - I mean that you can retrieve/fetch at max 1000 records with this request. https://developer.mypurecloud.com/api/rest/v2/externalcontacts/#get-api-v2-externalcontacts-contacts

    Regards,


    anon39326996 | 2021-02-05 16:00:07 UTC | #3

    Keep in mind that our current searching capabilities will search across all the contacts, in google style fashion. We will not search for only contacts with the middle name "John" but for all contacts that have the word "John" in their profile, whether that value is stored in a custom field or first name or middle name or last name.

    If you would like to search for middle names and middle names only, that would be a new capability for us to add. The perfect way to request that feature would be via our ideas portal and by providing the use case.


    Mostafa_OUDDERHEM | 2021-02-05 17:30:17 UTC | #4

    Hi Jerome, Thanks for your reply, but how to set the middle Name as variable to be inserted on the input of the API here what I have configured on the Request of the data action:

    { "requestUrlTemplate": "/api/v2/externalcontacts/contacts?pageSize=100&q=TheMiddleName", "requestType": "GET", "headers": { "UserAgent": "PureCloudIntegrations/1.0", "Content-Type": "application/x-www-form-urlencoded" }, "requestTemplate": "${input.rawRequest}" }

    Before it was:

    /api/v2/externalcontacts/contacts/?q=${input.query}

    I want to search by entering the middle name on the input.query.

    Thank you.

    Mostafa


    Jerome.Saint-Marc | 2021-02-05 18:20:01 UTC | #5

    When I used "TheMiddleName" in my reply, it was as an example. I mean like John, Bill, Frank, ...

    So it is the same than what you have with your existing Data Action: /api/v2/externalcontacts/contacts/?q=${input.query} Your "query" input parameter can take a phone number, the user's middle name, the user's lastname. No change in your Data Action definition.

    But as Lucie said above, you have to keep in mind that the search will try to find the content of q (input query parameter) inside any fields of the external contact. So if your input.query parameter is set to "John", "*We will not search for only contacts with the middle name "John" but for all contacts that have the word "John" in their profile, whether that value is stored in a custom field or first name or middle name or last name*"

    You may then receive more than one external contact in your search. And as it is described in the /api/v2/externalcontacts/contacts/ API endpoint, you can retrieve a maximum of 1000 records.

    You can control the page size in your Data Action, modifying it a little bit (ex: retrieving up to 100 records in a single page): /api/v2/externalcontacts/contacts?pageSize=100&q=${input.query}

    Regards,


    Mostafa_OUDDERHEM | 2021-02-10 08:49:52 UTC | #6

    Hi Jerome,

    Thanks, it works fine now.

    I have just issue with some contacts which are not having the workphone configured, when I search through middle name, I got this error:

    { "message": "Failed while processing the translation map. Could not resolve value for the key: 'workPhone' and no default value was configured. Additional details: Missing property in path $['entities'][0]['workPhone']", "code": "bad.request", "status": 400, "messageParams": {}, "contextId": "ac353966-82a3-4fde-9c34-66bca329e5b7", "details": [ { "errorCode": "ACTION.PROCESSING" } ], "errors": [] }

    Any idea ?

    Thank you.


    Jerome.Saint-Marc | 2021-02-10 12:50:11 UTC | #7

    Hello,

    I have defined 2 variables in my output contract: contactPhone as STRING nbFoundContacts as INTEGER

    My Response configuration looks like this:

    { "translationMap": { "firstPhone": "$.entities[0].workPhone.e164", "totalContacts": "$.total" }, "translationMapDefaults": { "firstPhone": "\"UNKNOWN\"", "totalContacts": "0" }, "successTemplate": "{\n \"contactPhone\": ${firstPhone}, \"nbFoundContacts\": ${totalContacts} \n }" }

    If no contacts are found (empty entities array), nbFoundContacts will be equal to 0 If contacts are found but the first contact has no workPhone, nbFoundContacts will be greater than 0 and contactPhone will be equal to "UNKNOWN".

    Regards,


    Mostafa_OUDDERHEM | 2021-02-10 15:05:18 UTC | #8

    Hi Jerome,

    Yes, it works fine now, many thanks for your help.

    Regards.


    system | 2021-03-13 15:05:21 UTC | #9

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 9920