Multiple phone numbers per ID in response

mh_koms

Gold Partner
Basic Certified
Joined
Dec 3, 2025
Messages
2
Reaction score
1
Hi specialists

I have a running and working CRM integration from an API. In 90% of cases, there is one phone number in the response of the API:
JSON:
"data": [
     {
       "dwhId": "DETBA00000000003844920000000072",
       "companyname": "Departement der Industriellen Betriebe  ",
       "firstname": "",
       "name": "",
       "street": "Beatenplatz",
       "houseNumber": "2",
       "zip": "8001",
       "location": "Zürich",
       "phoneNumbers": [
         "044 412 11 11"
       ],
       "mobileNumbers": []
     }]
]

in some rare cases, there are multiple numbers registered on the ID:
JSON:
"data": [
{
"dwhId": "DETBA00000000019753370000000072",
"companyname": "Zürich Versicherungs-Gesellschaft AG ",
"firstname": "",
"name": "",
"street": "Hagenholzstrasse",
"houseNumber": "60",
"zip": "8050",
"location": "Zürich",
"phoneNumbers": [
"*044 628 28 28",
"*0800 808 080"
],
"mobileNumbers": []
}
]


The first response is working, the second is not:
XML:
<Rules>
<Rule Type="Any">result.data.dwhId</Rule>
</Rules>
<Variables>
<Variable Name="ContactID" Path="result.data.dwhId">
<Filter />
</Variable>
<Variable Name="CompanyName" Path="result.data.companyname">
<Filter />
</Variable>
<Variable Name="FirstName" Path="result.data.firstname">
<Filter />
</Variable>
<Variable Name="LastName" Path="result.data.name">
<Filter />
</Variable>
<Variable Name="PhoneBusiness" Path="result.data.phoneNumbers">
<Filter />
</Variable>

How can I assign the first number to the variable, independent of how many are in the response?
I tried <Variable Name="PhoneBusiness" Path="result.data.phoneNumbers[0]"> already. Not working.

Any help and hints are very appreciated. Thank you.
 
Last edited:
The parser cannot read non-associative arrays. You would have to use an external script, or, look how they did Pipedrive as it does the same thing when doing a search (returns a flat array of phone numbers, whereas the full "get contact" returns a proper usable array.)
 
If you have control of the CRM (in case it's an in house development), you will need to edit the response and provide a way to identify each record. For example, instead of just returning an array of strings as you're doing now:
JSON:
"phoneNumbers": [
    "*044 628 28 28",
    "*0800 808 080"
]

You could return an array of objects that let you identify the phone type of each value, for example:
JSON:
"phoneNumbers": [
    {
        "number": "*044 628 28 28",
        "type:" "mobile"
    },
    {
        "number": "*0800 808 080",
        "type": "work"
    }
]

This way you can select the item from the array using a filter in the XML template.

If you can't change the JSON response returned by the CRM, something you can do is always setting the phone number being searched as an output, this way the record will be considered valid.
 
  • Like
Reactions: Evolute IT
If you can't change the JSON response returned by the CRM, something you can do is always setting the phone number being searched as an output, this way the record will be considered valid.
We cannot change the JSON. Thanks a ton for this tip! This solves my problem! Thank you.
 
Glad you have it working. The only thing to consider in this case is, if you have phonebook synchronization enabled, your contacts will start changing their phone numbers. Each contact will only have the last phone number from which they called. But it's a minor issue, and only when you are synching contacts.
 

Forum statistics

Threads
111,986
Messages
590,148
Members
164,917
Latest member
Oliver Hastedt