I don't know much about NuSoap, but unfortunately I have to use it.
I'm trying to follow example code for the dotmailer web service api Here. I need to be able to add custom fields for subscribers.
In the example code custom/additional fields are defined like so;
new SoapVar($FirstName,XSD_STRING,"string","http://www.w3.org/2001/XMLSchema");
Heres the code I have right now;
<?php
function subscribeUserEmail($email)
{
$username = "********";
$password = "********";
$postURL = "http://apiconnector.com/api.asmx?WSDL";
$contact = array (
"Email" => $email,
"AudienceType" => "B2C",
"OptInType" => "Single",
"EmailType" => "Html",
"ID" => -1,
"DataFields" => array(
"Keys" => array("TEST"),
"Values" => array("Name")
)
);
$params = array(
"username" => $username,
"password" => $password,
"contact" => $contact,
"addressbookId" => "******"
);
$client = new soapclient($postURL, true);
$error = $client->getError();
$result = $client->call('AddContactToAddressBook', $params);
echo "<h2>Request</h2>";
print("<pre>".$client->request."</pre>");
echo "<h2>Response</h2>";
print("<pre>".$client->response."</pre>");
echo "<h2>Debug</h2>";
print("<pre>".$client->debug_str."</pre>");
}
?>
If the $contact array is changed to this;
$contact = array (
"Email" => $email,
"AudienceType" => "B2C",
"OptInType" => "Single",
"EmailType" => "Html",
"ID" => -1,
"DataFields" => array(
"Keys" => array("TEST"),
"Values" => array(new SoapVar("Name",XSD_STRING,"string","http://www.w3.org/2001/XMLSchema") )
)
);
And used with a regular soap client, the code works. So I'm pretty sure there aren't any other problems with my function.
I've tried using the following;
new soapval("string", XSD_STRING, "Name","http://www.w3.org/2001/XMLSchema");
As an alternative to the SoapVar() method, but I get the same errors as if I entered the value as plain text.
How can I replicate the functionality of SoapVar() in NuSoap? This appears to be the only issue.
Related
I'm trying to insert data from a contact form (CF7) into two different table
I'm pretty sure my code is correct, but still nothing
Here's the code
remove_all_filters ('wpcf7_before_send_mail');
add_action( 'wpcf7_before_send_mail', 'my_conversion' );
function my_conversion( $cf7 )
{
$email = $cf7->posted_data["email"];
$name = $cf7->posted_data["lastname"];
$tel = $cf7->posted_data["cf_3"];
$fonction = $cf7->posted_data["cf_1"];
$entreprise = $cf7->posted_data["cf_2"];
$newsletter = $cf7->posted_data["newsletter"];
insert($email, $name, $tel, $fonction,$entreprise,$newsletter);
}
function insert($email, $name, $tel, $fonction,$entreprise,$newsletter)
{
global $wpdb;
$wpdb->insert("wp_wysija_user", array(
"user_id" => NULL,
"wpuser_id" =>"0",
"email" => $email,
"firstname" => "",
"lastname" => $name,
"ffonc" => $fonction,
"fent" => $entreprise,
"ftel" => $tel,
"ip" => "0",
"confirmed_ip" => NULL,
"confirmed_at" => NULL,
"last_opened" => NULL,
"last_clicked" => NULL,
"keyuser" => NULL,
"created_at" => "",
"status" => "0",
"domain" => ""
));
if($newsletter == "oui")
{
$wpdb->insert("wp_wysija_user_list", array(
"list" => "3",
"user_id" => NULL,
"sub_date" => "1430666348",
"unsub_date" => "0"
));
}
}
I know there's another plugin that does the job, but I'd rather do it my way
Thanks,
Jeremie.
Steps to perform:
Turn on WP Debug and see if you get some obvious error or warning
Check if the function my_conversion is called e.g. write
echo "I am called"; die;
Most probably the wpdb->insert is not working
Try the following:
var_dump( $wpdb->last_query );
or
$wpdb->print_error()
As you are most probably doin all this within an ajax request make sure to write the debugging results into a logfile or make sure you can see the results on your screen or within your console.
We want to import all our database into one of your lists. We use php. The code is:
$api_key = "dXXXXXXX7eX276XXXXXXXX490";
$list_id = "7XXXb0XXXe";
$Mailchimp = new Mailchimp($api_key);
$Mailchimp_Lists = new Mailchimp_Lists($Mailchimp);
$batch = array();
$batch[] = array('email' => array(
'email' => 'xxxgmail.com',
"euid" => "xxx#gmail.com",
"leid" => "xxx#gmail.com"
),
'merge_vars' => array('FNAME' => 'XXX'));
$subscriber = $Mailchimp_Lists->batchSubscribe($list_id, $batch, false, true, true);
But I get an error
Mailchimp_User_DoesNotExist
Could not find user record with id
I tried many times, removed uuid and leid but no success. What is wrong? Thank you!
The API key used by me was incorrect.
I'm trying to create a campaign with the Mailchimp PHP API in a custom Drupal module, but i fail to use an existing template.
I am sure of my template id in the request, but the id is always 0 in the response.
What is the correct request payload to reuse a template ?
I just want to reuse a very simple template. For now, there's no specific text for the campaign, i'll try to insert a text pattern when i'll be able to use the correct template.
Thanks in advance.
Here is my current code :
function mymodule_templates_list()
{
$mailchimpPath = realpath(__DIR__ . '/../../libraries/mailchimp');
require_once $mailchimpPath . '/src/Mailchimp.php';
require_once $mailchimpPath . '/src/Mailchimp/Templates.php';
$mailchimp = new Mailchimp('my-api-key');
$templatesService = new Mailchimp_Templates($mailchimp);
$list = $templatesService->getList(
array(
'user' => true,
'gallery' => false,
'base' => false,
),
array(
'include_drag_and_drop' => true,
)
);
dpm($list); // just to verify the template ID
$campaignService = new Mailchimp_Campaigns($mailchimp);
$response = $campaignService->getList();
dpm($response);
$options = array(
"list_id" => 'my-list-id', // this is OK, correct list used in the response
"subject" => "My subject", // OK
"from_email" => "mymail#dev.null", // OK
"from_name" => "Site name", // OK
"to_name" => '',
'template_id' => 123456, // KO : 0 in the response
);
$content = array(
"text" => "dunno what to use here",
"url" => 'dunno what to use here',
"archive" => "dunno what to use here",
);
$response = $campaignService->create('regular', $options, $content);
dpm($response);
return '';
}
I've been trying to integrate the Mailchimp API in PHP on our website, and I cannot seem to get mailchimp to take the FNAME and the LNAME.
The email always gets passed through to mailchimp and they are added to the list but the names simply don't and are always blank.
Things I have tried:
Using static names such as Dave in place of $_POST[FirstNAME] etc. but still no luck
Using MERGE1 and MERGE2 which are the alternate names for FNAME and LNAME.
Sending the email along with the FNAME and LNAME in the array for merge_vars
Putting the array in directly or as it is below within a variable ($Merge).
require('../MailCHIMP_API_PHP/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$Merge = array('FNAME' => $_POST[FirstNAME], 'LNAME' => $_POST[LastNAME]);
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array(
'email' => htmlentities($_POST[Email]),
'merge_vars' => $Merge
));
if ( ! empty( $subscriber['leid'] ) ) {
//echo "success";
} else {
//echo "fail";
}
As always there is probably something simple I am missing but I have been staring at this code for so long I obviously can't see it!
This issue was solved so thought I might as well post an answer. Here is the code that works.
require('../MailCHIMP_API_PHP/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$subscriber = $Mailchimp->call('lists/subscribe',
array(
'id' => $list_id,
'email' => array('email' => htmlentities($_POST[Email])),
'merge_vars' => array('FNAME' => htmlentities($_POST[FirstNAME]), 'LNAME' => htmlentities($_POST[LastNAME])),
'double_optin' => false
));
if ( ! empty( $subscriber['leid'] ) ) {
//echo "success";
} else {
//echo "fail";
}
I am making a start on SOAP but can't get past the first hurdle of authenticating myself...
Here is my code...
$login = array(
'loginWebRequest' => array(
'Username' => 'myuser',
'Password' => 'mypass'
)
);
$url = 'https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl';
$client = new SoapClient($url);
$result = $client->Login('Login',$login);
print_r($result);
I hope someone can see a mistake I have obviously made!
print_r($client->__getFunctions());
tells me this...
Array
(
[0] => LoginResponse Login(Login $parameters)
[1] => LogoutResponse Logout(Logout $parameters)
)
Thanks in advance
Paul
Try this:
$options = array(
"trace" => 1,
"exception" => 1
);
$login = array(
'loginWebRequest' => array(
'Username' => 'myuser',
'Password' => 'mypass'
)
);
$url = 'https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl';
$client = new SoapClient($url,$options);
$result = $client->call('Login',$login);
echo "<pre>";
print_r($client->__getLastRequest());
echo "<hr />";
print_r($result);
I recomend the use of soapui before any code, is importante to test de wsdl functions and permissions. In SOAPUI you can do a call for login function and it is more fast and easy to check for example login and password information.