REST API
The REST Api is mainly used for the SolarPlus Wordpress plugin and can be use with other applications.
Authentication
The authentication requires token that can be generated through http://dev.solarplus.co/user/api to be passed through Authentication header of the requests.
Generating access token
To generate go to http://dev.solarplus.co/user/api , Click on the “Generate new Secreto Key” button and after that click “Generate new Token” button.
Base Api Url
http://v3.solarplus.api
Appending Authentication Token
Every request to the api must have token key attached to the header Authorization. Place your generated token key like so:
{code:title=Append authentication token|linenumbers=true|language=php|firstline=0001|collapse=true}
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC93d3cuc29sYXJwbHVzLmNvbVwvYXBpXC8iLCJpYXQiOjE0OTg0OTEwMTgsImV4cCI6MTUzMDAzMTAxOCwidHRsIjoiMy4xNTRlKzciLCJ1aWQiOiIxMTI5In0.hfg_GnZSzsFbCesTMGr2CqJAZr8V7lCN6diL95COx60
{code}
Creating Contact
API Path: /api/contact
HTTP Verb: POST or PUT
Form Parameters:
Name
Key
Values
Required
Comments
Contact
First Name
first_name
String
Yes
Last name of the contact
Last Name
last_name
String
Yes
Last name of the contact
Email Address
email
String
Yes
Email address of the customer
Primary Phone
primary_phone
String
No
Primary phone number of the customer
Full Address
full_address
String
Yes
Full address of the customer
Business Name
business_name
String
No
Business name of the contact
Full Address
full_address
String
Yes
Contact and Site full address.
Notes
notes
String
No
Notes for this customer
Business Name as Client
business_as_client
Boolean
No
Whether to set the Site name the same as the Business Name.
Source
source
String
No
Contact source it can be one of the following: Other, TV, Radio, Press, Google, Tradeshow, Friends, Website, Word of Mouth
Status
status
String
No
Status can be one of the following: Lead, Active, Closed
Categories
categories[category_name]
Array of Strings
No
Business Category of the Contact.
Custom Fields
Custom Fields
custom_fields[field_name]
Array of Strings
Yes or No
Contact custom fields that the business has. The requirement depends on the creation of the field.
Sample PHP Code Using cURL:
{code:title=Creating Contact|linenumbers=true|language=php|firstline=0001|collapse=true}
<?php
$url = 'http://dev.solarplus.co/api/contact';
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC93d3cuc29sYXJwbHVzLmNvbVwvYXBpXC8iLCJpYXQiOjE0OTg0OTEwMTgsImV4cCI6MTUzMDAzMTAxOCwidHRsIjoiMy4xNTRlKzciLCJ1aWQiOiIxMTI5In0.hfg_GnZSzsFbCesTMGr2CqJAZr8V7lCN6diL95COx60';
$auth_header = 'Authorization Bearer ' . $token;
$form = array(
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john.doe@domain.com',
'primary_phone' => '123-123-123',
'full_address' => '222 Exhibition St, Melbourne VIC 3000, Australia',
'business_name' => 'John Solar Power',
'notes' => 'Nullam id dolor id nibh ultricies vehicula ut id elit.'
'categories' => array(
'Category 1' => 'Some value',
),
'custom_fields' => array(
'custom_text_12' => 'Some value',
),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', $auth_header));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($form));
$response = curl_exec($ch);
$json = json_decode($response);
curl_close($ch);
echo '<pre>';
print_r($json);
echo '</pre>';
{code}
JSON Response:
{code:title=JSON Response|linenumbers=true|language=php|firstline=0001|collapse=true}
{
"success": "true",
"message": "Contact successfully created.",
"data": {
"id": "19670",
"business_name": null,
"business_as_client": 0,
"source": "Other",
"status": "Lead",
"first_name": "John",
"last_name": "Doe",
"email": "john.doe@domain.com",
"primary_phone": "123-123-123",
"secondary_phone": null,
"full_address": "222 Exhibition St, Melbourne VIC 3000, Australia",
"categories": null,
"notes": "Nullam id dolor id nibh ultricies vehicula ut id elit."
}
}
{code}
Response Table: