Im trying to take data from Contact Form 7 WordPress plugin and pass it with json to GetResponse API
I have a php file that pull the data and send it, and its looks like this
I'm getting the CF7 email of confirmation but im not getting GetResponse Email confirmation for newsletter, i don't understand why, i tried to do some debugging and there was no errors
add_action('wpcf7_before_send_mail', 'mytheme_save_to_getresponse', 10, 1);
function mytheme_save_to_getresponse($form)
{
include 'ChromePhp.php';
require_once 'jsonRPCClient.php';
$api_key = 'some_api_key';
$api_url = 'http://api2.getresponse.com';
$client = new jsonRPCClient($api_url);
$result = NULL;
try {
$result = $client->get_campaigns(
$api_key,
array (
# find by name literally
'name' => array ( 'EQUALS' => 'testcase_001' )
)
);
}
catch (Exception $e) {
# check for communication and response errors
# implement handling if needed
die($e->getMessage());
}
$campaigns = array_keys($result);
$CAMPAIGN_ID = array_pop($campaigns);
$subscriberName = $_POST['name'];
$subscriberEmail = $_POST['email'];
$subscriberPhone = $_POST['c_phone'];
$subscriberCellphone = $_POST['c_cellphone'];
$subscriberArea = $_POST['c_area'];
$subscriberInsuranceType = $_POST['c_type'];
$subscriberCarType = $_POST['c_cartype'];
$subscriberManifacture = $_POST['c_manifacture'];
$subscriberManifacturemodel = $_POST['c_manifacturemodel'];
$subscriberManifactureYear = $_POST['c_manifactureyear'];
$subscriberDriverAge = $_POST['c_driversage'];
$subscriberPrevent = $_POST['c_prevent'];
$subscriberClaim = $_POST['c_claim'];
try {
$result = $client->add_contact(
$api_key,
array (
'campaign' => $CAMPAIGN_ID,
'name' => $subscriberName,
'email' => $subscriberEmail,
'cycle_day' => '0',
'customs' => array(
array(
'name' => 'home_phone',
'content' => $subscriberPhone
),
array(
'name' => 'cell_phone',
'content' => $subscriberCellphone
),
array(
'name' => 'living_area',
'content' => $subscriberArea
),
array(
'name' => 'drivers_age',
'content' => $subscriberDriverAge
),
array(
'name' => 'insurance_type',
'content' => $subscriberInsuranceType
),
array(
'name' => 'car_type',
'content' => $subscriberCarType
),
array(
'name' => 'manifacture_type',
'content' => $subscriberManifacture
),
array(
'name' => 'manifacture_model',
'content' => $subscriberManifacturemodel
),
array(
'name' => 'manifacture_year',
'content' => $subscriberManifactureYear
),
array(
'name' => 'license_loss',
'content' => $subscriberPrevent
),
array(
'name' => 'claims_number',
'content' => $subscriberClaim
)
)
)
);
}
catch (Exception $e) {
# check for communication and response errors
# implement handling if needed
die($e->getMessage());
}
}
Thanks in advance
everything was OK with this code, i GetResponse don't send confirmation requests more than once on the same email..
Related
The developer guide for SuiteCRM is kind of incomplete (at least here in Q4 2017) compared to the old SugarCRM one that it was based on before the software fork. So, by downloading the WordPress Plugin for SugarCRM, I was able to figure out the REST API and JSON for adding a sales lead into SuiteCRM with the following code.
Now how do I prevent duplicates by home phone, mobile phone, or email address?
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
header('Content-Type: text/plain');
CRM::loginCRM('admin','xxxxPASSWORDxxxxxx');
$aResult = CRM::addLead(array(
'name' => 'John Doe',
'description' => 'sample description',
'salutation' => 'Mr.',
'first_name' => 'John',
'last_name' => 'Doe',
'do_not_call' => 'No',
'phone_home' => '202-111-2222',
'phone_mobile' => '202-111-2222',
'email1' => 'test#example.com',
'primary_address_street' => '123 Main Street',
'primary_address_street2' => '',
'primary_address_street3' => '',
'primary_address_city' => 'New York',
'primary_address_state' => 'NY'
));
print_r($aResult);
CRM::logoutCRM();
die('OK');
/////////////////////////
class CRM {
private static $SessionID = '';
private static $URL = 'https://mycrmserver-example.com/service/v4_1/rest.php';
private static $User = '';
private static $Shadow = '';
public static function sendJSON($a) {
$s = file_get_contents(
self::$URL,
false,
stream_context_create(
array(
'http' => array (
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => http_build_query($a)
)
)
)
);
$a2 = json_decode($s);
return $a2;
}
public static function loginCRM($sUser,$sPass) {
$sShadow = md5($sPass);
self::$User = $sUser;
self::$Shadow = $sShadow;
$asLogin = array (
'method' => 'login',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode(array(
'user_auth' => array(
'user_name' => $sUser,
'password' => $sShadow,
'version' => 1
),
'application_name' => 'RestTest',
'name_value_list' => array()
))
);
$a = self::sendJSON($asLogin);
self::$SessionID = $a->id;
}
public static function logoutCRM() {
$asLogin = array (
'method' => 'logout',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode(array(
'user_auth' => array(
'user_name' => self::$User,
'password' => self::$Shadow,
'version' => 1
),
'application_name' => 'RestTest',
'name_value_list' => array()
))
);
self::sendJSON($asLogin);
}
public static function addLead($a) {
$asNameValueList = array();
foreach($a as $sKey => $sVal) {
$asNameValueList[] = array('name'=>$sKey,'value'=>$sVal);
}
$asAddEntry = array (
'method' => 'set_entry',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode(array(
'session' => self::$SessionID,
'module_name' => 'Leads',
'name_value_list' => $asNameValueList
))
);
$a = self::sendJSON($asAddEntry);
return $a;
}
} // end CRM
Add these functions into your CRM class and check them before adding a lead. I had a little help from this answer that incidentally gave me some insights. Also, I recommend you do things to tighten down your security such as add an .htaccess or NGINX rule that only allows certain IP addresses or require certain headers to reach anything in your /service folder, and /service/* subfolders either over HTTP or HTTPS.
public static function leadExistsByPhone($sHomePhone,$sMobilePhone) {
$sHomePhone = (empty($sHomePhone)) ? 'xxxxxinvalid' : $sHomePhone;
$sMobilePhone = (empty($sMobilePhone)) ? 'xxxxxinvalid' : $sMobilePhone;
$asCheck = array (
'method' => 'get_entry_list',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode(array(
'session' => self::$SessionID,
'module_name' => 'Leads',
'query' => "
leads.phone_home = '$sHomePhone'
OR leads.phone_mobile = '$sMobilePhone'
",
'order_by' => 'leads.date_entered DESC',
'offset' => '0',
'select_fields' => array(),
'link_name_to_fields_array' => array(),
'max_results' => 999999,
'deleted' => false
))
);
$a = self::sendJSON($asCheck);
$nCount = # $a->result_count;
$nCount = intval($nCount);
return ($nCount > 0);
}
public static function leadExistsByEmail($sEmail) {
if (!filter_var($sEmail, FILTER_VALIDATE_EMAIL)) {
die('DENIED: invalid email address format');
}
$asCheck = array (
'method' => 'get_entry_list',
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => json_encode(array(
'session' => self::$SessionID,
'module_name' => 'Leads',
'query' => "
leads.id IN
(
SELECT email_addr_bean_rel.bean_id
FROM email_addr_bean_rel
JOIN email_addresses
ON email_addr_bean_rel.email_address_id = email_addresses.id
WHERE
email_addresses.email_address = '$sEmail'
)
",
'order_by' => 'leads.date_entered DESC',
'offset' => '0',
'select_fields' => array(),
'link_name_to_fields_array' => array(),
'max_results' => 999999,
'deleted' => false
))
);
$a = self::sendJSON($asCheck);
$nCount = # $a->result_count;
$nCount = intval($nCount);
return ($nCount > 0);
}
I am getting error from Facebook Marketing API when creating Leadgen Form. I followed Facebook guide but nothing worked yet. API documentation link
In previous I was successfully create leadgen legal content, leadgen context cards, leadgen conditional questions group and conditional questions group csv. After that I am trying to create Leadgen Form but API returns Invalid parameter
$config = Config::get('facebook');
$data['account_id'] = 'act_'.$config['ad_account_id'];
$data['page_id'] = $config['page_id'];
$api = Api::init($config['app_id'], $config['app_secret'], $config['access_token']);
// Init facebook
$legal_params = array(
'privacy_policy' => array(
'url' => 'http://example.com/privacy-policy',
'link_text' => 'Privacy Policy'
),
'custom_disclaimer' => array(
'title' => 'Terms and Conditions',
'body' => array(
'text' => 'My custom disclaimer',
'url_entities' => array(
array("offset" => 3, "length" => 6, "url" => 'http://example.com/privacy-policy')
),
),
'checkboxes' => array(array(
"is_required" => false,
"is_checked_by_default" => false,
"text" => "Allow to contact you",
"key" => "checkbox_1",
))
),
);
$legal_res = Api::instance()->call('/'.$data['page_id'].'/leadgen_legal_content',
RequestInterface::METHOD_POST,
$legal_params)->getContent();
$legal_content_id = $legal_res['id'];
$contex_params = array(
'title' => 'Thank You',
'style' => 'LIST_STYLE',
'content' => array(
'Easy sign-up flow',
'Submit your info to have a chance to win',
),
'button_text' => 'Get started',
);
$contex_res = Api::instance()->call('/'.$data['page_id'].'/leadgen_context_cards',
RequestInterface::METHOD_POST,
$contex_params)->getContent();
$context_card_id = $contex_res['id'];
// Conditional Questions
$conditional_request = Api::instance()->prepareRequest(
'/'.$data['page_id'].'/leadgen_conditional_questions_group',
RequestInterface::METHOD_POST);
$conditional_request->getFileParams()->offsetSet(
'conditional_questions_group_csv',
(new FileParameter(public_path().'/facebook/lead-csv-form.csv'))->setMimeType("text/csv"));
$csv_data = Api::instance()->executeRequest($conditional_request)->getContent();
$questions_group_id = $csv_data['id'];
// Create Lead Form
$form = new LeadgenForm(null, $data['page_id']);
$form->setData(array(
LeadgenFormFields::NAME => 'Test LeadAds Form Name',
LeadgenFormFields::FOLLOW_UP_ACTION_URL => 'https://www.facebook.com/examplepage',
LeadgenFormFields::QUESTIONS => array(
(new LeadGenQuestion())->setData(array(
LeadgenQuestionFields::TYPE => 'EMAIL',
)),
(new LeadGenQuestion())->setData(array(
LeadgenQuestionFields::TYPE => 'CUSTOM',
LeadgenQuestionFields::LABEL => 'Country',
'conditional_questions_group_id' => $questions_group_id,
'dependent_conditional_questions' => array(
array('name' => 'State'),
array('name' => 'City'),
)
)),
),
'block_display_for_non_targeted_viewer' => true,
'context_card_id' => $context_card_id,
'legal_content_id' => $legal_content_id,
));
$form->create();
I am using Laravel push notification library, for pushing notification.
However, i can easly get responses for GCM responses for Android Device.
But unable to get APNS response.
$message = PushNotification::Message("New Messages",$params['payload']);
$collection = PushNotification::app('appNameIOS')
->to($params['reg_id'])
->send($message);
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
}
Make sure you have followed proper format as below:-
//iOS app
PushNotification::app(['environment' => 'development',
'certificate' => '/path/to/certificate.pem',
'passPhrase' => 'password',
'service' => 'apns']);
$devices = PushNotification::DeviceCollection(array(
PushNotification::Device('token', array('badge' => 5)),
PushNotification::Device('token1', array('badge' => 1)),
PushNotification::Device('token2')
));
$message = PushNotification::Message('Message Text',array(
'badge' => 1,
'sound' => 'example.aiff',
'actionLocKey' => 'Action button title!',
'locKey' => 'localized key',
'locArgs' => array(
'localized args',
'localized args',
),
'launchImage' => 'image.jpg',
'custom' => array('custom data' => array(
'we' => 'want', 'send to app'
))
));
$collection = PushNotification::app('appNameIOS')
->to($devices)
->send($message);
// get response for each device push
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
}
Is it just me or is there almost no documentation on how to do this? Mandrill's site isn't much help. Anyway...here's the problem...
try {
$mandrill = new Mandrill('API_KEY');
$attachment = file_get_contents("../template.xls");
$attachment_encoded = base64_encode($attachment);
$message = array(
'html' => '<p>Some html text</p>',
'text' => 'Some text',
'subject' => 'Subject',
'from_email' => 'email#domain.com',
'from_name' => 'Name',
'to' => array(
array(
'email' => 'myemail#domain.com',
'name' => 'Name',
'type' => 'to'
)
),
'attachments' => array(
array(
'type' => 'application/vnd.ms-excel',
'name' => 'New_Features_Submission.xls',
'path' => $attachment_encoded
)
)
);
$async = false;
$result = $mandrill->messages->send($message, $async);
print_r($result);
} catch (Mandrill_Error $e) {
echo 'A Mandrill error occured: ' . get_class($e) . '-' . $e->getMessage();
throw $e;
}
The email sends correctly, but I can't even open the .xls file. I tried using 'application/xls' for the type, that didn't work either. I'm not familiar with encoding, help please!
This line:
'path' => $attachment_encoded
Needs to be this:
'content' => $attachment_encoded
I'm using the latest version (2) of SDK for php. Below is a snippet of code for assigning a name tag to existing instance:
try {
$result = $ec2->createTags(array(
'Resources' => array($instanceid),
'Tags' => array(
'Name' => 'PWC_cwc'),
));
} catch (Exception $e) {
die("Failed to create tag name: ".$e."<br>");
}
Output:
Failed to create tag name: exception 'Guzzle\Service\Exception\ValidationException' with message 'Validation errors: [Tags][Name][Tag] must be of type object' in /Users/harry/Documents/workspace/BigData/vendor/guzzle/guzzle/src/Guzzle/Service/Command/AbstractCommand.php:394 Stack trace: #0
I'm guessing something is wrong with the way I pass the argument, but just couldn't figure out the correct way of doing this
The API link for createTags method is here: http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Ec2.Ec2Client.html#_createTags
You have to specify the 'Key' and 'Value' of each tag.
$args = array(
'DryRun' => False,
'Resources' => array($resource),
'Tags' => array(
array(
'Key' => 'firstkey',
'Value' => $firstkeyvalue),
array(
'Key' => 'secondkey',
'Value' => $secondkeyvalue),
array(
'Key' => 'thirdkey',
'Value' => $thirdkeyvalue)
));
$response = $ec2->createTags($args);
Try this:
$result = $ec2->createTags(array(
'Resources' => array($instanceid),
'Tags' => array(
'Tag' => array(
'Key' => '<key>',
'Value' => '<value>'
)
)
));
You need to have an array of 'Tag' inside the 'Tags' array.