API Integration osclass

1.3k views Asked by At

I have found a few people looking for solutions to osclass which doesnt seem to be massively popular as far as plugins go so hope that my issue will help others too.

I have created an php API which integrates with Interspire Email Marketer (IEM).

When someone signs up to become an advertiser at an osclass site the following API contacts Interspire Email Marketers XML.PHP and adds the subscriber to the list.

I'm a little stuck as to what to add to the SUBMIT button of Osclass registration form. Heres the API:

<?PHP

// CHECK AUTHORIZATION
// -------------------------------------------------------------------------    -----
if ($MailingListAuth == true) {

/
// -------------------------------------------------------------------------    -----
$s_name = check_type('s_name');
$s_email = check_type('s_email');
// ------------------------------------------------------------------------------

$xml = '<xmlrequest>
<username>MyIEMUserName</username>
<usertoken>b331be663b16ae7atolkeiias9f7hgkg7ff2f1d</usertoken>
<requesttype>subscribers</requesttype>
<requestmethod>AddSubscriberToList</requestmethod>

<details>
<emailaddress>'.$s_email.'</emailaddress>
<mailinglist>2</mailinglist>
<format>html</format>
<confirmed>yes</confirmed>

<customfields>

<item>
<fieldid>2</fieldid>
<value>'.$s_name.'</value>
</item>

</customfields>

</details>
</xmlrequest>
';

$ch = curl_init('https://example.com/mail/xml.php'); //CHANGE TO THE PATH OF     YOUR IEM INSTALLATION
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$result = @curl_exec($ch);
if($result === false) {die("Error performing request");}
//var_dump($result); //for debugging purposes
//Example of how to display returned data
$xml_doc = simplexml_load_string($result);
if ($xml_doc->status == 'SUCCESS' && empty($xml_doc->data)) {die('Status is     success. Empty response.');}
if ($xml_doc->status == 'SUCCESS') {
    echo 'Response: <br />';
    var_dump($xml_doc->data);
} else {
    echo 'Error is '. $xml_doc->errormessage;
}

}

?>

Heres the osclass form button code

<button type="submit" class="ui-button ui-button-middle ui-button-main"><?    php _e("Create", 'bender'); ?></button>

I'm not sure how I call the API php page so that it gets sent to IEM and adds the subscriber.

1

There are 1 answers

2
CONEJO On

You have hooks and plugins, you could use the 'user_register_completed' hook

for example

function IEM_subscribe($userId) {
    $user = User::newInstance()->findByPrimaryKey($userId);
    //YOUR CODE HERE
    // user's email is in $user['s_email']
    // user's name is in $user['s_name']
}
osc_add_hook('user_register_completed', 'IEM_subscribe');

This function will be called AFTER the user is registered, is you want to called it before, use the 'pre_user_post' hook.