PBX / Create deal / Phone

We’re trying to integrate our PBX system with Pipedrive and now we’ve facing an issue here.
When we receive a call from existing client, a new deal is created. That’s not correct — a new activity should be created in an existing deal (e.g. “missed call” category).
This happens when contact number is not on the first position in “Person” entity.
As you know, it is possible to assign several numbers to a Person, but activity is created in existing deal only when client calls form number, that is written down on the first position. When it’s not - a new deal is created. We use webhooks for send data.

Is there any way to solve this issue?

I think I would need to see the exact coding you’re using in this case to get a better idea of what might be the issue. Can you share it here?
If not, can you send it to support@pipedrive.com and we can go through it there?

public function createDeal($repeat = '0')
    $dealData = array(
        'title' => $this->personData['name'],
        'person_id' => $this->personData['id']

    if (!is_null($this->personData['org_id']) && isset($this->personData['org_id'])) {
        $dealData['org_id'] = $this->personData['org_id'];

    // Whom to assign the deal
    if (!is_null($this->connectedWith)) {
        $pipe_id = $this->getPipeID($this->pipeKey, $this->connectedWith);
        if (!is_null($pipe_id)) {
            $dealData['user_id'] = $pipe_id;
        if (!is_numeric(($dealData['user_id']))) {
    // To which pipeline assign the deal
    if ($this->type == 'in') {
        $dealData['stage_id'] = $this->getDealStage($this->destinationID);
        if (!is_numeric(($dealData['stage_id']))) {

    // Redeclare the name of the deal to correct variable type
    $dealData = $this->getCorrectNameOfTheDeal($repeat, $dealData);
    // Taking custom fields
    $dealData = $this->takingCustomFields($dealData);
    // CURL Data
    if (is_null($dealData['person_id'])) {
        $this->grayLog('Deal was not created. Reason: empty person_id', $dealData);
        return false;
    $url = "https://api.pipedrive.com/v1/deals?api_token=" . $this->pipeKey;
    $result = $this->sendPostCurl($url, $dealData);
    // check if an id came back
    if (!empty($result['data']['id'])) {
        $this->data['deal_id'] = $result['data']['id'];
        return true;
    } else {
        $this->grayLog('Deal was not created. Result: ' . $result, $dealData);
        return false;

Talking to some of my team to get a better answer - but can you give some more details on how you’re using webhooks to send data when you receive a call?

Also, if you have the data on the Persons, can you check how many contact number the Person has? Any more context and details you can provide would be very beneficial.

  1. Could you please clarify first question?
  2. Person can has 2 or 3 phone numbers.

up up up! :grinning::grinning::grinning::grinning::grinning:

Hi @modeb, looking at the code is see no reference to Activity creation, is that the whole code related to the problem?

@diego.mendez I don’t see how “Activity” creation could be the problem.
The issue is related to “Deal” creation.
Or maybe you mean “Activity” with “call” type?

Hi @modeb, in your first message you mentioned that an activity should be created within a deal, but in the code you shared there is no reference to this, I can only see a function for deal creation. But you mention that a new deal being created is not correct.

* Create activity
* @return boolean
public function createActivity()
$actData = array(
‘due_date’ => date(‘Y-m-d’),
‘due_time’ => date(‘H:i’),
‘duration’ => $this->calculateDuration(),
‘note’ => $this->noteText,

    $actData = $this->detectNameFromTypeOfCall($actData);

    $getType = $this->getActivityType();
    if (!$getType) {
        $actData['type'] = 'call';
    } else {
        $actData['type'] = $getType;

    $actData = $this->detectingWhomToAssignTheActivity($actData);
    $url = "/activities";
    $result = $this->sendPostCurl($url, $actData);
    if (isset($result['data']['id'])) {
        $this->personData['id'] = $result['data']['id'];
        return true;
    } else {
        $this->grayLog('Pipedrive: Activity was not created. Info: ' . $result, $actData);
        return false;

Thanks for your reply @modeb. What I’m failing to see is the part related to the logic that you have to do to find the Pipedrive person once you get a phone number. Since the problem happens in this step we should see it in details. So once you have a phone number what are you doing exactly to find the matching person? If you use https://developers.pipedrive.com/docs/api/v1/#!/SearchResults/get_searchResults_field you should be able to get results for secondary phone numbers too.

Hi @diego.mendez,

I tried to search persons using url you provided and id of person is only returned in case when I use primary phone number to search. For testing purposes I’m working on Pipedrive’s online API form. field_type is “personField” and field_key is “phone”, return_item_ids is “1”. Can you please tell me, what I’m missing here?

$url = $this->config[‘pipedrive_url’] . “searchResults/field?term=%” . $term . “&exact_match=0&field_type=personField&field_key=phone&return_item_ids=1&api_token=” . $this->config[‘pipedrive_key’];
$output = $this->get($url);
$result = json_decode($output, 1);
if ($result[‘success’]) {
return $result[‘data’][0][‘id’];

    return null;

Here how we search deal by phone number

Hey @modeb I’m afraid you cannot search for a deal using a person’s field, you would first need to find the person and then the deals linked to it.

Could you please explain why? And what should be done if we really need that? Could you suggest any workaround to this?

Hi @modeb right now the only way is to first search the person and then search the deals linked to this person. Or you could add a custom field for deals and store the phone there too.