Issue in customer search REST API

tinyemail
Shopify Partner
8 1 2

Hello Community,

 

I found a very very weird behavior using  GET /admin/api/2022-10/customers/search.json? API calls

 

I have a few customers imported through the CSV file into my store all have accepts_marketing=yes,

When I create an API call passing accepts_marketing:0 or email_marketing_state:not_subscribed,

In both cases, I get few customers with accepts_marketing:true,
(please see below my Postman API calls)

tinyemail_0-1671568070247.pngtinyemail_1-1671568104720.png

 

Shouldn't I receive this customer because he has accepts_marketing: true?

 

And the interesting fact is if I go directly into the store and update this customer first put accepts_email_marketing:false and after accepts_email_marketing:true, then I don't receive this customer in these
requests.

 

Has somebody have this kind of situation am I am doing something wrong or the Shopify API is buggy? I would try to figure out it by myself but there's no documentation about this, which makes me disappointed in Shopify  :(.

 

 

Please let me know if you got this kind of scenario.

 

Thank you in advance.

 

Best regards,

tinyEmail.

 

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1436 235 489

Hi @tinyemail 👋

 


As of API version 2022-04, the `accepts_marketing` property was deprecated in favour of the `email_marketing_consent` property. I'd recommend using something like the below request instead:

 

curl -L -X POST 'https://STORE_NAME.myshopify.com/admin/api/2022-10/customers.json' \
-H 'X-Shopify-Access-Token: ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '{
    "customer": {
        "first_name": "test",
        "last_name": "customer",
        "email": "test.customer@myshopify.com",
        "verified_email": true,
        "email_marketing_consent": {
            "state": "subscribed",
            "opt_in_level": "confirmed_opt_in",
            "consent_updated_at": "2022-12-22T11:22:06-04:00"
        }
    }
}'

 

Hope that helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

tinyemail
Shopify Partner
8 1 2

Hello @ShopifyDevSup ,

thank you for your response and explanation. But as I mentioned before I want to apply a search filter to retrieve either Subscriber or NotSubscribed customers, for this in the deprecated version I use accepts_marketing: true/false but in the new version email_marketing_state:subscribed/not_subscribed. In both cases, the result is the same for not_subscribed I received customer with email_marketing_consent.state:subscribed.

 

Please advise how I should apply the filter to retrieve only subscribed/not_subscribed customers.

I need to count them for the system statistics.

 

Thank you in advance!!

 

Best regards,

TinyEmail.

 

 

PoojaBaghel14
Shopify Partner
1 0 2

I am also facing the same issue. could anyone please help 🙂