cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving newsletter subscriber field from magento 2 API

Retrieving newsletter subscriber field from magento 2 API

Hello everyone, I have the code below... but it's not giving me the newsletter subscription status. Please assist.

 

$api   = "rest/V1/customers/search";
$json = '
{
"search_criteria": {
"filter_groups": [
{
"filters": [
],
"filters": [
{
"field": "created_at",
"value": "' . $start . '",
"condition_type": "gt"
}
]
},
{
"filters": [
],
"filters": [
{
"field": "created_at",
"value": "' . $end . '",
"condition_type": "lt"
}
]
}
]
}
}';


$ch = curl_init(urldecode("https://www.example.com/index.php/" . $api . "?" . http_build_query(json_decode($json)))) 

I can see it on my dashboard, but the returned results are not showing this field!

https://imgur.com/a/3cIRBZQ

 

 

1 REPLY 1

Re: Retrieving newsletter subscriber field from magento 2 API

Hi van_trinh,

 

You can try with this api end point:

EndPoint  = "/V1/customers/{customer_id}"

Method = "PUT"

Json  = 
{
  "customer": {
    "id": {customer_id},
     "email": "{customer_email}",
    "firstname": "{customer_firstname}",
    "lastname": "{customer_lastname}",
    "store_id": {store_id},
    "website_id": {website_id},
    "extension_attributes": {
     "is_subscribed": true
    }
  }
}

 

Hope it helps!

if issue solved,Click Kudos & Accept as Solution
Thanks