Normally assigned user gets email when created/updated a lead in Sugar CRM.
I am using the REST API to add/update leads in suite CRM.I need to send email to the assigned user.How can it be done?
$url = "http://{site_url}/service/v4_1/rest.php";
$username = "admin";
$password = "password";
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_POST, 1);
curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($curl_request, CURLOPT_HEADER, 1);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => md5($password),
"version" => "1"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
$login_result = call("login", $login_parameters, $url);
$session_id = $login_result->id;
$set_entry_parameters = array(
"session" => $session_id,
"module_name" => "Leads",
"name_value_list" => array(
array("firstnamename" => "name", "email1" => "email","assigned_user_id"=>"xxxxx-xxxxx-xx-x-xxx"),
),
);
$set_entry_result = call("set_entry", $set_entry_parameters, $url);
?>
I can update the record.I need to send the email to the assigned user id.
Looks like it's a known bug in Sugar API since version 6.5 (and not yet corrected).
Creating a new Lead via the API not sending email Version 6.5.16 (Build 1082)
Defect 68115: Cases created or updated and assigned via REST API doesn't send out a notification
In the original forum post a guy suggested using logic hooks as a workaround. I know logic hooks exist but never used them, though I believe it's a path to try.
Good luck!
Related
const measurement_id = `G-XXXXXXXXXX`;
const api_secret = `<secret_value>`;
fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${measurement_id}&`api_secret`=${api_secret}`, {
method: "POST",
body: JSON.stringify({
client_id: 'XXXXXXXXXX.YYYYYYYYYY',
events: [{
name: 'tutorial_begin',
params: {},
}]
})
});
can someone tell me how i can do the above code in php?
i have tried the following but it is not working,
$data = array(
'client_id' => self::ga_extract_cid_from_cookies(),
'user_id' => 123,
'timestamp_micros' => time(),
'non_perosnalised_ads' => false,
'events' => array(
'name' => 'login'
)
);
$dataString = json_encode($data);
$post_url = 'https://www.google-analytics.com/mp/collect?api_secret=xxxxxxx&measurement_id=xxxxxxxxx';
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
When i run the above its not sending any event to google analytics account. I don't know what is the error and how to find it. Need help on this pls.
I believe the main problem in your example, apart from the typo in the $datastring variable, was that the user id was sent as an int, not as a string. My example here works:
$ip = str_replace('.', '', $_SERVER['REMOTE_ADDR']);
$data = array(
'client_id' => $ip,
'user_id' => '123',
'events' => array(
'name' => 'event_serverside'
)
);
$datastring = json_encode($data);
$post_url = 'https://www.google-analytics.com/mp/collect?api_secret=xxxxxxxxxx&measurement_id=xxxxxxxxx';
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POST, TRUE);
$result = curl_exec($ch);
Am trying to use PHP 7.2 to submit a new job to the Watson Video Enrichment API.
Here's my code:
//set some vars for all tasks
$apiUrl = 'https://api-dal.watsonmedia.ibm.com/video-enrichment/v2';
$apiKey = 'xxxxxxxx';
//vars for this task
$path = '/jobs';
$name = 'Test1';
$notification_url = 'https://example.com/notification.php';
$url = 'https://example.com/video.mp4';
$data = array(
"name" => $name,
"notification_url" => $notification_url,
"preset" => "simple.custom-model",
"upload" => array(
"url" => $url
)
);
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_URL, $apiUrl.$path );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Authorization: APIKey '.$apiKey
));
$result = curl_exec($ch);
echo $result;
But I can't get it to work, even with varying CURLOPTs, like:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
I keep getting the response: Bad Request.
Here's the API docs.
Am I setting up the POST CURL all wrong? Is my $data array wrong? Any idea how to fix this?
Reading their API documentation, it looks like the field preset is not of type string. Rather it has a schema defined here. This appears similar to how you are using the upload schema.
You should change your data array to look like this:
$data = array(
"name" => $name,
"notification_url" => $notification_url,
"preset" => array(
"video_url" => "https://example.com/path/to/your/video"
),
"upload" => array(
"url" => $url
)
);
Ok, I figured it out. Thanks to #TheGentleman for pointing the way.
My data array should look like:
$data = array(
"name" => $name,
"notification_url" => $notification_url,
"preset" => array(
"simple.custom-model" => array(
"video_url" => $url,
"language" => "en-US"
)
),
"upload" => array(
"url" => $url
)
);
I am trying to create a new list via the mailchimp api, I have tried tweaking the code so much but keep getting the error:
{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Invalid Resource","status":400,"detail":"The resource submitted could not be validated. For field-specific details, see the 'errors' array.","instance":"0174d737-b3d4-40a6-9cd4-e934ed8578a7","errors":[{"
field":"","message":"Schema describes object, NULL found instead"}]}
My code (api key is valid):
$data = array( // the information for your new list--not all is required
"name" => $name,
"contact" => array (
"company" => $company,
"address1" => $address1
),
"permission_reminder" => $permission_reminder,
"use_archive_bar" => $archive_bars,
"campaign_defaults" => array(
"from_name" => $from_name,
"from_email" => $from_email,
"subject" => $subject,
"language" => $language
),
"notify_on_subscribe" => $notify_subs,
"notify_on_unsubscribe" => $notify_unsubs,
"email_type_option" => $type,
"visibility" => $visibility
);
$ch = curl_init("https://$dataCenter.api.mailchimp.com/3.0/lists/");
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($result); // display API response
I'm not seeing any JSON encoding of your payload in the code you provided. You will need to json_encode() your payload ($data) in order for MailChimp to be able to read it.
Like this:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
I'm looking for XMLRPC keywords to find out a list of users of a BUGZILLA project.
Here is my code, login works fine and im' able to use several keywords to find out what i need : Bug.search, Bug.fields.
public function loginBz($url,$login,$password,$getResult)
{
set_time_limit(0);
$URI = $url;
$xml_data = array(
'login' => $login,
'password' => $password,
'remember' => 1
);
$ch = curl_init();
$file_cookie = tempnam ("/tmp", "CURLCOOKIE");
$options = array(
//CURLOPT_VERBOSE => true,
CURLOPT_URL => $URI,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array( 'Content-Type: text/xml', 'charset=utf-8' )
);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data);
// var_dump($request);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
$response = xmlrpc_decode($server_output);
//print_r ($response);
if($getResult)
return $response;
else
return $ch;
}
public function getFieldsBz($product,$component,$ch){
$xml_data = array(
'product' => $product,
'component' => '$component'
);
$request = xmlrpc_encode_request("Bug.user", $xml_data); // create a request for filing bugs
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example
$response = xmlrpc_decode($server_output);
return $response;
}
I've been searching into BugZilla API but did not found what I need : List of Users for a product Bz.
Does anyone know which keyword I have to use in xmlrpc_encode_request(keyword,array_filter) ?
It would help :)
First there isn't a method called Bug.user, see https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/Bug.html for a complete list.
There is a method called User.get, see https://www.bugzilla.org/docs/4.4/en/html/api/Bugzilla/WebService/User.html#get
There is a parameter called groups which may do what you want depending on how you setup Bugzilla security.
You can use https://xmlrpc.devzing.com/ to experiment or if you upgrade to Bugzilla 5.x you can use the new REST API. https://www.bugzilla.org/docs/5.0/en/html/api/Bugzilla/WebService/Server/REST.html
What's the best way to check a batch of email addresses and whether or not they are subscribed to a particular list? My current method is making an API call for each email address, but this becomes very slow when the count becomes > 50.
I'm using V2.0, using PHP methods since I'm developing on CakePHP.
//Determine MailChimp Subscription
$args = array(
'id' => $this->apiKeys['mailchimp_list_ID'],
'emails' => array(1 => array('email' => $customer['User']['username']))
);
$mailChimpQuery = $this->mailChimp('member-info', $args);
$mailChimpStatus = ($mailChimpQuery['success_count'] == 1 ? 1 : 0);
$customer['Customer']['subscribed'] = $mailChimpStatus;
The mailChimp call in another Controller is:
public function mailChimp($action, $args=array()) {
$args['apikey'] = $this->apiKeys['mailchimp_api'];
$url = 'https://us8.api.mailchimp.com/2.0/lists/' . $action .'.json';
if (function_exists('curl_init') && function_exists('curl_setopt')){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
$result = curl_exec($ch);
curl_close($ch);
} else {
$json_data = json_encode($args);
$result = file_get_contents($url, null, stream_context_create(array(
'http' => array(
'protocol_version' => 1.1,
'user_agent' => 'PHP-MCAPI/2.0',
'method' => 'POST',
'header' => "Content-type: application/json\r\n".
"Connection: close\r\n" .
"Content-length: " . strlen($json_data) . "\r\n",
'content' => $json_data,
),
)));
}
return $result ? json_decode($result, true) : false;
}
FYI, I came up with my own solution:
Create an array of all the email addresses in the database
Create a for-loop that takes segments of 50 email addresses from that array and runs a batch check using member-info (https://apidocs.mailchimp.com/api/2.0/lists/member-info.php)
Manipulate the return array from the API call to extract only the email address and whether or not it's subscribed to the list.
Within the for-loop, add each 50 email addresses return values into a new array and then by the end of it; you'll have an array of all the email addresses in your database with a corresponding true/false value depending on whether or not they are subscribed to the list.
Good luck!