Array in CRM response

Status
Not open for further replies.

hoibat

Platinum Partner
Advanced Certified
Joined
May 25, 2020
Messages
16
Reaction score
6
Hi!
I'm having trouble integrating a custom CRM (Pipedrive).
We've been working with this template: https://www.3cx.com/community/threads/pipedrive-3cx-server-side-integration.65431/ (Thanks @Mark Phillips :) )

Unfortunately the API on Pipedrive will change and a couple of API Elements will be removed in further versions. So we tried to adapt to the new API.
My problem is, that the new API will return all phone numbers to a contact in no order and without any path description, see the example:

JSON:
{
  "success": true,
  "data": {
    "items": [
      {
        "result_score": 0.489265,
        "item": {
          "id": 5,
          "type": "person",
          "name": "Blub Bla",
          "phones": [
            "0791111111",
            "0793333333",
            "0794444444",
            "0792222222"
          ],
          "emails": [
            "[email protected]"
          ],
          "visible_to": 3,
          "owner": {
            "id": 12159201
          },
          "organization": null,
          "custom_fields": [],
          "notes": []
        }
      }
    ]
  },
  "additional_data": {
    "pagination": {
      "start": 0,
      "limit": 100,
      "more_items_in_collection": false
    }
  }
}

Now, how can I match the phone numbers to variables in a GET request?

Thanks a lot and best regards,
Guido
 
Hello Guido,

Unfortunately it's not possible to get array values like that. If the array contains an object, and you can filter by some field, it would be possible, for example:
JSON:
[
    {
        "type": "mobile",
        "number": "0791111111"
    },
    {
        "type": "business",
        "number": "0793333333"
    }
]

But having only the numbers it's not possible. The only option you have is creating some proxy, which you can invoke, and then the proxy invokes the real API and returns a JSON that can be processed by 3CX.
 
Hmm yeah I know, if the object would have names, it would be a breeze...
But to proxy this isn't really an option, since we'd have to handle yet another server for just doing this and we'd have to maintain and cater for all unforseen circumstances... not really feasible.

Will 3CX ever be able to handle arrays in JSON GETs? I mean, is this something that's on a roadmap?
 
Well, supporting this is not that easy, because there is no way to distinguish an element from the other. So how would you map an element to the mobile phone field and other to the business phoen field? This is why the scenario is not supported. IMHO this is a bad design on the Pipedrive API. They should provide details for each phone number, and return the information properly formatted.
 
In my opinion, you are completely right. :) But we cannot do anything about the mess on Pipedrive's end. ;)

I hear you there, it's almost impossible to distinguish between what would be a mobile and what not and people could still use a mobile for work and so on and on.
But I'd already be fine with mapping the number to a general "phone" field, so that contact lookup wouldn't fail when there are more than one number on a contact.
 
If you're confident that the CRM will return the right record when you invoke the lookup API, something you can do is completely ignore that array, and assign the pre-existing variable Number to an output. This way the record will be considered valid, but you will only get the number you're searching for. If the CRM returns other 3 numbers, they will not be in the 3CX Contact entry created.
 
For example:
<Output Type="PhoneBusiness" Passes="0" Value="[Number]" />
 
Ha, good idea! I'll try that.
This way the lookup should work and I could skip the responses to get to my next scenario. I'll let you know if there is progress. :)
 
  • Like
Reactions: edossantos
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,324
Messages
591,897
Members
165,475
Latest member
lastshadow