0

I am developing code that sends an email from our website through Infusionsoft API & XMLRPC.

Here my code:

$email = $user_rec['email'];
    $contactID=$user_rec['client_infusionid'];      
    echo $contactID;

    $Subject = 'Your reset password request at GIC Deal Finders';

    $From = $this->GetFromAddress();

    $link = 'http://dashboard.gicdealfinders.info/resetpwd.php?email='.
            urlencode($email).'&code='.
            urlencode($this->GetResetPasswordCode($email));

    $htmlBody ='Hello '.$user_rec["name"].'<br/><br/>'.
    'There was a request to reset your password at GIC Deal Finders<br/>'.
    'Please click the link below to complete the request: <br/><a href="'.$link.'">'.$link.'</a><br/><br/>'.
     '<br/>'.
    'Regards,<br/>'.
    'Toyin Dawodu, MBA<br/>'.
    'Founder and Chief Relationship Officer';

    $clients = new xmlrpc_client("https://ze214.infusionsoft.com/api/xmlrpc");
    $clients->return_type = "phpvals";
    $clients->setSSLVerifyPeer(FALSE);
    ###Build a Key-Value Array to store a contact###
    $emailI = array(
    'contactList' => $contactID,
    'fromAddress' => $From,
    'toAddress' => $email,
    'ccAddresses' => 'admin@gicdealfinders.info',
    'bccAddresses' =>'abhilashrajr.s@gmail.com',
    'contentType' => 'HTML',
    'subject' => $Subject,
    'htmlBody' => $htmlBody,
    'textBody' => 'test');
    //$check=$myApp->sendEmail($clist,"Test@test.com","~Contact.Email~", "","","Text","Test Subject","","This is the body");

    ###Set up the call###
        $calls = new xmlrpcmsg("APIEmailService.sendEmail", array(
        php_xmlrpc_encode($this->infusion_api),         #The encrypted API key
        php_xmlrpc_encode($emailI)      #The contact array

        ));

        ###Send the call###
        $results = $clients->send($calls);
        //$conID = $results->value();
        /*###Check the returned value to see if it was successful and set it to a variable/display the results###*/
        if(!$results->faultCode()) {
            return true;
            } else {
                print $results->faultCode() . "<BR>";
                print $results->faultString() . "<BR>";
            return false;
            }

The captured error shows:

-1
No method matching arguments: java.lang.String, java.util.HashMap

Can anyone check my code and show me a way to fix it?

gre_gor
  • 6,669
  • 9
  • 47
  • 52

1 Answers1

0

As the returned error says, the wrong parameters are sent to Infusionsoft API.

The list of acceptable parameters is provided in Infusionsoft API documentation.

First of all, you need to add your API key as the first value in $emailI array.

Also, Infusionsoft API expects the second parameter to be a list of Contact IDs, which means the second parameter $contactID must be sent from php side as an array.

The following code shows the fixes:

$emailI = array(
    'yourApiKey',
    array($contactID),
    $From,
    $email,
    'admin@gicdealfinders.info',
    'abhilashrajr.s@gmail.com',
    'HTML',
    $Subject,
    $htmlBody,
    'test'
);
$calls = new xmlrpcmsg(
    "APIEmailService.sendEmail",
     array_map('php_xmlrpc_encode', $emailI)
);

Please also notice, that if you have more then just one or two Infusionsoft API calls in your code, it's advisable to use API Helper Libraries. Also you may find another wrappers for Infusionsoft API at github.com if current official Helper Libraries don't work for you.

Y. E.
  • 687
  • 1
  • 10
  • 29
  • ###Set up the call### $calls = new xmlrpcmsg("APIEmailService.sendEmail", array( php_xmlrpc_encode($this->infusion_api), #The encrypted API key php_xmlrpc_encode($emailI) #The contact array )); in my code php_xmlrpc_encode($this->infusion_api) store the api key – ABGIC DEVELOPER Jun 18 '16 at 18:04
  • Yes, I saw it. My answer fixes your issues. Use your $this->infusion_api in place of 'yourApiKey' – Y. E. Jun 19 '16 at 11:05
  • i will check with it and let you know – ABGIC DEVELOPER Jun 19 '16 at 18:17
  • Did you have a chance to take a look into the answer? Thanks! – Y. E. Jun 28 '16 at 13:48