question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m writing here more for help than declaring this an issue as I’m pretty sure this is more related to my lack of experience with async methods.

I am moving my organization to MC, and trying to create a wrapper class in my business logic to pass other business objects into it, and then utilize your methods. I have been able to run GetAll() methods and return data from MailChimp, but have not been able to create lists or members.

Here’s a sample of my code:

public class myChimp
{
       private MailChimp.Net.MailChimpManager account { get; set; }

        public AIAChimp() 
        {
            account = new MailChimp.Net.MailChimpManager("defaultAPIKey");
        }
        public AIAChimp(string apiKey)
        {
            account = new MailChimp.Net.MailChimpManager(apiKey);
        }

        public async System.Threading.Tasks.Task<IEnumerable<MailChimp.Net.Models.List>> GetLists()
        {
            var listCollection = await account.Lists.GetAllAsync().ConfigureAwait(false);


            return listCollection;
        }

        public async System.Threading.Tasks.Task<MailChimp.Net.Models.List> CreateList(string listName)
        {
            var list = new MailChimp.Net.Models.List { Name = listName, 
                    PermissionReminder = "default", 
                    CampaignDefaults = { FromEmail = "test@test.com", 
                    FromName = "myCompany" }, Contact = { Company = "myCompany" } };

            return await account.Lists.AddOrUpdateAsync(list).ConfigureAwait(false);

        }
}

So with that, when I run these commands, the first works, and these second one throws an error at t2.Wait(), site a null value:

myChimp c = new myChimp();
            System.Threading.Tasks.Task<IEnumerable<MailChimp.Net.Models.List>> t = c.GetLists();
            t.Wait();
            foreach (MailChimp.Net.Models.List list in t.Result)
            {
                id = list.Id;
                Console.WriteLine(list.Name + " - " + list.DateCreated + " - " + list.Id + " - " + list.Stats.MemberCount);
            }

            System.Threading.Tasks.Task<MailChimp.Net.Models.List> t2 = c.CreateList("All US Staff");
            t2.Wait();
           Console.WriteLine(t1.Result.Id);

Right now, I am using a Free Account. I can also see errors in the API Status of my account for /PUT stating “The requested resource could not be found.”

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brandonseydelcommented, Jun 23, 2016
var c = new myChimp();
var t = await c.GetLists();

foreach(var list in t){
  id = list.Id;
  Console.WriteLine(list.Name + " - " + list.DateCreated + " - " + list.Id + " - " + list.Stats.MemberCount);
}

var t2 = await c.CreateList("All US Staff");
Console.WriteLine(t1.Id);

You should make your logic layer let the user know that your methods are async by suffixing your methods with async… ex.

var c = new myChimp();
var t = await c.GetListsAsync();

Also configureawait(false) will prevent deadlocks when users are using your logic layer so should be added until you want to dispatch back onto the main thread (UI layer)

0reactions
AJGarrettcommented, Jun 29, 2016

I found my issue. I wasn’t passing all the required fields for creating a list.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CreateList - Cleo
Cleo Help Center home page · Support · Support Home Core Support Services Severity ... CreateList. Returns a new empty list of the...
Read more >
CreateList
A user-defined comment that describes the purpose or action of the component. Action Component Reference · Example.
Read more >
createList method | Qlik Sense for developers Help
Defines a list of field values and registers a callback to receive the data. Version history. Version history. Version state, Details. Introduced ...
Read more >
CreateList - Lyris
CreateList. Creates a new list and returns the newly created listID. Arguments. ListType - The type of list to be created, from ListTypeEnum....
Read more >
serverWidget.createList(options) - SuiteScript
serverWidget.createList(options) ... Note: The content in this help topic pertains to SuiteScript 2.0. Method Description. Creates a standalone list.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found