Contact PHP API

FluentCRM has the following PHP api functions so you can easily add/modify contacts.

<?php

    $contactApi = FluentCrmApi('contacts');
    /*
    * Find a contact by Email or Contact ID
    * You can find a contact by email or contact id (ContactId is not the user ID).
    * @return: false or Contact Model Object
    */
    $contact = $contactApi->getContact($emailOrContactId);

    /*
    * Find a contact by contact id or email address
    * You can find a contact by contact id
    */
    $contact = $contactApi->getContact($contactId);

    // or find by email address
    $contact = $contactApi->getContact($emailAddress);


    // Find contact by user id
    $contact = $contactApi->getContactByUserRef($userId);

    /*
    * get current logged in user's contact profile
    *
    */
    $contact = $contactApi->getCurrentContact();

Accessing Contact Properties #

<php
    /*
    * Accessing contact properties
    */

    $contact->first_name;
    $contact->last_name;
    $contact->email;
    $tags = $contact->tags()->get();   // Tags array that are assigned to the contact 
    $lists = $contact->lists()->get(); // Lists array that are assigned to the contact

Updating Contact Properties #

<?php

    /*
    * Updating contact properties
    */
    $contact->first_name = 'New First Name';
    $contact->last_name = 'Last Name';
    $contact->save();

    /*
    * Adding tags to a contact
    */
    $tagIds = [1,2,3];
    $contact->attachTags($tagIds);

    /*
    * Adding Lists to a contact
    */
    $listIds = [2,3];
    $contact->attachLists($listIds);

    /*
    * Removing tags from a contact
    */
    $tagIds = [1,2,3];
    $contact->detachTags($tagIds);

    /*
    * Adding Lists to a contact
    */
    $listIds = [2,3];
    $contact->detachLists($listIds);

Creating or Updating a new contact #

<?php

   $contactApi = FluentCrmApi('contacts');

    /*
    * Update/Insert a contact
    * You can create or update a contact in a single call
    */

    $data = [
        'first_name' => 'Jhon',
        'last_name' => 'Doe',
        'email' => '[email protected]', // requied
        'status' => 'pending',
        'tags' => [1,2,3], // tag ids as an array
        'lists' => [4] // list ids as an array
    ];

    $contact = $contactApi->createOrUpdate($data);

    // send a double opt-in email if the status is pending
    if($contact->status == 'pending') {
        $contact->sendDoubleOptinEmail();
    }

Filtering Contacts #

    $contactApi = FluentCrmApi('contacts');

    // get Subscribed Contacts
    $subscribedContacts = $contactApi->getInstance()->where('status', 'subscribed')->get(); // you can also use paginate() instead of get();

    // Get both pending and upsubscribed contacts
    $contacts = $contactApi->getInstance()->whereIn('status', ['unsubscribed', 'pending'])->get();

    // Get contacts by tag ids
    $tagIds = [1,2];
    $tagOneTwoContacts = $contactApi->getInstance()->filterByTags($tagIds)->get();

    // Get contacts by list ids
    $listIds = [1,2];
    $ListOneTwoContacts = $contactApi->getInstance()->filterByLists($listIds)->get();

    // search contacts
    $searchResult = $contactApi->getInstance()->searchBy('search_string')->get();

Latest comments (9)

How to search data using custom field. I want to create a custom field “Contact Owner” and pull data. When the Contact Owner logs into the system. They should get the list of contacts under them. Is it possible using this or any other API?

For other DEV’s this might help:

You can access the custom field by using the following code:

$contact->custom_fields()[‘cf_slug’] = ‘Your Value’;
Where “cf_slug” is the slug for your custom Field and “Your value” is the value you want to put.

For other dev’s this might be of service:

You can access the custom field by using the following code:

$contact->custom_fields()[‘cf_slug’] = ‘Your Value’;
Where “cf_slug” is the slug for your cust

Hello. There is any bug that Fluent CRM is not working on Android (both mobile and desktop version) to send emails (WordPress 8.0 version) because it just doesn’t let me save a subject both to create a new campaign or a template.