# Opt in user error handler

**URL:** <https://integration.keap.com/t/opt-in-user-error-handler/5420>\
**Category:** API Q&A\
**Created:** [July 17, 2017, 7:04pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420 "2017-07-17T19:04:28Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 17, 2017, 7:04pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/1 "2017-07-17T19:04:28Z")

</div>

I am trying to Opt in for a user based on email address, but getting error.

```
	global $infusionsoft;

	$infusionsoft->refreshAccessToken();

	//opt in user
	$billing = $order->get_address( $type = 'billing' );
	$email = $billing['email'];
	error_log('email is '.$email);

	$optIn = $infusionsoft->emails('optIn', $email, 'I have Permission box was checked');

```

//// Error Message  
WP\_Error Object  
(  
[errors] =\> Array  
(  
[invalid-request] =\> Array  
(  
[0] =\> No such handler: EmailsService.optIn  
)

```
    )

[error_data] => Array
    (
    )

```

)

---

<div class="post-metadata">

**Author:** ![Pav](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/pav/32/124_2.png) [@Pav](https://integration.keap.com/u/Pav)\
**Post date:** [July 17, 2017, 9:00pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/2 "2017-07-17T21:00:18Z")

</div>

Sounds like a bug in the SDK. The Email Service handler is “APIEmailService”.

[https://developer.infusionsoft.com/docs/xml-rpc/#email-opt-in-an-email-address](https://developer.infusionsoft.com/docs/xml-rpc/#email-opt-in-an-email-address)

---

<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:** [July 17, 2017, 9:51pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/3 "2017-07-17T21:51:15Z")

</div>

> [@Del\_Chefv](#):
>
> $optIn = $infusionsoft-\>emails(‘optIn’, $email, ‘I have Permission box was checked’);

The above line is wrong according to documentation it should be:

$infusionsoft-\>emails()-\>optIn($email, ‘I have Permission box was checked’);

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 17, 2017, 10:34pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/4 "2017-07-17T22:34:11Z")

</div>

Thanks John,

I am still getting error, which document are you referring to.

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:** [July 17, 2017, 10:43pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/5 "2017-07-17T22:43:56Z")

</div>

Going from the code you posted, you’re using the api (not iSDK)…documentation for optin for the api can be found here:

[https://developer.infusionsoft.com/docs/xml-rpc/#email-opt-in-an-email-address](https://developer.infusionsoft.com/docs/xml-rpc/#email-opt-in-an-email-address)

Also, what is the post back you are getting. ie make it

$return=$infusionsoft-\>emails()-\>optIn($email, ‘I have Permission box was checked’);  
var\_dump($return);

I’m asking this way because the error you’re showing is a WP error

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 17, 2017, 11:01pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/6 "2017-07-17T23:01:11Z")

</div>

when i implement the example code, it crashes the website.

i am not getting any errors

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:** [July 17, 2017, 11:12pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/7 "2017-07-17T23:12:20Z")

</div>

Then test away from your framework. Create a stand alone file that gets the message for you.

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 19, 2017, 4:25pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/8 "2017-07-19T16:25:51Z")

</div>

Thanks for your reply.

I create stand alone file, still retrieving same problem.

Can you please provide me an example for this?

---

<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:** [July 19, 2017, 4:31pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/9 "2017-07-19T16:31:31Z")

</div>

What is the return value as I described doing above?

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 19, 2017, 4:34pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/10 "2017-07-19T16:34:59Z")

</div>

Same thing what happend above. it’s crashes …

---

<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:** [July 19, 2017, 4:36pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/11 "2017-07-19T16:36:40Z")

</div>

Then it’s not api related. Either syntax or server. So place die(); after each line, one at a time, and see how far down you can go before it crashes. Then focus on the structure or function of that specific line. Also, ensure that error\_reporting is set to E\_ALL

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 19, 2017, 4:39pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/12 "2017-07-19T16:39:16Z")

</div>

thanks for your help and fast reply, I well debugging to find the problem.

---

<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:** [July 20, 2017, 2:02pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/13 "2017-07-20T14:02:24Z")

</div>

@Del_Chefv  
Try using APIEmailService.optIn instead of EmailsService.optIn as this appears to be the issue

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 20, 2017, 3:49pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/14 "2017-07-20T15:49:22Z")

</div>

Thanks @JonSmith where can I find APIEmailService in [xml-rpc - Keap Developer Portal](https://developer.infusionsoft.com/docs/xml-rpc/#introduction)

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:** [July 20, 2017, 4:12pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/15 "2017-07-20T16:12:16Z")

</div>

[https://developer.infusionsoft.com/docs/xml-rpc/#email-opt-in-an-email-address](https://developer.infusionsoft.com/docs/xml-rpc/#email-opt-in-an-email-address)

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 20, 2017, 4:20pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/16 "2017-07-20T16:20:37Z")

</div>

the example code what is displayed in the library did not work for me.

After debugging I found this call was working for me:  
$optin = $infusionsoft-\>APIEmail(‘optIn’, $email, ‘I have Permission box was checked’);  
var\_dump($optin);

But i am getting bool(false);

---

<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:** [July 20, 2017, 4:32pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/17 "2017-07-20T16:32:51Z")

</div>

If the email is already opted in then the return value will be false. You will only get a true when an email that is currently unmarketable will return true and then will return false every time there after.

---

<div class="post-metadata">

**Author:** ![Del\_Chefv](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/del_chefv/32/403_2.png) [@Del\_Chefv](https://integration.keap.com/u/Del_Chefv)\
**Post date:** [July 20, 2017, 4:40pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/18 "2017-07-20T16:40:44Z")

</div>

Thanks, @John_Borelli, every example code in PHP from the library did not work out for me.

My solution is 🤘  
$infusionsoft-\>emails()-\>getOptStatus($email)

should be…

$infusionsoft-\>APIEmail( ‘getOptStatus’, $email);

@JonSmith Maybe updating the Libary will be useful or something is wrong on my side…

---

<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:** [July 20, 2017, 7:58pm UTC](https://integration.keap.com/t/opt-in-user-error-handler/5420/19 "2017-07-20T19:58:59Z")

</div>

You could submit a request for that doc to be updated. The methods you have indicated you used in the first place, they all work for me. You shouldn’t need to get the status. blindly optin the email. What changes for you if they’re opted out already or already opted in, that you need to know that this particular time the call returned true? The results are still the same…?
