Set CivCRM Email to Blank by REST API - rest

I am trying to set the email address to blank in CiviCRM. I serialise an array as below and post via REST (code is groovy):
def rest = [
json: 1,
api_key: apiKey,
key: siteKey,
debug: 1,
version: 3,
entity: 'Contact',
action: 'create',
contact_type: contact_type,
overwriteblank:true,
id: record.crID,
rest["email[1][email]"] = modified.value as String
rest["email[1][location_type_id]"] = 1
]
I have tried the 'overwriteblank' option - but the email still does not seem to be set to blank.
Thanks

An email address is a separate API entity from the contact (since a contact can have an infinite number of email addresses). All you need to do is get the email entries where the contact_id = whatever and then delete them.
$result = civicrm_api3('Email', 'get', array('contact_id' => $YOUR_CONTACT_ID));
then after checking for errors and iterating over $result['values']:
$deleted = civicrm_api3('Email', 'delete', array('id' => $YOURRESULTROW['id']));
With the SQL method, you're not deleting the email so much as setting that person's email to be an empty string.

The best that I could do was by sql.
String sql_update = """update civicrm_email set email = "" where contact_id = ?"""

Related

Create new contact to Mailjet and adding to an existing list

After subscription on my website form, I need to create the new contact on Mailjet and then add it to a specific list that already exist.
I have this following code which I execute after insert my user to database.
$firstname = "Michael";
$email = myemail#gmail.com;
$mj = new \Mailjet\Client($MJ_APIKEY_PUBLIC,$MJ_APIKEY_PRIVATE);
// create new contact on Mailjet
$contact_params = [
"Email" => $email
];
$response_add = $mj->post(Resources::$Contact, ['body' => $contact_params]);
// adding the created contact to my list
$list_params = [
'Name' => $firstname,
'Action' => "addnoforce",
'Email' => $email
];
$response_list = $mj->post(Resources::$ContactslistManagecontact, ['id' => 10181436, 'body' => $list_params]);
The contact is correctly created on Mailjet but never add to the list. The $response_list always give me back NULL and I don't really know why. I'm pretty new with Mailjet API, but I've following the official API and the way I want to do it seems correct. (https://dev.mailjet.com/email/reference/contacts/subscriptions#v3_post_contactslist_list_ID_managecontact)
Thanks for help :)
In case you are yet to find a solution.
Try this out, it works for me.
Check the "/contactslist/{list_ID or list_address}/managecontact" section on this documentation; https://dev.mailjet.com/email/reference/contacts/subscriptions#v3_post_listrecipient
Enjoy

Unable to get Response Parameters in Notification and Success url SOFORT API

public function sofyAction()
{
$args = [ 'config_key' => $this->getConfigKey() ];
$sofy = new Api($args);
$helper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
$successUrl = $helper($this->url()->fromRoute('sofort_response'));
$params = [
'amount' => 1500,
'currency_code' => 'EUR',
'reason' => 'Vouhcer Order',
'success_url' => $successUrl,
'customer_protection' => false,
'notification_url' => 'MY_PRIVATE_RESPONSE_URL',
];
$trans = $sofy->createTransaction($params);
return $this->redirect()->toUrl($trans['payment_url']);
}
How to get response and transaction ID as given it API document in Notification URL and on success URL too , please unable to find any help or guide for it ?
The easiest way is to let Payum do notification related job for you. To do so you either:
have to create manually a notification token using Payum's token factory (I am not sure it is present in the Zend module, it is quite old). Use the token as notification_url. Nothing more. Sofort will send a request to that url and Payum does the rest.
Make sure the token factory is passed to a gateway object and later is injected to capture action object. Leave the notification_url field empty and Payum will generate a new one.
use your own url as notification one and add there all the info you need (as a query string). I wouldn't recommend it since you expose sensitive data and once could try to exploit it.
I solved it this way by appending ?trx=-TRANSACTION- with success and notification url and than in response i recieved Transaction id as parameter and later loaded TransactionData with that transactionId . Payum Token way wasn't working for me ! Obiously had to use its config key to create Payum/Sofort/Api isnstance,
REQUEST:
$args = [ 'config_key' => $sofortConfigKey ];
$sofortPay = new Api($args);
// ?trx=-TRANSACTION- will append transacion ID as response param !
$params = [
'amount' => $coupon['price'],
'currency_code' => $coupon['currency'],
'reason' => $coupon['description'],
'success_url' => $successUrl.'?trx=-TRANSACTION-',
'abort_url' => $abortUrl.'?trx=-TRANSACTION-',
'customer_protection' => false,
'notification_url' => '_URL_'.'?trx=-TRANSACTION-',
];
$transactionParams = $sofortPay->createTransaction($params);
return $this->redirect()->toUrl($transactionParams['payment_url']);
RESPONSE:
$args = [ 'config_key' => $configKey ];
$sofy = new Api( $args );
$transNumber = $this->getRequest()->getQuery('trx');
$fields = $sofy->getTransactionData($transNumber);
Took help from API document. Payum documentation is worst. SOFORT API DOC

Store email body in table using Laravel 5.3 Mailable

I want to store the email body in my communications table. My controller:
Mail::to($user->email)->send(new WelcomeEmail($subscription));
Communication::create([
'to' => $user->email,
'subject' => 'Welcome Email',
'body' => '???'
]);
My email goes out (successfully) and I am able to create a Communication record, but have no idea how to retrieve the email body.
After reading the Mail manual, I thought I could work with an event:
protected $listen = [
'Illuminate\Mail\Events\MessageSending' => [
'App\Listeners\LogSentMessage',
],
];
But here I get only the full plain text email. If I create an instance of the mail, with:
$email = Mail::to($user->email)->send(new WelcomeEmail($subscription));
the outcome of dd($email); is null.
Some extra info, in my WelcomeEmail.php, I am using a view:
public function build()
{
return $this->view('emails.welcome_email');
}
You can directly do this to render Mailable and store it in a variable
$html = (new WelcomeEmail($subscription))->render();
I found a solution, hopefully it can help other people.
$body = View::make('emails.welcome_email')
->with('subscription', $this->subscription)
->with('template', $this->template)
->render();
I rendered the view and saved it in the body variable.

send email via Magento

I've seen on a few blog articles that this is a common way to send an email in Magento, but I have for the life of me, no idea why this email isnt being sent in 1.10! This is my method:
protected function _emailCode($code, $invoice) {
$order = $invoice->getOrder();
// Transactional Email Template's ID
$templateId = 1;
// Set sender information
$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName,
'email' => $senderEmail);
// Set recepient information
$recepientEmail = $order->getCustomerEmail();
$recepientName = $order->getCustomerName();
// Get Store ID
$storeId = Mage::app()->getStore()->getId();
// Set variables that can be used in email template
$vars = array('voucherCode' => $code);
$translate = Mage::getSingleton('core/translate');
// Send Transactional Email
Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
$translate->setTranslateInline(true);
}
I should note that emails works in other parts of Magento so sendmail is working properly and all that, also all my variables here are defined correctly and not empty when going through this.
Thanks!
Are you sure that transactional email with ID=1 exist?
try setting $templateId='sales_email_order_template'
this is a default template, should fit working script.
Check exception.log also.

How do I send an Email with no "to" address using Mail::Sender?

Is it possible to send an Email with only cc or bcc recipients using Mail::Sender? When I try to send an Email without a "to" address, I get the expected return code:
-8 = argument $to empty
Using an empty string '' in the "to" field does not work. Using a space works like a charm.
use Mail::Sender;
my $sender = Mail::Sender->new();
my $mail = {
smtp => 'mailserver',
from => 'example#example.com',
to => ' ',
bcc => 'example#example.com',
subject => 'test',
ctype => 'text/plain; charset=utf-8',
skip_bad_recipients => 1,
msg => 'test'
};
my $ret = $sender->MailMsg($mail);
print $ret;
Does the fake_to parameter work:
fake_to
=> the recipient's address that will be shown in headers. If not specified we use the value of "to".
If the list of addresses you want to send your message to is long or if you do not want the recipients to see each other's address set the fake_to parameter to some informative, yet bogus, address or to the address of your mailing/distribution list.
http://metacpan.org/pod/Mail::Sender
Looking at the source, it seems you'd still need to set the to parameter to something. Perhaps " " would do the trick?
Have you tried using '' ?