Trigger double opt-in email when creating customer via admin API

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:

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.