mailjet / mailjet-apiv3-dotnet

[API v3] Official Mailjet API v3 .NET wrapper
https://dev.mailjet.com
MIT License
75 stars 31 forks source link

Can't add contact with custom property #119

Closed jaaywags closed 1 year ago

jaaywags commented 1 year ago

Hello, I am trying to add a contact to a contact list with a custom property but it is not working. The email is added just fine but not the custom property. How can I go about this? I can manually add or update contacts to this contact list and specify the property through the website, but not through this package.

Here is what I have tried (the commented out sections were past attempts.

var request = new MailjetRequest
        {
            Resource = ContactslistManagemanycontacts.Resource,
            ResourceId = ResourceId.Numeric(commandModel.ContactListId)
        }
            .Property(ContactslistManagemanycontacts.Action, "addnoforce")
            // .Property(Contactdata.Fields, new JArray
            // {
            //     new JObject
            //     {
            //         {"Name", "mycustomproperty"},
            //         {"Value", true}
            //     },
            // })
            // .Property(Contactdata.Data, new JArray {
            //     new JObject
            //     {
            //         {
            //             "mycustomproperty", true
            //         },
            //     },
            // })
            .Property(ContactslistManagemanycontacts.Contacts, new JArray
            {
                new JObject
                {
                    {Contact.Email, commandModel.Email},
                    {Contact.IsExcludedFromCampaigns, "false"},
                    {"mycustomproperty", false},
                },
            });

        var response = await _MailJetClient.PostAsync(request);
jaaywags commented 1 year ago

I knew I would figure it out as soon as I posted the problem. Here is my solution for any future people.

var request = new MailjetRequest
{
    Resource = ContactslistManagemanycontacts.Resource,
    ResourceId = ResourceId.Numeric(commandModel.ContactListId)
}
    .Property(ContactslistManagemanycontacts.Action, "addnoforce")
    .Property(ContactslistManagemanycontacts.Contacts, new JArray
    {
        new JObject
        {
            {Contact.Email, commandModel.Email},
            {Contact.IsExcludedFromCampaigns, "false"},
            {
                "Properties",
                new JObject
                {
                    {"mycustomproperty", "true"},
                }
            },
        },
    });