Answer the question
In order to leave comments, you need to log in
How to send data to Bitrix24?
Kind people, please tell me and direct me to the right path)
By clicking, I send data to Bitrix24 via webhooks.
On idea I should transfer obligatory parameters. But all such examples are in PHP, and here I am trying to make the inventor of the bicycle using JS.
Maybe I'm not passing the correct url or Parameters
let btn = document.querySelector('button');
btn.addEventListener('click', createLid());
let fields =
{
"TITLE": "ИП Титов",
"NAME": "Глеб",
"SECOND_NAME": "Егорович",
"LAST_NAME": "Титов",
"STATUS_ID": "NEW",
"OPENED": "Y",
"ASSIGNED_BY_ID": 1,
"CURRENCY_ID": "USD",
"OPPORTUNITY": 12500,
"PHONE": [ { "VALUE": "555888", "VALUE_TYPE": "WORK" } ]
};
let params = { REGISTER_SONET_EVENT: "Y" };
let REGISTER_SONET_EVENT = {
'LOGIN': "xxxxxxx", // обязательно, логин для доступа к crm
'PASSWORD':'xxxxxxxx', // обязательно, пароль для доступа к crm
'TITLE': 'test-plugin' // обязательно, название лида
}
let url = `http://crmtest.domen.ru/rest/967/key4g4g4g4g/profile/crm.lead.add(${fields}, ${params})`;
let url2 = "http://crmtest.domen.ru/rest/crm.lead.add.json?fields[TITLE]=Обратныйзвонок&fields[PHONE]='34345345'&fields[NAME]='dsfs'&auth=key4h4h4h";
function createLid() {
fetch(url, {
method: 'post'
})
.then(function (data) {
console.log('Request succeeded with JSON response', data);
})
.catch(function (error) {
console.log('Request failed', error);
});
};
body: (...)
bodyUsed: false
headers: Headers {}
ok: false
redirected: false
status: 404
statusText: "Not Found"
type: "cors"
Failed to load resource: the server responded with a status of 404 (Not Found)
Answer the question
In order to leave comments, you need to log in
let url = `http://crmtest.domen.ru/rest/967/key4g4g4g4g/profile/crm.lead.add(${fields}, ${params})`;
You can use the @2bad/bitrix JavaScript (TypeScript) client , which will greatly simplify the task:
import Bitrix from '@2bad/bitrix'
const bitrix = Bitrix('https://PORTAL.bitrix24.ua/rest/1/WEBHOOK_URL')
bitrix.leads.create({
TITLE: 'Test lead'
})
.then(console.log)
If anyone will be useful, I did so. Using webhooks to create a lead.
fetch(url, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
fields: data.fields
})
})
.then(function (response) {
loader.classList.add("hiden");
success.classList.remove("hiden");
return console.log('Request succeeded', response.json());
})
.catch(function (error) {
loader.classList.add("hiden");
fail.classList.remove("hiden");
console.log('Request failed', error);
});
};
let data = {
fields: {
TITLE: "",
NAME: "",
STATUS_ID: "20",
OPENED: "20",
LAST_NAME: "",
SOURCE_ID: "",
POST: "",
BIRTHDATE: "",
UF_CRM_KOMMENTARII: '',
UF_CRM_1545200238: '216', // тип лида
PHONE: [{
VALUE: "",
VALUE_TYPE: "WORK"
}],
EMAIL: [{
VALUE_TYPE: "WORK",
VALUE: "",
}],
WEB: [{
VALUE_TYPE: "WORK",
VALUE: "",
}]
},
params: {
"REGISTER_SONET_EVENT": "Y"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question