N
Novu•14mo 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_ParthOP•14mo 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',
first_name='subscriber-1',
last_name='test-1'
),
SubscriberDto(
subscriber_id='test-subscriber-2',
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',
first_name='subscriber-1',
last_name='test-1'
),
SubscriberDto(
subscriber_id='test-subscriber-2',
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•14mo ago
@Support Can you help here?
E@zybright
E@zybright•14mo ago
@okitsme_Parth the variable url should be url = "https://api.novu.co/v1"
Pawan Jain
Pawan Jain•14mo ago
@okitsme_Parth Did you try with api directly because I see, it is working in nodejs
okitsme_Parth
okitsme_ParthOP•14mo ago
No that will not work as the method adds /v1/subscribers/bulk itself at the end of the url
Novu_Bot
Novu_Bot•14mo ago
@okitsme_Parth, you just advanced to level 3!
okitsme_Parth
okitsme_ParthOP•14mo 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•14mo ago
Yes
okitsme_Parth
okitsme_ParthOP•14mo 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': '[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
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
Pawan Jain
Pawan Jain•14mo ago
This is request or response?
okitsme_Parth
okitsme_ParthOP•14mo ago
Request
Pawan Jain
Pawan Jain•14mo ago
'locale': None is creating issue similarly 'email': None
okitsme_Parth
okitsme_ParthOP•14mo ago
If possible can you send me the request body in any other language, whenever you are free
Pawan Jain
Pawan Jain•14mo 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"}}
Want results from more Discord servers?
Add your server