P
P
poisons2020-07-12 12:28:45
Python
poisons, 2020-07-12 12:28:45

How to send notifications in the cloud version of bitrix24?

Good afternoon, I ran into a rather strange situation, notifications do not want to work for me at close range, although other parts of the API work quite well, as an example, tasks are successfully created for me, requests to the client card work, etc.
Given:
1. Cloud bitrix24.
2. bitrix24 - rest 1.1.1
_ _

from bitrix24 import *
import datetime

sendString = ['Attention! Bla-bla-bla']
bx24 = Bitrix24('https://bla.bitrix24.com/rest/4/bla/profile/')

bx24.callMethod('tasks.task.add', fields={'TITLE': 'Test',
                                          'DESCRIPTION' : sendString[0],
                                          'DEADLINE' : datetime.datetime.now() + datetime.timedelta(days=7),
                                          'AUDITORS': {'1':'10'},
                                          'RESPONSIBLE_ID' : '4',
                                          'CREATED_BY': '1',
                                          'DESCRIPTION_IN_BBCODE' : 'Yes'
                                           })

At the output, a task is created, all the necessary fields are pushed up and everything is fine.
Well, the designs work as expected.
bx24.callMethod('crm.contact.list',
                                     filter={'UF_CRM_1571409252888': date},
                                     select=['ID', 'NAME', 'LAST_NAME', 'EMAIL', 'PHONE']
                                     )


But a strange thing happens with notifications.
We read the doc at the first link, they suggest doing this:
BX24.callMethod('im.notify', {to: user.id, message: 'Привет, '+user.name+'!'});

Okay, let's do:
bx24.callMethod('im.notify', fields={'TO': '4', 'MESSAGE': 'Bla-bla-bla'})

and catch
in callMethod
    raise BitrixError(r)
bitrix24.exceptions.BitrixError: User ID can't be empty

Okay, let's go to the second link, it is described a little differently and it is suggested to pull im.message.add, we do
bx24.callMethod('im.message.add', fields={'DIALOG_ID': '4', 'MESSAGE': 'Bla-bla-bla'})

And now we catch
bitrix24.exceptions.BitrixError: Message can't be empty


What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Roman, 2020-07-12
@Ramapriya

im.notify parameters are written in lowercase

bx24.callMethod('im.notify', fields={'to': '4', 'message': 'Bla-bla-bla'})

L
LAV59, 2020-07-15
@LAV59

Literally ran into the exact same situation today. CRM api works, but when notifying and working with chat, the error "ID cannot be empty" is returned. Tried it this way and that, it didn't work.

V
Vladimir Zotov, 2021-02-01
@ZV8

Faced exactly the same problem.
As a result, in my case, the error was due to inattention:
In the API rights setting, there were "CRM" and "Chat and notifications".
But for this functionality, "Messaging Service" is required. . After adding it everything works.
Check... maybe you have the same problem.
60183c3dd5cc2095735613.jpeg

A
Andrewsek, 2021-08-12
@Andrewsek

I managed.
bx24.callMethod('im.message.add', {'DIALOG_ID': '4', 'MESSAGE': 'Bla-bla-bla'})
doesn't need to wrap parameters in fields like methods in CRM.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question