php-sdk 3.0.0-alpha: How to get $contactId (how to unsubscribe contact from specific list by email)?

Highlighted
Occasional Contributor

php-sdk 3.0.0-alpha: How to get $contactId (how to unsubscribe contact from specific list by email)?

I am using php-sdk 3.0.0-alpha (because I need Guzzle 6 for the other packages/dependencies). There is method unsubscribeContact which requires $contactId (int - Unique contact id):

    /**
     * Opt out a contact
     * @param string $accessToken - Constant Contact OAuth2 access token
     * @param int $contactId - Unique contact id
     * @return boolean
     * @throws CtctException
     */
    public function unsubscribeContact($accessToken, $contactId) {
        $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.contact'), $contactId);

        try {
            $response = parent::sendRequestWithoutBody($accessToken, 'DELETE', $baseUrl);
        } catch (TransferException $e) {
            throw parent::convertException($e);
        }

        return ($response->getStatusCode() == 204) ? true : false;
    }

But how to get that Id? For example, if I want to unsubscribe example@example.com from a specific list - how can I get the id of that contact? There is no method to get contact by email address. Also, the unsubscribeContact method doesn't receive any param to determine the list.

 

Thanks,

Filip

3 REPLIES 3
Highlighted
Occasional Contributor

Re: php-sdk 3.0.0-alpha: How to get $contactId (how to unsubscribe contact from specific list by ema

Ok, I found how: $contact->results[0]->id . This is not very intuitive, and I did not find this in the documentation / examples.

Highlighted
Moderator

Re: php-sdk 3.0.0-alpha: How to get $contactId (how to unsubscribe contact from specific list by ema

Hello @VinceS647,

 

The unsubscribeContact is going to unsubscribe a contact from the account it is not to remove a contact from a single list. If you wish to remove a contact from a single list you need to update the contact and just remove that list ID.

 

Also if at any time you are looking for a single contact ID you would use the getContact.


Regards,
Jimmy D.
Tier II API Support Engineer
Highlighted
Occasional Contributor

Re: php-sdk 3.0.0-alpha: How to get $contactId (how to unsubscribe contact from specific list by ema

Hello,

 

It's not Vince but Filip :)

 


Also if at any time you are looking for a single contact ID you would use the getContact.


getContact method requires contact ID so it cannot be used to get a single contact ID:

 

    /**
     * Get contact details for a specific contact
     * @param string $accessToken - Constant Contact OAuth2 access token
     * @param int $contactId - Unique contact id
     * @return Contact
     * @throws CtctException
     */
    public function getContact($accessToken, $contactId) {

To get contact ID:

 

$contact = $this->cc->contactService->getContacts($this->token, ["email" => Input::get('email')]);
$contact->results[0]->id
Developer Portal

View API documentation, code samples, get your API key.

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured