Skip to main content
Contributor I
April 16, 2025
Solved

Unable to bulk subscribe profile,

  • April 16, 2025
  • 4 replies
  • 148 views

When making a call to the profile-subscription-bulk-create-jobs

I get error “Duplicate email subscribe found” 

 

POST https://a.klaviyo.com/api/profile-subscription-bulk-create-jobs Accept: application/vnd.api+json Authorization:  Klaviyo-API-Key **** Revision: 2025-01-15 Content-Type: application/vnd.api+json

{   "data": {     "type": "profile-subscription-bulk-create-job",     "attributes": {       "custom_source": "NA",       "profiles": {         "data": [           {             "type": "profile",             "attributes": {               "email": "johndoe2025041605@example.com",               "subscriptions": {                 "email": {                   "marketing": {                     "consent": "SUBSCRIBED",                     "consented_at": "2025-04-16T12:03:46.8339052-07:00"                   }                 }               }             }           }         ]       },       "historical_import": true     },     "relationships": null   } }

 

I get the following error.

 

{   "errors": [     {       "id": "90df49e8-981d-43a2-9ad2-9029eaa509e6",       "status": 400,       "code": "invalid",       "title": "Invalid input.",       "detail": "Duplicate email subscribe found",       "source": {         "pointer": "/data/attributes/profiles/data/0/attributes/subscriptions/email/marketing/consented_at"       },       "links": {},       "meta": {}     }   ] }

    Best answer by whereisjad

    @SebastienAube I believe the problem is that for the relationships section of the JSON payload you specified null.

    You should instead replace with something like below:

      "relationships": {
    "list": {
    "data": {
    "type": "list",
    "id": "<List ID>"
    }
    }
    }

    below is article on how to find the list ID for list you wish to subscribe your profiles to:

    https://help.klaviyo.com/hc/en-us/articles/115005078647

    4 replies

    whereisjad
    Expert Problem Solver IV
    Expert Problem Solver IV
    April 18, 2025

    @SebastienAube I believe the problem is that for the relationships section of the JSON payload you specified null.

    You should instead replace with something like below:

      "relationships": {
    "list": {
    "data": {
    "type": "list",
    "id": "<List ID>"
    }
    }
    }

    below is article on how to find the list ID for list you wish to subscribe your profiles to:

    https://help.klaviyo.com/hc/en-us/articles/115005078647

    — Jad A | Klaviyo + Shopify + API Integrations Specialist • 7+ Years' Experience Helping with new setups, seamless integrations, and API connections—happy to connect. http://ja-technical-consulting.xyz/
    Contributor I
    April 22, 2025

    Thanks ​@whereisjad  I added the list element and get the same result unfortunately.

    whereisjad
    Expert Problem Solver IV
    Expert Problem Solver IV
    April 22, 2025

    @SebastienAube do you mind sharing the entire JSON payload again but redacting the IDs from it?  

    — Jad A | Klaviyo + Shopify + API Integrations Specialist • 7+ Years' Experience Helping with new setups, seamless integrations, and API connections—happy to connect. http://ja-technical-consulting.xyz/
    Contributor I
    May 6, 2025

    @SebastienAube do you mind sharing the entire JSON payload again but redacting the IDs from it?  

    I have a similar problem. I am using Symfonie and do the PHP api calls. 

    From what I understand - reading documentation - for a double opt in I can add a profile without subscription and then send an E-Mail manually where the user would click a special link from within the email which sends an api call to set status to subscribed. 

    is this action tied to a relation? I did that and it is working - I get a 202 response but the profile never updates.

     

    public function subscribeProfile(string $email): bool
    {
    $url = self::API_BASE . '/profile-subscription-bulk-create-jobs';

    $payload = [
    'data' => [
    'type' => 'profile-subscription-bulk-create-job',
    'attributes' => [
    'profiles' => [
    'data' => [
    [
    'type' => 'profile',
    'attributes' => [
    'subscriptions' => [
    'email' => [
    'marketing' => [
    'consent' => 'SUBSCRIBED',
    ]
    ]
    ],
    'email' => $email,
    ]
    ]
    ]
    ],
    'historical_import' => false
    ]
    ]
    ];

    try {
    $response = $this->httpClient->request('POST', $url, [
    'headers' => array_merge(
    $this->getHeaders(),
    ['Content-Type' => 'application/json']
    ),
    'json' => $payload,
    ]);

    $status = $response->getStatusCode();

    if (!in_array($status, [200, 202])) {
    $body = $response->getContent(false);
    throw new \RuntimeException("subscribeProfile failed: HTTP $status - $body");
    }

    return true;
    } catch (\Throwable $e) {
    throw new \RuntimeException('Exception during subscribeProfile: ' . $e->getMessage(), 0, $e);
    }
    }

    I create the profile in the first step of the DOI like so:

     

    public function createProfile(string $email): ?string
    {
    $response = $this->httpClient->request('POST', self::API_BASE . '/profiles/', [
    'headers' => array_merge($this->getHeaders(), ['Content-Type' => 'application/json']),
    'json' => [
    'data' => [
    'type' => 'profile',
    'attributes' => [
    'email' => $email,
    ],
    ],
    ],
    ]);

    $data = $response->toArray(false);

    if (!isset($data['data']['id'])) {
    throw new \RuntimeException('Failed to create profile: ' . json_encode($data));
    }

    return $data['data']['id'];
    }

    I am kind of at a lost as to where to find the information to spot my mistake...