N
Novu•8mo ago
okitsme_Parth

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

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
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
14 Replies
okitsme_Parth
okitsme_Parth•8mo ago
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='test-user@sd.com',
first_name='subscriber-1',
last_name='test-1'
),
SubscriberDto(
subscriber_id='test-subscriber-2',
email='test-user-2@sd.com',
first_name='subscriber-2',
last_name='test-2'
),
SubscriberDto(
subscriber_id='test-subscriber-3'
)
]

novu = SubscriberApi(url, api_key).bulk_create(subscribers)
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='test-user@sd.com',
first_name='subscriber-1',
last_name='test-1'
),
SubscriberDto(
subscriber_id='test-subscriber-2',
email='test-user-2@sd.com',
first_name='subscriber-2',
last_name='test-2'
),
SubscriberDto(
subscriber_id='test-subscriber-3'
)
]

novu = SubscriberApi(url, api_key).bulk_create(subscribers)
@sumitsaurabh927 if you are free, pls consider helping me here
sumitsaurabh927
sumitsaurabh927•8mo ago
@Support Can you help here?
E@zybright
E@zybright•8mo ago
@okitsme_Parth the variable url should be url = "https://api.novu.co/v1"
Pawan Jain
Pawan Jain•8mo ago
@okitsme_Parth Did you try with api directly because I see, it is working in nodejs
okitsme_Parth
okitsme_Parth•8mo ago
No that will not work as the method adds /v1/subscribers/bulk itself at the end of the url
Novu_Bot
Novu_Bot•8mo ago
@okitsme_Parth, you just advanced to level 3!
okitsme_Parth
okitsme_Parth•8mo ago
Not really, let me try and get back to you 🫡 @Pawan Jain it works I think SDK has some issues
Pawan Jain
Pawan Jain•8mo ago
Yes
okitsme_Parth
okitsme_Parth•8mo ago
@Pawan Jain 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': 'test-user@sd.com', 'firstName': 'subscriber-1', 'lastName': 'test-1', 'phone': None, 'avatar': None, 'locale': None, 'channels': None}, {'subscriberId': 'test-subscriber-2', 'email': 'test-user-2@sd.com', '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
Method: POST
URL: https://api.novu.co/v1/subscribers/bulk
JSON: [{'subscriberId': 'test-subscriber-1', 'email': 'test-user@sd.com', 'firstName': 'subscriber-1', 'lastName': 'test-1', 'phone': None, 'avatar': None, 'locale': None, 'channels': None}, {'subscriberId': 'test-subscriber-2', 'email': 'test-user-2@sd.com', '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
Pawan Jain
Pawan Jain•8mo ago
This is request or response?
okitsme_Parth
okitsme_Parth•8mo ago
Request
Pawan Jain
Pawan Jain•8mo ago
'locale': None is creating issue similarly 'email': None
okitsme_Parth
okitsme_Parth•8mo ago
If possible can you send me the request body in any other language, whenever you are free
Pawan Jain
Pawan Jain•8mo ago
Sure. give me some time
{"method":"post","url":"https://api.novu.co/v1/subscribers/bulk","body":{"subscribers":[{"subscriberId":"1234","firstName":"First Name 1","lastName":"Last Name 2","locale":"en-US"},{"firstName":"First Name 2","lastName":"Last Name 2","subscriberId":"1234566"}]},"params":{},"headers":{"Authorization":"API <API_KEY>","Content-Type":"application/json"}}
{"method":"post","url":"https://api.novu.co/v1/subscribers/bulk","body":{"subscribers":[{"subscriberId":"1234","firstName":"First Name 1","lastName":"Last Name 2","locale":"en-US"},{"firstName":"First Name 2","lastName":"Last Name 2","subscriberId":"1234566"}]},"params":{},"headers":{"Authorization":"API <API_KEY>","Content-Type":"application/json"}}