Sending Email via API is failing

I’ve got quite a bit of experience with the Infusionsoft API. But I’ve ran into a situation I can’t seem to solve.

I’m trying to send an email via the API and I’m getting an error.

Here’s a dump of the data I’m passing in the call as well as the error coming back:

  [0]=>
  array(1) {
    [0]=>
    int(1433)
  }
  [1]=>
  string(21) "tyler.garns@gmail.com"
  [2]=>
  string(15) "~Contact.Email~"
  [3]=>
  string(0) ""
  [4]=>
  string(0) ""
  [5]=>
  string(4) "HTML"
  [6]=>
  string(11) "Testing 123"
  [7]=>
  string(18) "Email Content HEre"
  [8]=>
  string(0) ""
}

fXmlRpc\Exception\ResponseException: Failed to parse XML-RPC request: Unknown type: nil in /var/www/html/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Exception/ResponseException.php:33 Stack trace: #0 /var/www/html/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Client.php(162): fXmlRpc\Exception\ResponseException::fault(Array) #1 /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Http/InfusionsoftSerializer.php(32): fXmlRpc\Client->call('APIEmailService...', Array) #2 /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Infusionsoft.php(387): Infusionsoft\Http\InfusionsoftSerializer->request('https://api.inf...', 'APIEmailService...', Array, Object(fXmlRpc\Client)) #3 /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php(101): Infusionsoft\Infusionsoft->request('APIEmailService...', Array, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) #4 /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php(128): Infusionsoft\Api\APIEmailService->sendEmail(Array) #5 /var/www/html/wp-content/plugins/insert-php/insert_php.php(48) : eval()'d code(2): include('/var/www/html/w...') #6 /var/www/html/wp-content/plugins/insert-php/insert_php.php(48): eval() #7 /var/www/html/wp-includes/class-wp-hook.php(298): will_bontrager_insert_php('[insert_php]\r\ni...') #8 /var/www/html/wp-includes/plugin.php(203): WP_Hook->apply_filters('[insert_php]\r\ni...', Array) #9 /var/www/html/wp-includes/post-template.php(240): apply_filters('the_content', '[insert_php]\r\ni...') #10 /var/www/html/wp-content/themes/astra/template-parts/content-page.php(30): the_content() #11 /var/www/html/wp-includes/template.php(690): require('/var/www/html/w...') #12 /var/www/html/wp-includes/template.php(647): load_template('/var/www/html/w...', false) #13 /var/www/html/wp-includes/general-template.php(167): locate_template(Array, true, false) #14 /var/www/html/wp-content/themes/astra/page.php(35): get_template_part('template-parts/...', 'page') #15 /var/www/html/wp-includes/template-loader.php(74): include('/var/www/html/w...') #16 /var/www/html/wp-blog-header.php(19): require_once('/var/www/html/w...') #17 /var/www/html/index.php(17): require('/var/www/html/w...') #18 {main}

Any ideas what I’m doing wrong here?

Thanks.

What I’m using in the rpc works with 8 parameters but you have 9…what’s that it starts with “array(9) {
[0]=>” ? Isn’t that supposed to be the key? I realize you would have removed it but shouldn’t that be a string?

Thanks for the reply John.

I’m using the SDK that passes the key after this step. This is the data I’m structuring before I pass it to the call. So, the missing API key isn’t the problem here. But thank you!

I should clarify - I’m using OAuth which sends the refreshAccessToken first, then this data you see here @John_Borelli.

Running a simple call to retrieve a contact works just fine.

Ok, so that’s why I asked. Using the SDK I have a working example:

$status = $ISAppObject->sendEmail(
array($ownerContactId),
$templateRecord[‘fromAddress’],
$templateRecord[‘toAddress’],
$templateRecord[‘ccAddress’],
$templateRecord[‘bccAddress’],
$templateRecord[‘contentType’],
$templateRecord[‘subject’],
$templateRecord[‘htmlBody’],
$templateRecord[‘textBody’]);

and all are string except the first which is an array of one

@Tyler_Garns what app. Let check the logs quick?

Thanks @bradb. App is chunk

I don’t see any errors in the logs, but this part of your error is strange Infusionsoft\Infusionsoft->request(‘APIEmailService…’, Array, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) Why does it think the values are null is my question? What is you client_id? You can PM that if you want. I will run a trace in Mashery and see what the actual values are that we see.

Thanks @bradb. What’s the client_id?

It the part of the credentials Mashery gives you. You said OAuth right?

Got it. Just pm’d it to you. Thanks.

@Tyler_Garns
It looks like from the stack trace you are storing the variables into an array then passing them to the method. Like this:

>sendEmail($array)

try doing something like this:

>sendEmail($contactArray,"tyler.garns@gmail.com","~Contact.Email~","","","HTML","Testing 123","<p>Hello World!</p>","Hello World")

Make sure that the contact’s are opted into receiving emails from Infusionsoft before sending the test as a contact that isn’t opted in will cause a failure to be returned.

Thanks @JonSmith. I actually am doing it they way you suggested. I threw it on the screen as an array so you could see what I was passing. Not working. I’m wondering if it’s having a problem with another plugin.

Will you turn on debugging and see what happens? Also will you post exactly what you are sending to the method?

Ok, here’s the raw code:

           echo "now";
            $contact = $infusionsoft->contacts()->load((int)$_POST['cids'],array("FirstName","LastName","Email"));
            var_dump($contact); echo "<br /><br />";
            $result = $wpdb->get_row("SELECT * FROM wp_users_emails WHERE Id=".(int)$_POST['emailId'],ARRAY_A);
            $emailBody = "<div style='width:100%;padding:20px;background-color:".$result['bgColor'].";'><div style='border-radius:4px;width:100%;max-width:560px;margin:0px auto;background-color:white;padding:20px;'>".nl2br($result['topText'])."<a href='#'><img src='".$result['imageUrl']."' style='width:100%;margin:20px 0px;' /></a>".nl2br($result['bottomText'])."</div></div>";
            $clist = array($_POST['cids']);
            $emailDetails = array($clist,$result['fEmail'],"~Contact.Email~","","","HTML",$result['subject'],$emailBody,"");
            echo "<pre>"; var_dump($emailDetails); echo "</pre>";
            $sent = $infusionsoft->emails()->sendEmail(array(1433),20709);
            var_dump($sent);
            echo "SENT1";
            $sent = $infusionsoft->emails->sendEmail($clist,$result['fEmail'],"~Contact.Email~","","","HTML",$result['subject'],$emailBody,"");
            echo "SENT? "; var_dump($sent);

And here’s what is ended up on the page with debugging on:

Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.0.) in /var/www/html/wp-includes/functions.php on line 4139

Notice: Constant WP_MEMORY_LIMIT already defined in /var/www/html/wp-config.php on line 91

Notice: Undefined variable: location in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 7

Notice: Undefined variable: status in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 7
nowarray(3) { ["Email"]=> string(21) "tyler.garns@gmail.com" ["FirstName"]=> string(5) "Tyler" ["LastName"]=> string(5) "Garns" } 
array(9) {
  [0]=>
  array(1) {
    [0]=>
    string(4) "1433"
  }
  [1]=>
  string(21) "tyler.garns@gmail.com"
  [2]=>
  string(15) "~Contact.Email~"
  [3]=>
  string(0) ""
  [4]=>
  string(0) ""
  [5]=>
  string(4) "HTML"
  [6]=>
  string(13) "Testing Tyler"
  [7]=>
  string(361) "
Hi ~Contact.FirstName~,More text here
"
  [8]=>
  string(0) ""
}
Warning: Missing argument 3 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 4 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 5 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 6 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 7 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 8 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 9 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Warning: Missing argument 10 for Infusionsoft\Api\APIEmailService::sendEmail(), called in /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php on line 130 and defined in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 99

Notice: Undefined variable: toAddress in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: ccAddress in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: bccAddress in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: contentType in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: subject in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: htmlBody in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: textBody in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101

Notice: Undefined variable: templateId in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php on line 101
Fatal error: Uncaught Infusionsoft\Http\HttpException: fXmlRpc\Exception\ResponseException: Failed to parse XML-RPC request: Unknown type: nil in /var/www/html/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Exception/ResponseException.php:33 Stack trace: #0 /var/www/html/vendor/lstrojny/fxmlrpc/src/fXmlRpc/Client.php(162): fXmlRpc\Exception\ResponseException::fault(Array) #1 /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Http/InfusionsoftSerializer.php(32): fXmlRpc\Client->call('APIEmailService...', Array) #2 /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Infusionsoft.php(387): Infusionsoft\Http\InfusionsoftSerializer->request('https://api.inf...', 'APIEmailService...', Array, Object(fXmlRpc\Client)) #3 /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Api/APIEmailService.php(101): Infusionsoft\Infusionsoft->request('APIEmailService...', Array, 20709, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) #4 /var/www/html/wp-content/plugins/webrtc-aws-upload/send-video.php(130): Infusionsoft\Api\APIEmailSer in /var/www/html/vendor/infusionsoft/php-sdk/src/Infusionsoft/Http/InfusionsoftSerializer.php on line 39```

You’ll see that I’m trying the simpler version of the sendEmail API call with just the TemplateID first. That’s not working either.

Anybody have any insights on this?

@bradb do you think there’s any chance I could connect with someone on Tuesday morning of next week? I’ll be at Infusionsoft HQ all day before PCON. Thanks.

Hey @Tyler_Garns is the simplified version of the sendEmail call something that you have implemented? I would like to see the simplified function itself. For example (only for demo purposes) I would expect to see a function where the elements from $customArrayOfArgs are split and evaluated into their values below.

function sendEmail($customArrayOfArgs) {
//Do the iterating of $customArrayOfArgs and ensure they end up in the format below

    return $infusionsoft->emails()->sendEmail(array(17,143829);,"Test@test.com","~Contact.Email~", "","","Text","Test Subject","tester tester","This is the body", 4579);
}

If you still need some eyes on this, please feel free to DM me.