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

Import contacts with Feed Me #395

Closed
martinhellwagner opened this issue May 30, 2023 · 29 comments
Closed

Import contacts with Feed Me #395

martinhellwagner opened this issue May 30, 2023 · 29 comments
Assignees
Labels
enhancement New feature or request

Comments

@martinhellwagner
Copy link

I was wondering if it's possible to run a Feed Me feed against an API GET endpoint that imports contacts into a Craft Campaign mailing list. Currently, the only way seems to import these contacts as users, and then run an import for these users into a Craft Campaign mailing list – which seems to be quite a detour since I don't need these Mailing List Contacts as users.

@martinhellwagner martinhellwagner added the question Further information is requested label May 30, 2023
@bencroker
Copy link
Collaborator

The plugin currently allows importing contacts via CSV file or user sync only, but I’ll look into adding compatibility with Feed Me.

@bencroker bencroker added enhancement New feature or request and removed question Further information is requested labels May 30, 2023
@bencroker bencroker self-assigned this May 30, 2023
@martinhellwagner
Copy link
Author

@bencroker

Thanks a lot! Is there a timeframe for this enhancement? We'd need the import by the middle of June. If that's too soon for this feature, I'll look for a workaround via a CSV file. Speaking of: is there a CLI command we could use for triggering an import with a Cron Job or so?

@bencroker
Copy link
Collaborator

bencroker commented May 30, 2023

Thanks a lot! Is there a timeframe for this enhancement?

No, but I’ll aim to get it in by next week.

@martinhellwagner
Copy link
Author

@bencroker

Wow, thanks – much appreciated! 🙏🏼

@bencroker
Copy link
Collaborator

bencroker commented May 31, 2023

Added in eb5b1aa. You can help test this by running composer require putyourlightson/craft-campaign:dev-develop as 2.8.0.

@martinhellwagner
Copy link
Author

@bencroker

That was fast! 😍 Works like a charm – thanks a lot!

@bencroker
Copy link
Collaborator

Released in version 2.8.0.

@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 1, 2023

@bencroker

I successfully implemented the request that fetches the data from an API. The data is sent to the Feed Me feed like this:

        Event::on(DataTypes::class, DataTypes::EVENT_BEFORE_FETCH_FEED, function(FeedDataEvent $event) {
            ...
            $event->response = [
                'success' => true,
                'data' => $this->fetchData($tokenType, $accessToken),
            ];
        });

However, even though valid JSON is returned from the fetchData method, the following error appears on our Stage (even though it is working properly on my local machine):

Screenshot 2023-06-01 at 15 49 08

Could that be a problem with the Campaign plugin, or should I talk to the Craft / Feed Me team about that?

@bencroker
Copy link
Collaborator

I’m not sure but can investigate. Did you repeat the test to see if the error occurs multiple times?

@martinhellwagner
Copy link
Author

I repeated the test multiple times, and it always fails with the same error on Stage. I never get the error on my local system though. I've also tried the cURL request that fetches the data on my local environment and on Stage – it works on both systems. I'm guessing it might be a problem with feeding the response's JSON data into the $event->response array.

@bencroker
Copy link
Collaborator

Hmm, can you resave the feed setup details again? I’m really not sure where the issue might be.

@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 1, 2023

I've also tried to resave the feed multiple times – unfortunately, this doesn't change anything. I've also already e-mailed the Craft support with this problem – maybe they know more about this. 🤔

@martinhellwagner
Copy link
Author

@bencroker

The Craft support suggested that Section isn't defined in the feed settings – and sent me this screenshot:

oli_D8JmCKQT@2x

Is that something that might help with a solution?

@bencroker
Copy link
Collaborator

Um, section?? Did you select a mailing list to import contacts into?

@bencroker bencroker reopened this Jun 1, 2023
@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 1, 2023

Yes, all the necessary dropdowns are set:

Screenshot 2023-06-01 at 22 16 31

(The Feed URL is not set to a URL because the actual call to the API is done with Guzzle in my code. However, the error doesn't change if I insert the correct endpoint URL.)

@bencroker
Copy link
Collaborator

In that case, the Craft support team’s suggestion is not particularly helpful.

@martinhellwagner
Copy link
Author

What I'm surprised is that it works locally, but not on Stage. I have the same code deployed, and the same DB for both environments. Both environments run PHP 8.1.

@olivierbon
Copy link

olivierbon commented Jun 8, 2023

Right, I got to the bottom of this.

This only happens when 'runQueueAutomatically' => false, and the queue is offset to a separate worker.

The reason is this.

The plugin will only register new elements on CP request.

I'll leave the awesome @bencroker do his thing now :)

@bencroker
Copy link
Collaborator

Great find, @olivierbon, and thank you so much for reporting it!
Fixed in 5b55002 and released in version 2.8.1.

@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 8, 2023

Great news! Really appreciate your work on this, @olivierbon & @bencroker! 🙏🏼

Will try it out first thing next week.

@martinhellwagner
Copy link
Author

Just tested it – looks good. Thanks again! 🚀

@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 22, 2023

@bencroker

We found one issue where I'm not exactly sure if this has to do with the implementation of the feature. I have two feeds that each fetch a set of contacts from an API endpoint. One contact is found in both of these API responses.

My understanding would be that this contact would be created and subscribed to the first mailing list when running the first feed, and then subscribed to the second mailing list when running the second feed (I have both feeds set to "Add & Update"). The contact indeed gets created, but it only ever gets subscribed to the mailing list whose corresponding feed I'm running first. Am I doing something wrong, or is this the way it's currently implemented?

Thanks for your answer! 🙏🏼

@bencroker
Copy link
Collaborator

That process should work as you expect it to. Does the issue only happen with automated API fetches, or can you reproduce it manually? If you can, then please outline the steps involved so I can test locally.

@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 22, 2023

If I extract the JSON data in question from the feed and add it manually, then the same thing happens. This is the data I'm using – the one contact that should go into both mailing lists (the businessMail is the unique identifier):

{
	"content": [{
		"id": 5357,
		"createdDate": 1685450968784,
		"modifiedDate": 1685524744466,
		"firstName": "Maria",
		"lastName": "Musterfrau",
		"fullName": "Musterfrau Maria",
		"reverseFullName": "Maria Musterfrau",
		"mail": null,
		"phone": null,
		"mobile": null,
		"address": null,
		"localDescription": null,
		"businessMail": "mamu@text.com",
		"businessPhone": null,
		"businessMobile": null
	}]
}

These are the feeds:

Screenshot 2023-06-22 at 21 35 29 Screenshot 2023-06-22 at 21 35 41

@bencroker
Copy link
Collaborator

The compareContent config setting determines whether to check against existing element content before updating. If the content of the user has not changed then saving is skipped, so setting it to false (the default is true) should have the desired effect.
https://docs.craftcms.com/feed-me/v4/get-started/configuration.html

@martinhellwagner
Copy link
Author

martinhellwagner commented Jun 23, 2023

@bencroker

Yep, that was it. Thanks for pointing me in the right direction! 🚀

@maximilian-schwarz
Copy link

I have the same error message as @martinhellwagner

This only happens when 'runQueueAutomatically' => false, and the queue is offset to a separate worker.

I think you need this event to register new elements for Feed me:
https://github.com/craftcms/feed-me/blob/c30fb38b4ab334cd1081727750c65cb42d900a4d/src/services/Elements.php#L32

Craft Version: 4.5.5
Feed me: 5.2.0
Campaign: 2.8.6

@bencroker
Copy link
Collaborator

bencroker commented Oct 27, 2023

This issue has already been resolved, @maximilian-schwarz, and the event to register elements in Feed Me is already being used.

Event::on(FeedMeElements::class, FeedMeElements::EVENT_REGISTER_FEED_ME_ELEMENTS,

If this is still an issue for you then please update to the latest version of the plugin and create a new issue with further details and I’ll be happy to look into it

@maximilian-schwarz
Copy link

@bencroker thanks for the fast reply. I tested it with the current version and the issue still exist.

I have created a new issue with a working solution ;)

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

No branches or pull requests

4 participants