Professional Documents
Culture Documents
MailAgent Web Services are used as a web standard compliant mode of interacting
with the client websites. Using these Web Services, the clients are able, directly from their
websites, to trigger remote actions on the MailAgent Systems. Specifically, the client can:
1.
Notify MailAgent about its users actions: subscription / unsubscriptions,
demographic data changes etc
2.
Query MailAgent's database about its users status and data
3.
Send e-mails (infrastructure or newsletters)
4.
Start / stop newsletters
There are two Web-Services available: two interfaces which serve the same purpose.
They are two flavoures of the same product.
One is a SOAP WSDL-based service, the other one is a XML-RPC service. We will
show both examples along the way.
For documentation purposes, we will classify the web service's methods into the
folowing categories:
1.
Referring to subscribers: addSubscriber, validateSubscriber, querySubscriber,
editSubscriber
2.
Referring to
subscriptions:
addSubscription,
validateSubscription,
invalidateSubscription, deleteSubscription, querySubscription
3.
Referring to newsletters: getNewNewsletters, setNewsletterStatus
4.
Referring to messages: sendMessage, sendMessageGroupByDay
The methods always respond with one array (dictionary, Hashmap) with these keys:
op_status (check the table at the end of the document; always 0 if ok)
op_message (description message of the error if any)
results (additional method results. If present, always array)
Throughout the document we will name this type TWSResponse.
The methods description follows.
All the XML-RPC examples will be using our PHP distributable library (NWGClient)
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
=> "projectcode",
"campaign_id"
=> 49,
"email"
=> "user@example.com",
"demographics"
=> array(
"prenume" => "Mihai",
"nume" => "Georgescu"
)
);
$client = new NWGClient();
try{
$response = $client->addSubscriber( $params );
} catch ( Exception $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
validateSubscriber
Description: Adds a new subscriber to a project's campaign, but with validation
through a sent email. The client can specify demographics for this user. An error is raised if
the subscriber is already registered to this campaign. If the user already has those
demographics, they are not updated (see editSubscriber for editing)
Parameters: cod, campaign_id, email, [vars], [demographics]
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->validateSubscriber( "projectcode", 49,
"user@example.com",
array(
"username" => "mihaigeorgescu"
),
array(
"prenume" => "Mihai",
"nume" => "Georgescu"
)
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
"vars"
"demographics"
=>
=>
=>
=>
"projectcode",
49,
"user@example.com",
array(
"username" => "mihaigeorgescu"
),
=> array(
"prenume" => "Mihai",
"nume" => "Georgescu"
)
);
$client = new NWGClient();
try{
$response = $client->validateSubscriber( $params );
} catch ( Exception $e )
{
querySubscriber
Description: Returns the details of a subscriber to a campaign. If the subscriber is
valid (it is a subscriber to this campaign), the method also returns the bounce and spam status
of this subscriber.
Parameters: cod, campaign_id, email
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->querySubscriber( "projectcode", 49,
"user@example.com"
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
echo "User details: " . print_r( $response['results'], 1 ) . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
);
=> "projectcode",
=> 49,
=> "user@example.com",
editSubscriber
Description: Edits a subscribers demographics.
Parameters: cod, email, demographics
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->editSubscriber( "projectcode",
"user@example.com",
array(
"prenume" => "Marius",
"nume" => "Popescu"
)
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"email"
"demographics"
=> "projectcode",
=> "user@example.com",
=> array(
"prenume" => "Marius",
"nume" => "Popescu"
)
);
$client = new NWGClient();
try{
$response = $client->editSubscriber( $params );
} catch ( Exception $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
);
=> "projectcode",
=> 18,
=> "user@example.com"
validateSubscription
Description: Adds a new subscription to a project's campaign for an already existing
project subscriber (to another campaign), but with email validation.
Parameters: cod, campaign_id, email, [vars]
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->validateSubscription( "projectcode", 18,
"user@example.com",
array(
"username" => "mihaigeorgescu"
)
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
"vars"
=> "projectcode",
=> 18,
=> "user@example.com",
=> array(
"username" => "mihaigeorgescu"
)
);
$client = new NWGClient();
try{
$response = $client->validateSubscription( $params );
} catch ( Exception $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
invalidateSubscription
Description: Removes a subscribers subscription to a campaign, but with email
validation.
Parameters: cod, campaign_id, email, [vars]
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->invalidateSubscription( "projectcode", 18,
"user@example.com",
array(
"username" => "mihaigeorgescu"
)
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
"vars"
=>
=>
=>
=>
"projectcode",
18,
"user@example.com",
array(
"username" => "mihaigeorgescu"
)
);
$client = new NWGClient();
try{
$response = $client->invalidateSubscription( $params );
} catch ( Exception $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
deleteSubscription
Description: Removes a subscribers subscription to a campaign
Parameters: cod, campaign_id, email
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->deleteSubscription( "projectcode", 18,
"user@example.com"
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
);
=> "projectcode",
=> 18,
=> "user@example.com"
querySubscription
Description: Returns the details of a subscriber to a campaign.
Parameters: cod, campaign_id, email
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->querySubscription( "projectcode", 18,
"user@example.com"
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"email"
);
=> "projectcode",
=> 18,
=> "user@example.com"
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"subject"
);
=> "projectcode",
=> 18,
=> "A direct newsletter subject"
setNewsletterStatus
Description: Updateaza statusul unui newsletter direct.
Parameters: cod, newsletter, newstatus
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->setNewsletterStatus( "projectcode",
827, 2 );
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
if ( $response['op_status'] == 0 )
echo "Status updated OK for newsletter: " .
$response['results']['newsletter'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"newsletter"
"newstatus"
);
=> "projectcode",
=> 827,
=> 2
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"newsletter"
"to"
"vars"
=>
=>
=>
=>
"subscriber_id"
"projectcode",
142,
"user@example.com",
array(
"subject" => "Hello dear user",
"body" => "Please don't reply to this
message."
),
=> -1
);
$client = new NWGClient();
try{
$response = $client->sendMessage( $params );
} catch ( Exception $e )
{
die( "Exception: " . $e->getMessage() );
}
sendMessageGroupByDay
Description: Sends an email message to an unique/day newsletter for a direct
campaign.
Parameters: cod, campaign_id, [to], [vars], [subscriber_id]
Response: TWSResponse
Examples
SOAP
$client = new SoapClient(
"http://www.mailagent.ro/MailAgentService.wsdl");
try{
$response = $client->sendMessageGroupByDay("projectcode",
232,
"user@example.com",
array( "subject" => "Hello dear user",
"body" => "Please don't reply to this
message."
), -1
);
} catch ( SoapFault $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
XML-RPC
require_once( "nw.genericclient.php");
$params = array(
"cod"
"campaign_id"
"to"
"vars"
=>
=>
=>
=>
"subscriber_id"
"projectcode",
232,
"user@example.com",
array(
"subject" => "Hello dear user",
"body" => "Please don't reply to this
message."
),
=> -1
);
$client = new NWGClient();
try{
$response = $client->sendMessageGroupByDay( $params );
} catch ( Exception $e )
{
die( "Exception: " . $e->getMessage() );
}
echo "Exit code: " . $response['op_status'] . "\n";
echo "Response message: " . $response['op_message'] . "\n";
Error codes
0
100
101
102
103
201
202
203
204
205
210
301
302
303
304
305
401
402
500
5xx
601
701
702
703
801
802
803
804
1001
1002