title | language_tabs | toc_footers | includes | search | |||||
---|---|---|---|---|---|---|---|---|---|
API Reference |
|
|
|
true |
Welcome to Anarock! You can use API for pushing leads from your system to our database.
Below is a documentation about how to use the API for publishing leads to Anarock databse.
Code for creating hash using time_stamp:
<?php
// the shared secret key here
$key = 'KEY';
$current_time = time();
$message = (string)$current_time;
// to lowercase hexits
$hash = hash_hmac('sha256', $message, $key);
// NodeJS
var cryto = require('crypto');
var key = 'KEY'; // the shared secret key here
var time_stamp = Math.round((new Date()).getTime() / 1000);
var message = time_stamp.toString();
var hash = crypto.createHmac('sha256', key).update(message);
// to lowercase hexits
return hash.digest('hex');
Make sure to replace
KEY
with your API key.
Anarock uses SHA256 HMAC authentication method. The hash is created using current timestamp and your key as parameters.
You can request key by getting in touch with Anarock team.
Anarock expects the two keys hash
and current_time
to be included in all API requests to server.
These will be provided by your point of contact in ANAROCK team.
You must replaceKEY
with your personal API key.
You must test first with staging KEY
and then only put in production KEY
.
<?php
$api_url = 'STAGING OR PRODUCTION URL'; // as mentioned on left under HTTP Request Heading
$key = 'KEY';
$current_time = time();
$message = (string)$current_time;
// to lowercase hexits
$hash = hash_hmac('sha256', $message, $key);
// you can use libraries like https://github.com/brick/phonenumber to format numbers before sending
$number = PhoneNumber::parse('+447123456789'); // phone number of the lead with +
$country_code = $number->getRegionCode(); // GB
$phone = $number->getNationalNumber(); // 7123456789
$campaign_id = "UniqueString"; // String to Attribute the lead to specific project. contact ANAROCK team for this.
$postFields = "";
$postFields .= "&field=".$value; // refer to query parameters section on left section
$postFields .= "¤t_time=".$current_time;
$postFields .= "&phone=".$phone; // Phone number without country code
$postFields .= "&country_code=".$country_code; // Standard ISO3166-1 alpha-2 code for a country.
$postFields .= "&hash=".$hash; // its mandatory to create hash using same timestamp as sent in current_time parameter
$postFields .= "&campaign_id=".$campaign_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
$postFields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
// print_r($server_output);
?>
const crypto = require('crypto');
const PhoneNumber = require( 'awesome-phonenumber' );
const axios = require('axios'); // using axios to make post request, you can use any other method/library you are comfortable with
const timeStamp = Math.round((new Date()).getTime() / 1000);
const message = timeStamp.toString()
const hash = crypto.createHmac('sha256', key).update(message).digest('hex')
const number = new PhoneNumber(number.toString()); // pass the number with + to the PhoneNumber Library
const phone = number.getNumber('significant');
const country_code = number.getRegionCode();
const campaign_id = 'UniqueString';// String to Attribute the lead to specific project. contact ANAROCK team for this.
return axios({
url: 'STAGING OR PRODUCTION URL', // as mentioned on left under HTTP Request Heading
method: 'POST',
data: {
phone: phone,
country_code: country_code,
current_time: timeStamp,
hash: hash,
campaign_id: campaign_id,
... other fields as given in the query parameters section on left section
}
})
The above command returns JSON structured like this:
{
"status":"OK",
"message":"success",
"response":
{
"lead_id": 17863
}
}
This endpoint is used to posts a lead to ANAROCK database.
staging
POST https://lead-webhook.staging.anarock.com/api/v0/CHANNEL_NAME/sync-lead
``
production
POST https://lead.anarock.com/api/v0/CHANNEL_NAME/sync-lead
Staging KEY
in Staging API
and Production KEY
inProduction API
.
This will be provided by your point of contact from ANAROCK team
Parameter | Type | Mandatory | Description |
---|---|---|---|
name | String | - | Example "Rahul Kumar" |
phone | String | True | phone number without country code. Example: "9988998899" |
country_code | String | True | Standard ISO3166-1 alpha-2 code for a country. Link: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 You can also use libraries like, example: "IN" for India Defaults to "IN" |
String | - | Exmaple "[email protected]" | |
purpose | String | True | "buy" This should be hardcoded |
listing_id | String | - | Id of the product/listing/project/property for which lead is generated. Example: "111" |
listing_name | String | - | name of the project/property for which lead is generated. Example: "Runwal Green" |
current_time | Integer | True | current epoch time in second(notmilisecond) Link: https://www.epochconverter.com/clock |
hash | String | True | Generated in the section above Hash should be created using the same time stamp as sent in the parameter current_time |
city | String | - | Example "Mumbai" |
locality | String | - | Example "Bandra West" |
min_budget | Integer | - | exmaple 10000000 |
max_budget | Integer | - | exmaple 50000000 |
contact_date | Integer | - | epoch time(in second) at which lead has contacted |
remarks | String | - | additional comment about lead |
homeloan_required | Boolean | - | whether the lead is interested in home loan or not |
is_otp_verified | Boolean | - | whether the lead is OTP verified or not |
is_call_verified | Boolean | - | whether the lead is Call verified or not |
credit_value | Stirng | - | credit/ cost of the lead. Exmaple: "250" |
is_broker | Boolean | - | whether the lead submitted is of a broker or not |
apartment_types | String | - | comma separated bhk types where bhk type can be 1bhk/2bhk/3bhk/3+bhk/1rk ) example: "2bhk,3+bhk" |
source | String | - | google , facebook , affiliate , emailer , linkedin , portals ,twitter , etc - this field should always contain primary origin or lead |
sub_source | String | - | google_display , google_search , facebook_brands , facebook_lead_gen , affiliate - this should identify the type of campaign either branding or performance |
placement | String | - | utm_campaign , affiliate_name e.g. taboola, nestoria, polyvalent, times_of_india, portal_name e.g. 99acres, magicbricks, housing - this should tell exact campaign details be it google facebook etc. generally you should pass utm_campaign in this |
extra_details | JSON | - | key-value pair which will contain any extra details for lead e.g. {"utm_medium: "something", "utm_source": "something", "keyword": "targetted keyword on google for the campaign"} |
campaign_id | String | True | The is a unique identifier for the project you are sending the lead for. Should be collected from point of contact in ANAROCK team. Without this lead attribution will be incorrect. |
source_id | Integer | True | This is mandatory field for sending any lead. This helps categorization of leads based on different sources. Refer to Lead Source Sub Source API |
sub_source_id | Integer | True | This is mandatory field for sending any lead. This helps categorization of leads based on different sub_sources. Refer to Lead Source Sub Source API |
campaign_id
, leads will not be attributed to the correct team, Always check with your point of contact that leads are attributed to the desired project only.
Please format phone numbers before sending using one of the libraries below
Language | Link |
---|---|
PHP | https://github.com/brick/phonenumber |
NodeJS | https://www.npmjs.com/package/awesome-phonenumber |
<?php
// shows that lead is generated from google
$source_id = 1
// shows that lead is generated from google GDN.
$sub_source_id = 8
$postFields .= "&source_id=".$source_id;
$postFields .= "&sub_source_id=".$sub_source_id;
const source_id : 1 // shows that lead is generated from google
const sub_source_id : 8 // shows that lead is generated from google GDN.
{
source_id : 1
sub_source_id: 8
}
Its very important to categorize lead depending upon the source and sub source for better understanding of performance and analysis of over all marketting channels.
While posting a lead the parameters should also have a source_id and sub_source_id as fields.
The values for which can be accessed from this API.
Example - If a lead is been generated from google GDN then
Remember โ without propersource_id
and sub_source_id
, leads will not be attributed to the correct sources. If you are running campaign on a new source and it's not present in the API, please contact Anarock team for the same.
<?php
$key = 'KEY';
$current_time = time();
$message = (string)$current_time;
// to lowercase hexits
$hash = hash_hmac('sha256', $message, $key);
$phone = 9999999999 // Phone number to test
$api_url = "https://lead-webhook.staging.anarock.com/api/v0/CHANNEL_NAME/last-lead-data?phone="+$phone+"¤t_time="+$current_time+"&hash="+$hash
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
// print_r($server_output);
const crypto = require('crypto');
const timeStamp = Math.round((new Date()).getTime() / 1000);
const message = timeStamp.toString()
const hash = crypto.createHmac('sha256', key).update(message).digest('hex')
const phone = 9999999999 // Phone number to test
axios({
method: "GET",
url: `https://lead-webhook.staging.anarock.com/api/v0/CHANNEL_NAME/last-lead-data?phone=${phone}¤t_time=${timeStamp}&hash=${hash}`
})
The API given will returns JSON structured like this:
{
"status":"OK",
"message":"success",
"response":{
"lead_id":194466,
"name":"NAME",
"email":"[email protected]",
"phone":"+9199999999",
"country_code":"+91",
"source":null,
"sub_source":null,
"placement":null,
"extra_details":null,
"project_name":"bkc test",
"source_id": 1,
"sub_source_id": 10
}
}
}
To check if a lead has been successfully submitted with all parameters captured correctly.
Use the following GET API
staging
https://lead-webhook.staging.anarock.com/api/v0/CHANNEL_NAME/last-lead-data?phone=PHONE_NUMBER¤t_time=CURRENT_TIME&hash=HASH
production
https://lead.anarock.com/api/v0/CHANNEL_NAME/last-lead-data?phone=PHONE_NUMBER¤t_time=CURRENT_TIME&hash=HASH