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
lvollmerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lvollmerAuthor Commented:
it should be noted that add_to_list.php has mostly junk code I was testing in it.
0
Ray PaseurCommented:
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
0
lvollmerAuthor Commented:
Thanks, Ray. When I get to my machine I will do that.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Rose BabuSenior Team ManagerCommented:
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>

Open in new window

0
lvollmerAuthor Commented:
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

Open in new window

0
lvollmerAuthor Commented:
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
0
lvollmerAuthor Commented:
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.
0
Ray PaseurCommented:
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.
0
lvollmerAuthor Commented:
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
0
Ray PaseurCommented:
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?
0
lvollmerAuthor Commented:
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.
0
Ray PaseurCommented:
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.
0
lvollmerAuthor Commented:
haha, good point.
0
lvollmerAuthor Commented:
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:
    /* @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;

    }

Open in new window


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>

Open in new window


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

Open in new window


I am trying to research what this means.
0
Slick812Commented:
hello, , you do not seem to refer to the "Sample" code for beginners in the "main.php" file, the Sample code there is this -

function createRecipientTest()
{
    $soap = new WebService();
    $recipient = new Recipient(); // you need to create a recipient object first

    $address = "test186@yahoo.com";  // you need to change these to the specific web addys need for YOU
    $externalID = "test186@yahoo.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;

}

Open in new window


this is all PHP OO, you might try and look more at the samples in the "main.php" file,
I may not have the time to try and walk you through this, but may can offer some suggestions to help,

your code line of -
$soap->createRecipient($recipient);

is INCORRECT
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lvollmerAuthor Commented:
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:




	$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 />";

Open in new window


Any tips or hints on what I may be doing wrong, or how I can get SubscribeToList() function to execute?
0
Ray PaseurCommented:
Instantiate is a term of art.  It means "make an object from a Class definition."  The object is said to be an instance of the class, hence the term.
0
lvollmerAuthor Commented:
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.
0
Ray PaseurCommented:
Great!  Best of luck with it, ~Ray
0
Slick812Commented:
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
0
lvollmerAuthor Commented:
Slick - that is the plan. I need a lot more practice.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.