-
Notifications
You must be signed in to change notification settings - Fork 66
Create Contact
corsacca edited this page Feb 21, 2018
·
14 revisions
This page is a work in progress. The code is being made to follow this documentation
The function source code: Create contact function
create_contact( array $fields = [], $check_permissions = true )
- fields (Required): an array of fields like name, phone number corresponding to the new contact. More details below.
- check_permissions: check if the signed in user has the permission to perform this action. By default this should be true, unless this is called by an automated process.
- url:
https://example.com/wp-json/dt/v1/contact/create - type: POST
- data: A JSON string of fields object. Required same format as defined below
- contentType: "application/json; charset=UTF-8",
- dataType: "json",
- in $contact_id, the id of the newly created contact
- WP_ERROR, in the case something went wrong.
Fields have different types. Each type will need it's own syntax. The list of fields will changed based on your install. For a list of available fields have a look at: Contact Post Type page
Field examples:
- title
fields = [
"title" => "John Doe"
]
Field examples:
- overall_status
- seeker_path
The options for each of these can be found in the Contact Post Type page The key is used to set save the field instead of the value.
fields = [
"overall_status" => "established"
]
- phone_numbers
- emails
- addresses
The are separate from the text fields because there can be more than one of each. A contact can have several phone numbers. Once created each phone number will have it's own id.
$fields = [
"phone_numbers" => [
["value" => "43 42 45 43"],
["value" => "94 39 29 39"]
]
]
- baptism_date
$fields = [
"baptism_date" => "2018-12-31" //format Y-m-d
]
- assigned_to //int, a user id
- subassigned //int, a contact id
$fields = [
"assigned_to" => 4 //the id of the user
]
- quick_button_no_answer
- quick_button_phone_off
- quick_button_phone_off
- quick_button_contact_established
- quick_button_meeting_scheduled
- quick_button_meeting_complete
- quick_button_no_show
$fields = [
"quick_button_no_answer" => 3
]
- locations
- groups
- people_groups
- baptized_by
- baptized
- coaching
- coached_by
- subassigned
$fields = [
"locations" => [ "1", "9" ]
]
$fields = [
"title" => "Bob",
"overall_status" => "established",
"phone" => [
["value" => "43 42 45 43"],
["value" => "94 39 29 39"]
],
"locations" => [ "1", "9" ],
"quick_button_no_answer" => 3,
"baptism_date" => "2017-11-34",
]
Disciple_Tools_Contacts::create_contact( $fields, true )
jQuery.ajax({
type: "POST",
data: JSON.stringify({
title:"bob",
phone_numbers:[{value:"12324"}]
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
url: wpApiSettings.root + `dt/v1/contact/create`,
beforeSend: function(xhr) {
xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);
}