javascriptbitrix

How do I use the Bitrix API to filter contacts using multiple values for one key?


I'm trying to return a list of contacts that could match multiple "PHONE" values. Right now I can get a list that matches one phone value but not an array of phone values. Here's what I have:

let contactList = await bitrix.call('crm.contact.list', {
        "filter": {
            "PHONE": phoneArray,    //example ["1112223344","5556651234"]
        },
        "select": ["*","EMAIL","PHONE"]
    });

I'm basing this off their API documentation that shows how to match one phone value here

There's also another article I found that mentions using a "LOGIC":"OR" in a filter that could potentially work. It's written in PHP so I'm not exactly sure how it translates to javascript.


Solution

  • You can use crm.duplicate.findbycomm (https://training.bitrix24.com/rest_help/crm/auxiliary/duplicates/crm.duplicate.findbycomm.php):

    BX24.callMethod(
        "crm.duplicate.findbycomm", 
        {
            entity_type: "CONTACT",
            type: "PHONE",
            values: [ "8976543", "11223355" ],
        }, 
        function(result) 
        {
             if(result.error())
                  console.error(result.error());
             else
             {
                  console.dir(result.data());          
             }
        }
    );
    

    but there are limitations:

    An array containing up to 20 e-mails or phone numbers

    Maybe it will do use batch (https://training.bitrix24.com/rest_help/js_library/rest/callBatch.php)

    Unfortunately crm.contact.list can't match multiple "PHONE" values