#Facing 400 Client Error: Bad Request for url: https://api.novu.co/v1/subscribers/bulk

1 messages · Page 1 of 1 (latest)

naive parcel
#

I am trying to use bulk_create method, but facing this error:

Traceback (most recent call last):
  File "/workspace/blank/tt.py", line 59, in <module>
    novu = SubscriberApi(url, api_key).bulk_create(subscribers)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/novu/api/subscriber.py", line 81, in bulk_create
    self.handle_request(
  File "/workspace/.pyenv_mirror/user/current/lib/python3.12/site-packages/novu/api/base.py", line 155, in handle_request
    res.raise_for_status()
  File "/home/gitpod/.pyenv/versions/3.12.0/lib/python3.12/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.novu.co/v1/subscribers/bulk
#

Code i used:

from novu.dto.subscriber import SubscriberDto
from novu.api.subscriber import SubscriberApi

url = "https://api.novu.co"
api_key = "its_secrettttt"

subscribers = [
    SubscriberDto(
        subscriber_id='test-subscriber-1',
        email='[email protected]',
        first_name='subscriber-1',
        last_name='test-1'
    ),
    SubscriberDto(
        subscriber_id='test-subscriber-2',
        email='[email protected]',
        first_name='subscriber-2',
        last_name='test-2'
    ),
    SubscriberDto(
        subscriber_id='test-subscriber-3'
    )
]

novu = SubscriberApi(url, api_key).bulk_create(subscribers)
naive parcel
#

@lavish grove if you are free, pls consider helping me here

lavish grove
untold marsh
#

@naive parcel the variable url should be url = "https://api.novu.co/v1"

tawdry pollen
#

@naive parcel
Did you try with api directly

#

because I see, it is working in nodejs

naive parcel
near templeBOT
#

@naive parcel, you just advanced to level 3!

naive parcel
#

@tawdry pollen it works

#

I think SDK has some issues

tawdry pollen
#

Yes

naive parcel
#

@tawdry pollen i did some digging and got this output is this sort of correct?

Method: POST
URL: https://api.novu.co/v1/subscribers/bulk
JSON: [{'subscriberId': 'test-subscriber-1', 'email': '[email protected]', 'firstName': 'subscriber-1', 'lastName': 'test-1', 'phone': None, 'avatar': None, 'locale': None, 'channels': None}, {'subscriberId': 'test-subscriber-2', 'email': '[email protected]', 'firstName': 'subscriber-2', 'lastName': 'test-2', 'phone': None, 'avatar': None, 'locale': None, 'channels': None}, {'subscriberId': 'test-subscriber-3', 'email': None, 'firstName': None, 'lastName': None, 'phone': None, 'avatar': None, 'locale': None, 'channels': None}]
Payload: None
Headers: None
tawdry pollen
#

This is request or response?

naive parcel
tawdry pollen
#

'locale': None is creating issue

#

similarly 'email': None

naive parcel
#

If possible can you send me the request body in any other language, whenever you are free

tawdry pollen
#

Sure. give me some time