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

Adding user to contact list is failing #38

Closed
gbesler opened this issue Jul 23, 2020 · 3 comments
Closed

Adding user to contact list is failing #38

gbesler opened this issue Jul 23, 2020 · 3 comments

Comments

@gbesler
Copy link

gbesler commented Jul 23, 2020

I can successfully initialize Mailchimp in debug mode and I am trying to create a contact from my app. But I receive an error:

Error: The operation couldn’t be completed. (appname.APIError error 4.)

What I do is:

 var contact: Contact = Contact(emailAddress: "some@email.com")
        
        let emailPermission = Contact.MarketingPermission(marketingPermissionId: "emailPermissinon", enabled: true)
        let mailPermission = Contact.MarketingPermission(marketingPermissionId: "mailPermission", enabled: true)
        let adPermission = Contact.MarketingPermission(marketingPermissionId: "adPermission", enabled: true)

        contact.marketingPermissions = [emailPermission, mailPermission, adPermission]
        MailchimpSDK.createOrUpdate(contact: contact) { result in
            switch result {
            case .success:
                print("Successfully added or updated contact")
            case .failure(let error):
                print("Error: \(error.localizedDescription)")
            }
        }

What am I doing wrong?

@michael-patzer
Copy link
Collaborator

Hi @gbesler. Thanks for opening the issue and providing a code sample.

Case 4 in the APIError enum is apiError(response: APIErrorResponse). Could you print out the status, type, and detail of the APIErrorResponse?

        MailchimpSDK.createOrUpdate(contact: contact) { result in
            switch result {
            case .success:
                print("Successfully added or updated contact")
            case .failure(let error):
                print("Error: \(error.localizedDescription)")
                switch error {
                case .apiError(response: APIErrorResponse)
                    print("Status: \(response.status), Type: \(response.type), Detail: \(response.detail)")
                }
            }
        }

@gbesler
Copy link
Author

gbesler commented Jul 23, 2020

Hi @michael-patzer
It seems somehow the SDK did not throw an error for "nil" SDK key. It was not entering catch phrase with a nil SDK key.
I guess this should be fixed. Thanks for your help.

@gbesler gbesler closed this as completed Jul 23, 2020
@michael-patzer
Copy link
Collaborator

@gbesler Thank you. We'll take a look at this. You may also contribute a fix if you'd like. When you open a PR, the cla-bot will give instructions on how to sign our Contributor License Agreement.

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

2 participants