REST API V4 / Contacts
The contacts API allows you to fetch, add, edit, and delete contacts.
Contact Properties
Attribute | Type | Description |
ID |
integer | The system ID of the contact |
data |
object | The core properties of the contact containing information like name and email |
meta |
object | Custom fields and metadata properties of a contact record in key: value format |
user |
object|false | If the contact is associated with a WordPress user the user object will be provided, if there is no user record the attribute will be false |
files |
object[] | An array of file objects |
notes |
object[] | An array of note objects |
Example contact object
Create a contact
Create a new contact with this route.
POST /wp-json/gh/v4/contacts
Sample Request
Sample Response
Create a contact via the API using wp_remote_post()
Retrieve a contact
Fetch a contact with this route.
GET /wp-json/gh/v4/contacts/<ID>
Sample Response
Update a contact
Update a contact with this route.
PATCH /wp-json/gh/v4/contacts/<ID>
Sample request
Sample response
Delete a contact
Delete a contact with this route.
DELETE /wp-json/gh/v4/contacts/<ID>
Sample response
{ "status": "success" }
Sample Code
<?php add_filter( 'delete_contact', 'my_custom_function', 10, 2 ); /** * Your custom function to run * * @param $success bool * @param $contact \Groundhogg\Contact */ function my_custom_function( $success, $contact ){ // Return out if the action previously failed or the contact does not exist if ( ! $success || ! \Groundhogg\is_a_contact( $contact ) ){ return $success; } // delete the contact $contact->delete(); return WP_Error( 'deleted', 'contact deleted' ); } ?>
List contacts
Retrieve several contacts with this route
GET /wp-json/gh/v4/contacts
Sample request
Sample response
Additional Examples:
Create new tags
{ "data": { "email": "saixaero82@gmail.com", "first_name": "Sai", "last_name": "Behera" }, "tags": [ "my new tag" ] } To create multiple tags, separate them with a comma [ "my new tag", "my new tag 2, "my new tag 3"]
Add contact with existing tags
{ "data": { "email": "saixaero82@gmail.com", "first_name": "Sai", "last_name": "Behera" }, "tags": [ 1, 2, 3 ] } For multiple tags, you can use either an array of IDs or tag names [ 1, 2, 3 ] or [ 'tag 1', 'tag 2', 'tag 3' ]
Update checkbox meta fields
The internal name is the name given to the custom field.
{ "data": { "email": "john@example.com" }, "meta" : { "Internal Name": [ "Option A", "Option B", "Option C" ] } }