Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

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

Closed
FilipQL opened this issue Aug 30, 2017 · 1 comment

Comments

@FilipQL
Copy link

FilipQL commented Aug 30, 2017

I am using php-sdk 3.0.0-alpha (because I need Guzzle 6 for the other packages/dependencies, as stated here: #113). 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 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.

@FilipQL
Copy link
Author

FilipQL commented Aug 30, 2017

OK, I found how: $contact->results[0]->id (and $contact = $this->cc->contactService->getContacts($this->token, ["email" => Input::get('email')]);. This (->results[0]->id) is not very intuitive, and I did not find this in the documentation/examples.

@FilipQL FilipQL closed this as completed Aug 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant