Larry Vollmer
asked on
API help
I am pretty new to OOP and have never used an API, and am tasked with doing so right now. If someone could point me in the right direction or help me out, I would greatly appreciate it.
I am working with a third party provider to manage email lists. I want to create a page where the user enters their email address, and it gets sent to a specific email list. The third party provider does not have any prebuilt widgets to accomplish this, so they have sent me some API files to accomplish this.
1) I edit the config file appropriately (it is attached)
2) create 2 basic pages - 1 where the user enters the email address and one where it is captured. (subscribe.php, add_to_list.php - attached)
3) There is a function called SubscribeToList() in WebService.php (attached) that I need to somehow invoke. I am stuck here. I don't know how to use this function so that the email data is sent to the third party provider. Can anyone help me out?
Archive.zip
I am working with a third party provider to manage email lists. I want to create a page where the user enters their email address, and it gets sent to a specific email list. The third party provider does not have any prebuilt widgets to accomplish this, so they have sent me some API files to accomplish this.
1) I edit the config file appropriately (it is attached)
2) create 2 basic pages - 1 where the user enters the email address and one where it is captured. (subscribe.php, add_to_list.php - attached)
3) There is a function called SubscribeToList() in WebService.php (attached) that I need to somehow invoke. I am stuck here. I don't know how to use this function so that the email data is sent to the third party provider. Can anyone help me out?
Archive.zip
Please post the associated files in clear text using the "code" snippet feature. I am not comfortable using ZIP files in an internet forum. Nothing personal - just better safe than sorry. When you post these, please remove the junk code and reduce the question to the SSCCE. We will be glad to help, ~Ray
ASKER
Thanks, Ray. When I get to my machine I will do that.
can you the add_to_list.php file with the below code and test it once?
<?php
$listID = "2207";
$recipientID = $_POST ["email"];
$confirmed = "Yes";
$sourceID = "web";
$mailingID = $_POST ["email"];
include_once "WebService.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>API Test</title>
</head>
<body id="index" class="home">
<?php
$soap = new WebService();
$respResult = $soap->SubscribeToList($listID, $recipientID, $confirmed, $sourceID, $mailingID);
print_r ( $respResult );
?>
</body>
</html>
ASKER
Fatal error: Uncaught SoapFault exception: [S:Server] java.rmi.RemoteException: RecipID is a required field in /homepages/36/d130859598/htdocs/hp/sp/WebService.php:29 Stack trace: #0 /homepages/36/d130859598/htdocs/hp/sp/WebService.php(29): SoapClient->__call('SubscribeToList', Array) #1 /homepages/36/d130859598/htdocs/hp/sp/WebService.php(116): WebService->__call('SubscribeToList', Array) #2 /homepages/36/d130859598/htdocs/hp/sp/WebService.php(116): SoapClient->SubscribeToList(Array) #3 /homepages/36/d130859598/htdocs/hp/sp/add_to_list.php(22): WebService->SubscribeToList('2207', 'lorem@ipsum.com', 'Yes', 'web', 'lorem1@ipsum.co...') #4 {main} thrown in /homepages/36/d130859598/htdocs/hp/sp/WebService.php on line 29
ASKER
Ray - here are the files:
at this point, i'd just like to connect to the API and make sure the data is sent over, so add_to_list.php is just using hard coded testing variables.
I've omitted the config file, it just contains user/pass info and the SOAP url for connecting. I've confirmed all of that info is correct.
add-to-list.php
entities.php
main.php
WebService.php
at this point, i'd just like to connect to the API and make sure the data is sent over, so add_to_list.php is just using hard coded testing variables.
I've omitted the config file, it just contains user/pass info and the SOAP url for connecting. I've confirmed all of that info is correct.
add-to-list.php
entities.php
main.php
WebService.php
ASKER
If I am understanding that error correctly, it looks like it wants to have a RecipID before it can write any data. I am trying to implement that.
Wow, I don't know what to make of that. Is that the absolute minimum SSCCE you can provide that demonstrates the problem? I wouldn't even know where to start looking, sorry.
ASKER
Yeah - that is all they sent me and gave me a "good luck". I did just receive some documentation, which I have attached.
It would have been nice to have this yesterday.
PulsePoint-Data-Integration-Over.pdf
It would have been nice to have this yesterday.
PulsePoint-Data-Integration-Over.pdf
Sigh. Their web site is pretty opaque, too. It looks like they do not have a users-group or forum, except behind a password-protected page. Have the PulsePoint tech support reps been unable to help you at all?
ASKER
They keep pushing towards building it themselves for a fee, and I'd rather build it myself if possible. They aren't very helpful. Seems like it shouldn't be a daunting task, and I can't believe a company that manages email lists doesn't have some pre built widget that allows a user to simply sign up to a list.
Of course they have a pre-built widget. They could never have tested the platform without an automated testing mechanism. But their widget might be written in Java or VB, and so it would be inapplicable to a PHP requirement.
ASKER
haha, good point.
ASKER
Perhaps I have made some progress. I need to research this latest error. According to the documentation I need to use the createRecipient function before I can assign a recipient to a list.
here are those two functions:
Here is my code:
I am hardcoding the values until I get the script working. Easier to test.
And here is the error I get:
I am trying to research what this means.
here are those two functions:
/* @createRecipient
* parameters:
* <xs:element name="recipient" type="tns:Recipient" minOccurs="0" />
* return:
* <xs:element name="return" type="xs:int" />
* */
function createRecipient(Recipient $recipient)
{
$result =parent::createRecipient(array(
"recipient" => $recipient
));
return $result;
}
/* @SubscribeToList
* parameters:
* <xs:element name="listID" type="xs:int" />
* <xs:element name="recipID" type="xs:int" />
* <xs:element name="confirmed" type="xs:boolean" />
* <xs:element name="sourceID" type="xs:string" minOccurs="0" />
* <xs:element name="mailingID" type="xs:int" />
* return:none
*/
function SubscribeToList($listID, $recipientID, $confirmed, $sourceID, $mailingID)
{
$result =parent::SubscribeToList(array(
"listID" => $listID,
"recipID" => $recipientID,
"confirmed" => $confirmed,
"sourceID" => $sourceID,
"mailingID" => $mailingID
));
return $result;
}
Here is my code:
<?php
include_once "WebService.php";
$listID = "2207";
$recipient ="lorem@ipsum.com";
$recipientID ="lorem@ipsum.com";
$confirmed = "Yes";
$sourceID = "web";
$mailingID = "lorem@ipsum.com";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>API Test</title>
</head>
<body id="index" class="home">
<?php
$soap = new WebService();
echo '<tt><pre>'. var_export($soap, TRUE) . '</pre></tt>';
$soap->createRecipient($recipient);
$soap->SubscribeToList($listID, $recipientID, $confirmed, $sourceID, $mailingID);
?>
</body>
</html>
I am hardcoding the values until I get the script working. Easier to test.
And here is the error I get:
Catchable fatal error: Argument 1 passed to WebService::createRecipient() must be an instance of Recipient, string given, called in /homepages/36/d130859598/htdocs/hp/sp/add_to_list.php on line 23 and defined in /homepages/36/d130859598/htdocs/hp/sp/WebService.php on line 74
I am trying to research what this means.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This file did not make a lot of sense to me at first, but since I have spent the last two days attempting to learn some OOP, it makes more sense to me now.
I can successfully create a recipient ID now, but cannot instantantiate (i hope that is correct terminology) the SubscribeToList() function afterwards. Here is what I have:
Any tips or hints on what I may be doing wrong, or how I can get SubscribeToList() function to execute?
I can successfully create a recipient ID now, but cannot instantantiate (i hope that is correct terminology) the SubscribeToList() function afterwards. Here is what I have:
$soap = new WebService();
$recipient = new Recipient();
$address = "lorem@ipsum.com";
$externalID = "lorem@ipsum.com";
$sourceDescription = "FinalTestingViaPhp";
$recipient->address = $address;
$recipient->sourceDescription = $sourceDescription;
$recipient->externalID = $externalID;
$result = $soap->createRecipient($recipient);
echo "Recipient Created. RecipientID of created recipient is " . $result . "<br />";
return $result;
// This code does not run
$list = "2278";
$result = $id;
$soap = new WebService();
$soap->SubscribeToList($list, $id, null, null, null);
echo "Subscribed recipient with recipientID" . $id . " to the list" . $list . "<br />";
Any tips or hints on what I may be doing wrong, or how I can get SubscribeToList() function to execute?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Figured it out. I just needed to use the functions in the php file itself. At least it was a learning experience! Splitting points for all that helped.
Great! Best of luck with it, ~Ray
You may need to spend some time with PHP OO code that does NOT relate to this API you are trying to do here, because there are differences in putting together (compounding) coding practices in Object code that are different than in function code. There are many new things to keep in mind when turning to Object Code, that you never heard of in function code. You can not just read about it, as you saw here, you have to do and re-do and re-do code untill you get a working understanding. All who start in OO code have this same problem, so just keep trying other OO stuff..
If you look in the "entities.php" you see classes like -
class Recipient{
this class without-FUNCTIONS is the same as a PHP ARRAY, except you use the -> instead of the [ ] to use properties like recipID
If you look in the "entities.php" you see classes like -
class Recipient{
this class without-FUNCTIONS is the same as a PHP ARRAY, except you use the -> instead of the [ ] to use properties like recipID
ASKER
Slick - that is the plan. I need a lot more practice.
ASKER