SolvedPrivate

API help

Posted on 2013-06-05
21
75 Views
Last Modified: 2013-06-06
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
0
Comment
Question by:lvollmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 6
  • 2
  • +1
21 Comments
 

Author Comment

by:lvollmer
ID: 39223652
it should be noted that add_to_list.php has mostly junk code I was testing in it.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39224410
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
 

Author Comment

by:lvollmer
ID: 39224459
Thanks, Ray. When I get to my machine I will do that.
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 16

Expert Comment

by:Rose Babu
ID: 39225756
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
 

Author Comment

by:lvollmer
ID: 39225879
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
 

Author Comment

by:lvollmer
ID: 39225913
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
 

Author Comment

by:lvollmer
ID: 39226387
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39226397
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
 

Author Comment

by:lvollmer
ID: 39226417
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39226613
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
 

Author Comment

by:lvollmer
ID: 39226637
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39226661
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
 

Author Comment

by:lvollmer
ID: 39226708
haha, good point.
0
 

Author Comment

by:lvollmer
ID: 39227058
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
 
LVL 34

Accepted Solution

by:
Slick812 earned 400 total points
ID: 39227181
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
 

Author Comment

by:lvollmer
ID: 39227293
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
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39227380
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
 

Author Comment

by:lvollmer
ID: 39227428
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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39227497
Great!  Best of luck with it, ~Ray
0
 
LVL 34

Expert Comment

by:Slick812
ID: 39227708
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
 

Author Comment

by:lvollmer
ID: 39227786
Slick - that is the plan. I need a lot more practice.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question