Simple API PHP post request for adding new contact (and delete)

Hello dear team,
I need an elementary example PHP code for adding and deleting contacts from my lists. But I can’t find anything besides using some Blue SDK anywhere on your website.
I need something trivial like:

$contactData = array(‹ first_name › => … ‹ last_name › => ‹ email › => … );

    $apiKey = 'MY-API-JEY';
    $apiUrl = 'https://api.brevo.com/v3/lists/2/contacts';
    $ch = curl_init($apiUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($contactData));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Authorization: Bearer ' . $apiKey,
    ));

    $response = curl_exec($ch);
   curl_close($ch);

Whatever I try, I always get a « Key not found » error.

(And need some API example for the delete).

Thank you so much!

Ok. I handled the adding. But can’t figure out the delete.
I would like to use the user email as an identifier.

Hi @pma , thanks for posting on this community!

For creation there is this doc: https://developers.brevo.com/reference/createcontact

and for the delete action there is this one: Delete a contact

You can choose the relevant language on the right.

Thank you very much!!!

1 « J'aime »