# Sending Email via API is failing

**URL:** <https://integration.keap.com/t/sending-email-via-api-is-failing/19365>\
**Category:** API Q&A\
**Created:** [October 28, 2017, 9:14pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365 "2017-10-28T21:14:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 28, 2017, 9:14pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/1 "2017-10-28T21:14:17Z")

</div>

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:

```auto
  [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.

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [October 29, 2017, 5:29am UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/2 "2017-10-29T05:29:23Z")

</div>

> [@Tyler\_Garns](#):
>
> array(9) {
> 
> [0]=\>

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?

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 29, 2017, 4:23pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/3 "2017-10-29T16:23:38Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 29, 2017, 4:32pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/4 "2017-10-29T16:32:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 29, 2017, 4:32pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/5 "2017-10-29T16:32:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![John\_Borelli](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/john_borelli/32/11880_2.png) [@John\_Borelli](https://integration.keap.com/u/John_Borelli)\
**Post date:** [October 29, 2017, 4:39pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/6 "2017-10-29T16:39:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bradb](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/bradb/32/13_2.png) [@bradb](https://integration.keap.com/u/bradb)\
**Post date:** [October 29, 2017, 4:39pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/7 "2017-10-29T16:39:36Z")

</div>

@Tyler_Garns what app. Let check the logs quick?

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 29, 2017, 4:41pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/8 "2017-10-29T16:41:07Z")

</div>

Thanks @bradb. App is chunk

---

<div class="post-metadata">

**Author:** ![bradb](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/bradb/32/13_2.png) [@bradb](https://integration.keap.com/u/bradb)\
**Post date:** [October 29, 2017, 4:51pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/9 "2017-10-29T16:51:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 29, 2017, 4:52pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/10 "2017-10-29T16:52:08Z")

</div>

Thanks @bradb. What’s the client\_id?

---

<div class="post-metadata">

**Author:** ![bradb](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/bradb/32/13_2.png) [@bradb](https://integration.keap.com/u/bradb)\
**Post date:** [October 29, 2017, 4:59pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/11 "2017-10-29T16:59:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 29, 2017, 5:00pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/12 "2017-10-29T17:00:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JonSmith](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/jonsmith/32/44_2.png) [@JonSmith](https://integration.keap.com/u/JonSmith)\
**Post date:** [October 30, 2017, 7:11pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/13 "2017-10-30T19:11:09Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 30, 2017, 7:28pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/14 "2017-10-30T19:28:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JonSmith](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/jonsmith/32/44_2.png) [@JonSmith](https://integration.keap.com/u/JonSmith)\
**Post date:** [October 30, 2017, 7:31pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/15 "2017-10-30T19:31:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 30, 2017, 7:53pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/16 "2017-10-30T19:53:10Z")

</div>

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);

```

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 30, 2017, 7:54pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/17 "2017-10-30T19:54:29Z")

</div>

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

```auto
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" } 

```

```auto
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) ""
}

```

```auto
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

```

````auto
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```
````

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [October 30, 2017, 7:55pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/18 "2017-10-30T19:55:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tyler\_Garns](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/tyler_garns/32/495_2.png) [@Tyler\_Garns](https://integration.keap.com/u/Tyler_Garns)\
**Post date:** [November 3, 2017, 3:21pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/19 "2017-11-03T15:21:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Carlos\_Ochoa](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/carlos_ochoa/32/2547_2.png) [@Carlos\_Ochoa](https://integration.keap.com/u/Carlos_Ochoa)\
**Post date:** [November 3, 2017, 4:37pm UTC](https://integration.keap.com/t/sending-email-via-api-is-failing/19365/20 "2017-11-03T16:37:54Z")

</div>

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.

```auto
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.

[Next page](https://integration.keap.com/t/sending-email-via-api-is-failing/19365.md?page=2)
