Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter <any param> must be array. #4

Open
SeregPie opened this issue Jan 29, 2018 · 6 comments
Open

Parameter <any param> must be array. #4

SeregPie opened this issue Jan 29, 2018 · 6 comments

Comments

@SeregPie
Copy link

SeregPie commented Jan 29, 2018

Hello.
https://training.bitrix24.com/rest_help/crm/contacts/crm_contact_list.php
Any example I'm trying to use, I get an error with Parameter 'param' must be array.

bitrix24.callMethod("crm.contact.list", {
  order: { "DATE_CREATE": "ASC" },
  filter: { "TYPE_ID": "CLIENT" },
  select: [ "ID", "NAME", "LAST_NAME", "TYPE_ID", "SOURCE_ID" ]
});

Is there any difference between this library and the library used in the documentation examples?

@SeregPie SeregPie changed the title Parameter filter must be array. Parameter <any param> must be array. Jan 29, 2018
@SeregPie
Copy link
Author

The problem is querystring. It just does not support nested objects.

@setyongr
Copy link
Owner

setyongr commented Feb 1, 2018

Yup, thanks for pointing out, using native querystring we must use notation like

{
   "SELECT[0]" : "ID",
    "SELECT[1]" : "TITLE",
    "SELECT[2]" : "COMPANY_TYPE",                    
}

Using other implementation of querystring also will solve #3

@Snailsloth
Copy link

Snailsloth commented Jul 2, 2018

Hello. Could you tell me how to use querystring? Even a small example could help me. I'm trying to create a lead with b24

"crm.lead.add", 
{
   fields:{
      "TITLE":"leadname"
    }
},

and have same error . Thanks!

I mean.. if I try to add a lead through the address bar, the following construction works:

https://company.bitrix24.ru/rest/user/key/crm.lead.add?fields=[TITLE]=IAMLEAD

but if i want to make same thing from node server , I can not construct a query in the method crm.lead.add correctly, i always got

'{"error":"","error_description":"Parameter \\u0027fields\\u0027 must be array."}' }

UPDATE:
Ok, i found some bug and issue in qs repo about troubles with object stringifying. I had the same problem: from

?${qs.stringify(param)

in node_modules/b24/dist/index.js . Output was "fields=" and nothing more.

After manual "qs" package installation and replacement of
const qs = require("querystring"); with const qs = require("qs"); , i finally can create a lead 🐌

Hope it can help someone

@andreasteffanoni
Copy link

Same problem for me. I followed Snailsloth suggestion, and the solution was really simple:
After adding qs to the project (npm add qs --save), params and url are simple to build (I used webhooks):

    var params = {
        fields: {
            "TITLE": "Aboca",
            "COMPANY_TYPE": "CUSTOMER",
            "OPENED": "Y",
            "ASSIGNED_BY_ID": "1",
            "PHONE": [{"VALUE": "0039 55 555888", "VALUE_TYPE": "WORK"}]
        }
    };

    const qs = require("qs");

    var url = 'https://yourHost/rest/YourUser/YourHookCode/crm.company.add?' + qs.stringify(params);`

Then you just make a http get. The example is for adding a new company, but I suppose you can use any bitrix24 API.

@Draecal
Copy link

Draecal commented Nov 25, 2020

I'm trying to do the following:

let params = { filter: { 'ID': '2' } } const tasks = bitrix24.callMethod('tasks.task.list', qs.stringify(params)).then(allTasks => { console.log(allTasks)

and getting all tasks not just the task 2

Solved The following code gives the intended data:

const tasks = bitrix24.callMethod('tasks.task.list', {filter:{
                        'REAL_STATUS': [2, 3]
                    }}).then(allTasks => {
                console.log(allTasks)
                    res.status(200).render('home/index', {allUsers: allUsers, allTasks: allTasks});
            }).catch(err => { console.log(err)});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants
@SeregPie @Draecal @setyongr @andreasteffanoni @Snailsloth and others