API2
greywacke at June 19th, 2014 12:55 — #1
Hi there,
I am not sure whether these integrations use the API 3.0 or still the API 2.3... They have intermittently; stopped working recently: from the various integrations hosted on performatix.co - with an API Error Code 108. Could this please be investigated so I may be enlightened as to the situation of what broke where? As I need to repair these cronjobs/scripts - even though I am willing to suggest we move to API 3.0 if not already being implemented...
Also, the MySQL database stored information for OnePage CRM - is as follows: "1bab9a7eb899760d6000082;usernamel@domain.co.za;xxxxxx;undefined"
the value of "undefined" has unexpectedly entered the Performatix database for the value of "OnePage CRM Integration Contact ID", which is after "OnePage CRM Admin ID (Reference)", "OnePage CRM Integration User Name" and "OnePage CRM Integration Password" in our Supplier Manager.
This redirection (for more accurate focus) is required very urgently - please,
sincerely,
Pierre "Greywacke" du Toit.
pete_onepagecrm at June 20th, 2014 03:34 — #2
Hi Pierre,
The use of status error codes like 108
would indicate that you guys are on API v2.
The 108
code is used for invalid request data - something your API client is sending isn't as expected by the server.
Can you share what call you are making to the API, and then we can try to figure out why it could be failing.
For example, here is a list for API v2 of what can cause an Invalid request data error when updating an action:
- id is missing
- assignee_id is invalid (not a user on your account)
- name is longer than 140 characters both next and waiting are assigned
- next is assigned and date is present
- waiting is assigned and date is presentboth waiting and 'next' are not assigned and date is missing/invalid
The reason your call is failing will depend on the exact call you're making. If you can give me an example of what you're trying to do, I can investigate it further.
greywacke at June 20th, 2014 04:58 — #3
thanks for the swift response, and i suspected it is still on v2... i noted from the API Endpoint however.
the code first logs in, then creates a contact for the lead we received. below is the code used: the global function to make an api call to the system - as well as the form handler code which is supposed to create a new contact.
// Make OnePage CRM API call
function make_api_call($url, $http_method, $post_data = array(), $uid = null, $key = null, $v3 = false) {
$full_url = 'https://app.onepagecrm.com/api/'.$url;
$ch = curl_init($full_url);
//curl_setopt($ch, CURLOPT_TIMEOUT, 0);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_method);
$timestamp = time();
$auth_data = array($uid, $timestamp, $http_method, sha1($full_url));
// For POST and PUT methods we have to calculate request body hash
if($http_method == 'POST' || $http_method == 'PUT'){
$post_query = http_build_query($post_data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_query);
$auth_data[] = sha1($post_query);
}
// Auth headers
if($uid != null){ // We are logged in
$hash = hash_hmac('sha256', implode('.', $auth_data), $key);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-OnePageCRM-UID: $uid",
"X-OnePageCRM-TS: $timestamp",
"X-OnePageCRM-Auth: $hash"
));
}
$result = json_decode(curl_exec($ch));
if($ret = curl_errno($ch)) {
$info = curl_getinfo($ch);
return 'CURL ERROR '.$ret.': '.curl_error($ch).' \r'.print_r($info,true);
}
curl_close($ch);
if($result->status > 99){
return print_r("API call error {$result->status} - {$result->message}\n",true);
}
return $result;
}
// handler's 1pg integration
function onePageIntegration($onepage) {
global $uid, $key, $cid, $conn;
if ($onepage !== ";;") {
$onepage = explode(";",$onepage);
$GLOBALS["user_id"] = $onepage[0];
$api_login = $onepage[1];
$api_password = $onepage[2];
// Login
//echo "Login action...\n";
$data = make_api_call('auth/login.json', 'POST', array('login' => $api_login, 'password' => $api_password));
if($data == ""){
return "OnePage Login Failed";
}
// Get UID and API key from result
$uid = $data->data->uid;
$key = base64_decode($data->data->key);
//echo "Logged in, our UID is $uid\n";
// Create sample contact and delete it just after
//echo "Creating new contact...\n";
//echo "%CONFIGTEXT Intellisource | Premium Lead Manager OnePage CRM Unformatted Integration | ".$GLOBALS["formname"]."%";
mysql_select_db("performatix", $conn);
$new_array = explode('&',preg_replace(array('/^\s+|\n|\r|\s+$/m','/Duplicate: &/','/\<br\/\>/m'), array("","&","\r\n"), populateflags("%CONFIGTEXT Intellisource | Premium Lead Manager OnePage CRM Unformatted Integration | ".$GLOBALS["formname"]."%",false,true)));
$contact_data = array();
foreach ($new_array as $element) {
$var = explode("=",$element,2);
$contact_data[$var[0]] = $var[1];
}
//$contact_data = $new_array;
array_push($GLOBALS["sql"],"\$contact_data = ".print_r($contact_data,true));
$new_contact = make_api_call('contacts.json', 'POST', $contact_data, $uid, $key);
//print_r($new_contact);
$cid = 0;
if(!($cid = $new_contact->data->id)) {
return "OnePage Contact Failed: ".$new_contact;
}
//echo "Contact created. ID=$cid\n";
return $cid;
} else {
return "";
}
}
pete_onepagecrm at June 20th, 2014 09:46 — #4
Hi Pierre, can you give me an example of your $contact_data
array?
greywacke at June 20th, 2014 11:45 — #5
certainly, here is the array printed in the debugging email for the lead which did not enter the onepage system:
$contact_data = Array
(
[firstname] => Bipin For Cape Access Equipment
[lastname] => 110451052
[company] =>
[job_title] =>
[address] =>
[city] => Cape Town
[state] => Western Cape - Cape Town
[zip_code] => 0000
[country] => ZA
[description] => Product: ISUZU KB SINGLE CAB LOW OR HIGHLINE STANDARD
Model: 2004-2013 Requirement: NEW STANDARD WHITE Budget: R12,500 plus Fitment: ASAP Exp Fitment Date: 2014/06/26 Accessories: Comments:
[amp;nbsp;] =>
[phones] => mobile|0769569200
[emails] => other|capeaccessequip@gmail.com
[lead_source] => email_web
[starred] => 1
[owner_id] =>
[status] => lead
[tags] =>
)
greywacke at June 20th, 2014 11:50 — #6
guessing the missing owner_id is the reason for the error? this is what the last element to that array should contain. and [undefined] is not a valid value for this - i please need to locate the last successful owner id that most leads had entered for bestdeal@canopiesdirect.co.za, before they started entering as blank or undefined - so i can update the owner id in mysql...
greywacke at June 22nd, 2014 01:56 — #7
hi again... i now strongly suspect the owner_id was that of the account administrator, Performatix Integration's user id sounds sooo familiar (the top level owner id just seems so familiar, [starting with 51acf*]). the users of this account [alida@*.co.za and angie@*.co.za] should still have privileges to read / modify all leads submitted to 1pgCRM on this account, correct?)
pete_onepagecrm at June 23rd, 2014 07:29 — #8
Hi Pierre,
This is actually much simpler than that.
There is a length limit on some of the fields.
In the case above, it's failing because the string Bipin For Cape Access Equipment
is too long for the firstname field.
The following character limits apply:
firstname = max 25 characters
lastname = max 25 characters
company name = max 55 characters
These limits also apply in the web application.
You'll need to truncate these fields before sending them into the API.
Let me know if you need any more help.
Powered by Discourse, best viewed with JavaScript enabled