Hi there,
we would like to collect newsletter leads via Meta Ads. We use Zapier for this.
When a person fills out the lead ad form in Meta, a customer is created in Shopify.
We use Shopify’s double opt-in process. In other words, when someone fills out the native newsletter form on our webshop, the email marketing consent state is “pending” and Shopify automatically sends the double opt-in email.
The problem is, if a customer is created viaZapier, he receives the Email Marketing Consent state “not_subscribed” in Shopify and therefore does not receive a double opt-in email from Shopify.
Is it possible to use Shopify Flow to change the Email Marketing Consent state to “pending” so that Shopify automatically sends the double opt-in email?
Thanks in advance.
1 Like
I think you’d need to use an http action in flow with a call to this api endpoint and then update the email_marketing_consent.state field.
Hi Jordan,
thanks for your advice! 
Since I am quite new to the topic and have only received error messages so far, can you maybe help me with how to fill in the HTTP method, URL, Headers and Body fields?
I am not sure which method REST API or GraphQL API.
Thanks in Advance.
1 Like
Sorry I’m a bit short on time here. The shopify support team sometimes helps with those types of things though here in the forums.
Hi Davide_DeAng,
There are some docs available which discuss how to use the Send HTTP Request action in Flow to call the Shopify Admin GraphQL API.
Hope that helps you get unblocked!
Hi Dave,
thanks for sharing the help article.
I tried to adapt the query shown in the article, but I am still getting error messages.
This is the input I use:
HTTP method:
POST
URL:
https://admin.shopify.com/store/{{shop.name}}/api/2024-01/graphql.json
Headers:
Key: X-Shopify-Access-Token Value: API secret key of the app (has write_customers and read_customers access scope)
Key: Content-Type Value: application/json
Body:
{"query": "mutation { customerUpdate(input: {id: \"{{ customer.id }}\", emailMarketingConsentstate: \"pending\"}) { customer{ id } } }"}
I get this error message:
{“status”:401,“response_body”:“{"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}”,“verb”:“POST”,“url”:“https://core.sfe.shopifyinternal.com/admin/api/2024-01/graphql.json”,“request_body”:“{"query": "mutation { customerUpdate(input: {id: \"gid://shopify/Customer/7737757729103\", emailMarketingConsentstate: \"pending\"}) { customer{ id } } }"}”}
Is the API secret key needed as authentication or the Admin API access token?
Do you know why the flow is not working? It would be great if you could help me that action.
Regards,
Davide
Hi Dave,
I found this article (https://shopify.dev/docs/api/admin-graphql/2024-01/mutations/customerEmailMarketingConsentUpdate) and updated my body of the HTTP-request to the following one:
{
“query”: “mutation customerEmailMarketingConsentUpdate($input: CustomerEmailMarketingConsentUpdateInput!) { customerEmailMarketingConsentUpdate(input: $input) { customer { id } userErrors { field message } } }”,
“variables”: {
“input”: {
“customerId”: “{{ customer.id }}”,
“emailMarketingConsent”: {
“marketingState”: “pending”
}
}
}
}
The flow status now is “Succeeded” and under Actions taken it says “Send HTTP request”, however the status of the customer did not change and he did not receive the double-opt-in mail. Do you know what is wrong or why this is the case?
Hi @DaveMcV ,
any idea why this is not working as expected?
Best Regards,
Davide
Hi @Davide_DeAng ,
If the request is returning successful in Flow then that’s as much support as we can offer, but I can give you some more debugging advice.
Add a Log output step in the Workflow parallel to the Send HTTP request action and copy the body of your message into that. Then when you run the Workflow, it will log the output. You can use that with a HTTP request tool you have locally, like Postman, to simulate the request from Flow and tweak it until you get it working. Then you can backfill those changes into your workflow and try again.
Also worth noting you can use the Retry run button on any workflow run page to re-run the workflow with the same input parameters, but with your latest changes. Just make sure you apply changes first in the editor.
Hope that helps!
Hi @Davide_DeAng ,
Oh that very likely could be related if you’re seeing a successful post but no opt in notification. That would be outside the scope of what you’d be able to solve with Flow.