Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a new subscriber returns 400 Bad Request #87

Open
joaonlforte opened this issue Dec 16, 2024 · 3 comments
Open

Creating a new subscriber returns 400 Bad Request #87

joaonlforte opened this issue Dec 16, 2024 · 3 comments

Comments

@joaonlforte
Copy link

I'm using dotnet sdk v0.3.3
and when calling POST /v1/subscribers the api returns a 400

c# code snippet

        var additionalData = request.Data?.Select(s => new AdditionalData
            {
                Key = s.Key,
                Value = s.Value
            }).ToList();

            var dto = new SubscriberCreateData
            {
                SubscriberId = subscriberId,
                Email = request.Email,
                FirstName = request.FirstName,
                LastName = request.LastName,
                Phone = request.Phone,
                Data = additionalData
            };

            await _client.Subscriber.Create(dto);

documentation example seems to be using the same contract format

this used to work properly in the past, but we've start getting this error (can't precise exactly when)

response

{
  "error": "Bad Request",
  "statusCode": 400,
  "timestamp": "2024-12-16T16:14:23.331Z",
  "path": "/v1/subscribers",
  "message": [
    "data must be an object"
  ],
  "ctx": {
    "error": "Bad Request",
    "statusCode": 400
  }
}
@toddb
Copy link
Collaborator

toddb commented Dec 17, 2024

To be honest, the library is woefully maintained and the payload looks like it has changed (400 is a client error). This isn't going help other than the library needs an update.

The starting point is to work out which API version you are running against. I would then run the tests against that version.

With that, there's the starting point for a patch.

I'm sorry not to be more helpful at this point.

@jainpawan21
Copy link
Member

Hi @joaonlforte

Thanks for sharing the issue.

We are working on generating SDK automatically using an open API file. All SDKs including dotnet SDK will be updated in mid Q1. Could you please use our API directly to create a subscriber

@joaonlforte
Copy link
Author

Hey 👋

thanks both @toddb @jainpawan21 for the fast reply ;)

@jainpawan21 I can sure! Do you have a more concrete date on making the revamped SDKs available? Should i keep an eye on the newsletter?

Nevertheless @jainpawan21 I think the NET documentation you pointed to is misleading still here

using Novu.DTO;
using Novu.Models;
using Novu;

var novuConfiguration = new NovuClientConfiguration
{
    /**
    * Defaults to https://api.novu.co/v1
    */
    Url = "https://novu-api.my-domain.com/v1",
    ApiKey = "12345",
};

var novu = new NovuClient(novuConfiguration);

var additionalData = new List<AdditionalDataDto> // DEPRECATED
{
  new AdditionalDataDto
  {
    Key = "External ID",
    Value = "1122334455"
  },
  new AdditionalDataDto
  {
    Key = "SMS_PREFERENCE",
    Value = "EMERGENT_ONLY"
  }
};

var newSubscriberDto = new CreateSubscriberDto
{
  SubscriberId = "unique_subscriber_id",
  FirstName = "John",
  LastName = "Doe",
  Avatar = "https://unslpash.com/random",
  Email = "[email protected]",
  Locale = "en-US",
  Phone = "+11112223333",
  Data = additionalData
};

var subscriber = await novu.Subscriber.CreateSubscriber(newSubscriberDto)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants