'accepts_marketing' is set to false when an order is placed through the REST API

Solved
MortenDitlevsen
New Member
2 0 0

Hi all,

I was directed here by the developer support chat.

I have an issue, that every time I place an order (through the Order REST API) and include a customer id on the order, then the attribute 'accepts_marketing' on the customer is always being set to 'false'.

Here's a short demonstration:

First I PUT the following to a specific customer: (https://xxxx.myshopify.com/admin/api/2021-04/customers/5210041319513.json)

 

{
    "customer": {
        "accepts_marketing": true
    }
}

 

 

In the reply I can see that accept_marketing is indeed being set as expected:

 

{
    "customer": {
        "accepts_marketing": true,
        "email": "xxx@xxx.xxx",
        "first_name": null,
        "last_name": null,
        "phone": null,
        "id": 5210041319513,
        "created_at": "2021-06-23T10:09:00+02:00",
        "updated_at": "2021-06-23T10:54:40+02:00",
        "orders_count": 1,
        "state": "disabled",
        "total_spent": "10.00",
        "last_order_id": 3815381237849,
        "note": null,
        "verified_email": true,
        "multipass_identifier": null,
        "tax_exempt": false,
        "tags": "",
        "last_order_name": "#1088",
        "currency": "DKK",
        "addresses": [],
        "accepts_marketing_updated_at": "2021-06-23T10:52:14+02:00",
        "marketing_opt_in_level": "single_opt_in",
        "tax_exemptions": [],
        "admin_graphql_api_id": "gid://shopify/Customer/5210041319513"
    }
}

 

 

Then I place an order for the same customer:

 

{
    "order": {
        "customer": { "id": 5210041319513 },
        "taxes_included": true,
        "financial_status": "paid",
        "line_items": [ {
            "price": 10,
            "quantity": 1,
            "name": "Test",
            "title": "Test"
        }]
    }
}

 

In the response from the order placement I can see that 'accepts_marketing' is now 'false'.

{
    "order": {
        "id": 3815383236697,
        "admin_graphql_api_id": "gid://shopify/Order/3815383236697",
        "app_id": 2808337,
        "browser_ip": null,
        "buyer_accepts_marketing": false,
        "cancel_reason": null,
        "cancelled_at": null,
        "cart_token": null,
        "checkout_id": null,
        "checkout_token": null,
        "closed_at": null,
        "confirmed": true,
        "contact_email": "xxx@xxx.xxx",
        "created_at": "2021-06-23T10:55:08+02:00",
        "currency": "DKK",
        "current_subtotal_price": "10.00",
        "current_subtotal_price_set": {
            "shop_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            }
        },
        "current_total_discounts": "0.00",
        "current_total_discounts_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            }
        },
        "current_total_duties_set": null,
        "current_total_price": "10.00",
        "current_total_price_set": {
            "shop_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            }
        },
        "current_total_tax": "0.00",
        "current_total_tax_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            }
        },
        "customer_locale": null,
        "device_id": null,
        "discount_codes": [],
        "email": "xxx@xxx.xxx",
        "financial_status": "paid",
        "fulfillment_status": null,
        "gateway": "",
        "landing_site": null,
        "landing_site_ref": null,
        "location_id": null,
        "name": "#1089",
        "note": null,
        "note_attributes": [],
        "number": 89,
        "order_number": 1089,
        "order_status_url": "https://ka-chingelingdev.myshopify.com/7274233907/orders/1406f68d9d05d988435ddecb4b6ecbde/authenticate?key=5bef75690990229e526edcbb14316f45",
        "original_total_duties_set": null,
        "payment_gateway_names": [],
        "phone": null,
        "presentment_currency": "DKK",
        "processed_at": "2021-06-23T10:55:08+02:00",
        "processing_method": "",
        "reference": null,
        "referring_site": null,
        "source_identifier": null,
        "source_name": "2808337",
        "source_url": null,
        "subtotal_price": "10.00",
        "subtotal_price_set": {
            "shop_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            }
        },
        "tags": "",
        "tax_lines": [],
        "taxes_included": true,
        "test": false,
        "token": "1406f68d9d05d988435ddecb4b6ecbde",
        "total_discounts": "0.00",
        "total_discounts_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            }
        },
        "total_line_items_price": "10.00",
        "total_line_items_price_set": {
            "shop_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            }
        },
        "total_outstanding": "10.00",
        "total_price": "10.00",
        "total_price_set": {
            "shop_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "10.00",
                "currency_code": "DKK"
            }
        },
        "total_price_usd": "1.60",
        "total_shipping_price_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            }
        },
        "total_tax": "0.00",
        "total_tax_set": {
            "shop_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            },
            "presentment_money": {
                "amount": "0.00",
                "currency_code": "DKK"
            }
        },
        "total_tip_received": "0.00",
        "total_weight": 0,
        "updated_at": "2021-06-23T10:55:08+02:00",
        "user_id": null,
        "customer": {
            "id": 5210041319513,
            "email": "xxx@xxx.xxx",
            "accepts_marketing": false,
            "created_at": "2021-06-23T10:09:00+02:00",
            "updated_at": "2021-06-23T10:55:09+02:00",
            "first_name": null,
            "last_name": null,
            "orders_count": 2,
            "state": "disabled",
            "total_spent": "20.00",
            "last_order_id": 3815383236697,
            "note": null,
            "verified_email": true,
            "multipass_identifier": null,
            "tax_exempt": false,
            "phone": null,
            "tags": "",
            "last_order_name": "#1089",
            "currency": "DKK",
            "accepts_marketing_updated_at": "2021-06-23T10:55:09+02:00",
            "marketing_opt_in_level": null,
            "tax_exemptions": [],
            "admin_graphql_api_id": "gid://shopify/Customer/5210041319513"
        },
        "discount_applications": [],
        "fulfillments": [],
        "line_items": [
            {
                "id": 9941977956441,
                "admin_graphql_api_id": "gid://shopify/LineItem/9941977956441",
                "fulfillable_quantity": 1,
                "fulfillment_service": "manual",
                "fulfillment_status": null,
                "gift_card": false,
                "grams": 0,
                "name": "Test",
                "price": "10.00",
                "price_set": {
                    "shop_money": {
                        "amount": "10.00",
                        "currency_code": "DKK"
                    },
                    "presentment_money": {
                        "amount": "10.00",
                        "currency_code": "DKK"
                    }
                },
                "product_exists": false,
                "product_id": null,
                "properties": [],
                "quantity": 1,
                "requires_shipping": true,
                "sku": null,
                "taxable": true,
                "title": "Test",
                "total_discount": "0.00",
                "total_discount_set": {
                    "shop_money": {
                        "amount": "0.00",
                        "currency_code": "DKK"
                    },
                    "presentment_money": {
                        "amount": "0.00",
                        "currency_code": "DKK"
                    }
                },
                "variant_id": null,
                "variant_inventory_management": null,
                "variant_title": null,
                "vendor": null,
                "tax_lines": [],
                "duties": [],
                "discount_allocations": []
            }
        ],
        "refunds": [],
        "shipping_lines": []
    }
}

A workaround is to include the 'buyer_accepts_marketing', but that means that I have to read out the customer entity before placing the order.

So to me this appears to be a bug.

Sincerely,

/morten

0 Likes
GrahamS
Shopify Staff
Shopify Staff
83 16 16

This is an accepted solution.

Hello @MortenDitlevsen ,

This would be an expected behaviour - certain fields (like "Accepts Marketing" or "Notify Customer") have default values that will be utilized if the field is omitted in the call. "Accepts Marketing" specifically will always default to "false" and update the customer profile unless it is cited as "true" in any call that includes that customer, regardless of whatever value that customer profile previously held.

Graham S | API Support @ Shopify
- Was my reply helpful? Click Like to let me 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

MortenDitlevsen
New Member
2 0 0

Hi @GrahamS ,

Thank you very much for the reply.

It was unexpected for me that using REST to place an Order actually ended up modifying a Customer entity.

I believe that this API design makes it a bit hard for the developer in general to know how big parts of periferal entities need to be included in the order placement in order for them not to fall back to defaults.

You mention 'certain fields' - are there other parts of the customer entity than the ones you mention that I should fetch from the customer first and include in the Order placement so as not to have them fall back to defaults?

Is there a place in the documentation where I could have already found this information on my own? If so, then I apologize for the interruption.

Sincerely,

/morten

0 Likes