This is regarding MailJet API for .NET - https://dev.mailjet.com/guides/?csharp#prepare-a-campaign
I get below error when I try to create a Campaign,
Root = {{ "ErrorInfo": "", "ErrorMessage": "Invalid json input: expected ",", but found """ at stream position 133 ...ctsList":"|ContactLis...", "StatusCode": 400 }}
Below is code the,
var client = new MailjetClient(MjApikeyPublic, MjApikeyPrivate){
Version = ApiVersion.V3
};
MailjetRequest request = new MailjetRequest{
Resource = Campaigndraft.Resource,
}.Property(Campaigndraft.Locale, "en_US")
.Property(Campaigndraft.Sender, "Mailjet Dv1")
.Property(Campaigndraft.SenderEmail, "buddhika_jet@outlook.com")
.Property(Campaigndraft.Subject, "Greetings from Mailjet")
.Property(Campaigndraft.ContactsList, "10152")
.Property(Campaigndraft.Title, "Friday newsletter");
response = await client.PostAsync(request);
I'm having doubts in the Campaigndraft.ContactsList value that I passed. Considering the official mailjet documentation the parameter should be (Ref - https://dev.mailjet.com/guides/?csharp#prepare-a-campaign),
.Property(Campaigndraft.ContactsListID, "$ID_CONTACTSLIST")
But I cannot find Campaigndraft.ContactsListID
in the mailjet API version 3 or version 3.1.
Any help will be much appreciated. Thanks in advance.
I found a solution to this problem with a help of my friend. Hope this will be helpful to anyone who is developing on top of mailjet API. So, yes, even though the official documentation (https://dev.mailjet.com/guides/?csharp#prepare-a-campaign) directs us to use 'ContactsListID' property of Campaigndraft class,
.Property(Campaigndraft.ContactsListID, "$ID_CONTACTSLIST")
it is actually not available in he Campaigndraft for some reason. So, the workaround is to use,
.Property("ContactsListID", contactListId)
string literal indicating "ContactsListID" value. This is because, Campaigndraft class in mailjet is just a API parameter name mapper and all the properties available in the class indicates the variety of parameters could be used for making API calls.
public static class Campaigndraft
{
public const string Sender = "Sender";
public const string Status = "Status";
public const string Subject = "Subject";
public const string Template = "Template";
//...
}
So, string literals can be used instead of all above parameters and any parameter that official mailjet package is missing. Hope this helps and thanks.