Hey guys,
I came across the issue, that I can not trigger the sending of the double opt-in marketing email, when I create a customer via admin API with marketingOptInLevel=CONFIRMED_OPT_IN
Is there any way to achieve this? I mean, this is a very important step for any merchant in the EU.
While researching, I found this topic in the old forum:
1 Like
Bump @Liam-Shopify any idea?
Can you share the full mutation you’re using @Stefano (with demo data instead of any real customer data)? I believe as well as marketingOptInLevel: CONFIRMED_OPT_IN you’d also need to use marketingState: PENDING.
Thanks for your reply @Liam-Shopify
In my opinion, the following mutation should, additionally to creating customer, automatically send the “Customer marketing confirmation” notification from Shopify, because there is no other mutation to trigger it.
Here you can see my Mutation:
Mutation:
import type { AdminApiContext } from "@shopify/shopify-app-remix/server";
import type { CustomerInput } from "~/types/admin.types";
const query = `#graphql
mutation createCustomer($input: CustomerInput!) {
customerCreate(input: $input) {
customer {
id
}
userErrors {
field
message
}
}
}
`;
export async function createCustomer(
admin: AdminApiContext,
input: CustomerInput
) {
const response = await admin.graphql(query, {
variables: {
input,
},
});
const responseJson = await response.json();
return responseJson?.data?.customerCreate;
}
Input:
{
email: "test@test.com",
firstName: "Stefano",
lastName: "Test",
phone: undefined,
addresses: [
{
firstName: "Stefano",
lastName: "Test",
address1: undefined,
city: undefined,
company: undefined,
countryCode: "DE",
province: undefined,
zip: undefined,
phone: undefined,
},
],
emailMarketingConsent: {
marketingOptInLevel: "CONFIRMED_OPT_IN",
marketingState: "PENDING",
},
locale: "en",
tags: [
"Test",
],
}
From digging into this more, it does look like Shopify does not send the double opt-in email automatically via the createCustomer mutation, even if you set the state to PENDING.
It seems Shopify automatically sends the double opt-in email only when a customer signs up through the storefront and double opt-in is enabled in the store’s settings. If you require double opt-in, it looks like the only supported method is to have customers sign up through the storefront, which will trigger the double opt-in email when enabled.
Ok, thanks for digging into that, but how does the Shopify App “Shopify Forms” handle double opt-in for newsletter registration? As I can see, it does not even support double opt-in, so maybe Shopify can provide this function for Shopify Forms, and then we can also make use of it. Thanks!
Will connect with them - but as you’ve found the Forms app doesn’t support double opt-in natively.
Hi @Liam-Shopify,
Just wanted to check if there have been any updates since then.
Do you know how Shopify Forms eventually handles the double opt-in for newsletters, or if any new functionality was added?
Thanks!
Hey @Kenichi_Nakahara, there’s still no way to trigger the double opt-in email programmatically.
The double opt-in setting only works for default theme forms ({% form 'customer' %} or {% form 'create_customer' %}). While theme app extensions technically have access to the {% form %} tag, they don’t work with the customer-specific forms.
The current option remains as building a custom double opt-in flow:
- Create the customer with
marketingState: PENDING via customerCreate
- Send your own confirmation email with a verification link
- Use
customerEmailMarketingConsentUpdate to update them to SUBSCRIBED when they confirm
For context, the Customer Account API has customerEmailMarketingSubscribe, but it requires an existing customer account, so same limitation.
Does the above help clarify this @Kenichi_Nakahara?
Hi @KyleG-Shopify,
Yes, that clarifies things very well — thank you for confirming.
I understand now that the double opt-in can only be triggered through the default theme forms and not programmatically.
That said, I think it would be much clearer and more consistent for users if the double opt-in workflow could also be triggered via API in the future.
I’m really looking forward to seeing such an update implemented someday.
Appreciate the detailed explanation!
1 Like
Happy to help. I agree it would be useful and have submitted this as a feature request on your behalf.
1 Like