0

I'm trying to make an external application that requests data from Bitrix24. If you take a look at the documentation, there's not much about the parameters used in the endpoints

https://training.bitrix24.com/rest_help/oauth/index.php.

Currently, I'm trying to get a list of all the data in the Deal table (crm.deal.list). That data is divided in two parts, the native fields (fields that bitrix has by default) and the user/custom fields (fields that a user creates) for some reason, when I use the method crm.deal.list crm.deal.list (bitrix24.com), it only returns the native fields. From what I saw online, I need to add certain parameters to the endpoint to actually get that custom data.

Now I have 2 problems: the parameters don't work, for example, if I need to select certain fields in the data that's returned, I would use something like this

https://{domain}/rest/{token}/crm.deal.list?select=["ID","TITLE"]. 

For some reason it doesn't work at all.

I don't know what is the parameter that I should use to get the custom fields. Sorry if I didn't explain some details, it's my first time here

var data = new List\<string\>()
        {
            "*", 
            "UF\_*"
        };

var para = new Dictionary\<string, object\>()
        {
            { "SELECT", data }
        };

var stringData = JsonSerializer.Serialize(para);    
        var URL = $@"https://{your_bitrix_domain}/rest/{access_token}/crm.deal.list.json/{stringData}";

using var client = new HttpClient();
try
        {
            var response = await client.GetStringAsync(URL);
            return Ok(response);
        }
        catch(Exception ex) 
        {
            Console.WriteLine(ex.ToString());
            return NotFound("fuck");
        }

This is the code that I'm using, the endpoint doesn't work, because the SELECT parameter doesn't get anything

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0

we must use Post and "para" send in body... I use sample code...

static string getResponseMessageByBitrix(Uri baseURI, string Query, string Params)
    {
        var content = new StringContent(Params, Encoding.UTF8, "application/json");
        UriBuilder builder = new UriBuilder(baseURI);
        builder.Query = Query;

        string a = builder.Uri.ToString();

        HttpClient client2 = new HttpClient();

        client2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        HttpResponseMessage response2 = client2.PostAsync(builder.Uri, content).ContinueWith(task => task.Result).Result;
        string httpResponseResult2 = null;
        if (response2.IsSuccessStatusCode)
        {
            return httpResponseResult2 = response2.Content.ReadAsStringAsync().ContinueWith(task => task.Result).Result;
        }
        else
        {
            return response2.StatusCode.ToString();
        }
        return "";
    }

And

string url = Url;
        Uri baseURI = new Uri(url);
        Uri newURI = new Uri(baseURI, "crm.lead.list.json");

        filterObj fil = new filterObj();
        List<string> a = new List<string>();
        a.Add("*");
        a.Add("UF_*");
        fil.select = a;

        Dictionary<string, string> order = new Dictionary<string, string>();
        order.Add("ID","asc");
        fil.order = order;

        string userJSON = JsonConvert.SerializeObject(fil);

        int arrVCount = 0;
        int Pages = 0;
        int FileNumber = 0;
        string path = @"D:\Google Drive\VS\intBitrix24\Lead\Lead";

        List<Lead> Leads = new List<Lead>();     
        do
        {

            //string search_items = @"order[ID]=asc&start="+ (Pages*50);
            string search_items = @"start=" + (Pages * 50);
            string Query = search_items;// + "params=" + userJSON;// + "&" + "sid=" + SesionId;
            string httpResponseResult = getResponseMessageByBitrix(newURI, Query, userJSON);
            var arrV = JToken.Parse(httpResponseResult);
Mant
  • 1
  • 1
0

There are a couple of ways to make your life easier, depending on what you would like to do in the end and what language you'd prefer to do it in.

First might be using one of the Bitrix provided/supported API helpers. They are CRest for php and BX24 JS library for Javascript. If you look through the examples listed in the documentation, which I admit leave a lot to be desired, you will see that they use one of these two libraries for the most part.

So, let's look at crm.deal.list which has the example

    <script type="text/javascript">
       BX24.callMethod(
        "crm.deal.list", 
        { 
            order: { "STAGE_ID": "ASC" },
            filter: { ">PROBABILITY": 50 },
            select: [ "ID", "TITLE", "STAGE_ID", "PROBABILITY", "OPPORTUNITY", "CURRENCY_ID" ]
        }, 
        function(result) 
        {
            if(result.error())
                console.error(result.error());
            else
            {
                console.dir(result.data());             
                if(result.more())
                    result.next();                      
            }
        }
    );  
    </script>

The example gives the clue that Bitrix expects a little more in the parameters than what you currently have. CRest works the same, generally, just formatted in a PHP array instead.

$result = CRest::call(
            'crm.deal.list',
            [
                "order" => [
                    "ID" => "DSC"
                ],
                "filter" => [
                    "STAGE_ID" => ["NEW"]
                ],
                "select" => [
                    "ID",
                    "TITLE",
                    "UF_*
                ]
            ]
        );

Second, if you don't want to use one of the libraries, that's no problem. Using a webhook is certainly supported. One of the easier ways to see if your webhook is formatted properly is to use the "Request builder" included in the developer resources section on Bitrix24. You can get to it by going to .bitrix24.com/devops/ and, for example, going to Import and Export, and then Export. Here is what it looks like.

The default example is for crm.contact.list, but you could change it to crm.deal.list if you prefer. Regardless, it gives an example with parameters. In this case it's

https://<yoursite>.bitrix24.com/rest/<userID>/<rest_key>/crm.contact.list.json?FILTER[>DATE_CREATE]=2019-01-01&SELECT[]=NAME&SELECT[]=LAST_NAME&SELECT[]=EMAIL

If you want to build the URL yourself, then notice that it uses SELECT[]= to essentially format in an equivalent way to SELECT["NAME", "LAST_NAME", "EMAIL"]. So to recreate the doc example, the parameters would be

crm.deal.list.json?ORDER[]=STAGE_ID:ASC&FILTER[>PROBABILITY]=50&SELECT[]=ID&SELECT[]=TITLE&SELECT[]=STAGE_ID&SELECT[]=PROBABILITY&SELECT[]=OPPORTUNITY&SELECT[]=CURRENCY_ID

Now, to your question using the info above, the way to get just the ID and TITLE would be crm.deal.list.json?SELECT[]=ID&SELECT[]=TITLE and the way to get userfields is the same, just add/substitute SELECT[]=UF_<UF number>. To get all user fields you can do SELECT[]=UF_* (which it looks like you attempted, maybe the \ actually caused some problems instead of, what I assume you were trying to do, escaping the _) and similarly to get all fields use SELECT[]=*&SELECT[]=UF_*

Nick R
  • 76
  • 7