API Examples
Documentation
API v1.0.2
Hello World!
These snippets are meant to demonstrate connecting to the API and reading a response (using
the HelloWorld() method).
Specific code samples are available in the documentation.
MnbApi.class.php
require_once 'MnbApi.class.php'; $api_key = 'XXXXXX'; $mnb = new MnbApi($api_key); $resp = $mnb->HelloWorld('Hello, World!'); if ($mnb->hasError()) { echo "ERROR!:\n" . " Error #: " . $mnb->getErrorCode() . "\n" . " Error Msg: " . $mnb->getErrorMessage() . "\n"; } else echo "Response: $resp\n";
XML-RPC
This example uses PHPXMLRPC,
though you can obviously use any XML-RPC client you wish.
require_once 'xmlrpc.inc'; $api_key = 'XXXXXX'; $m = new xmlrpcmsg('HelloWorld', array(new xmlrpcval($api_key), new xmlrpcval('Hello, World!') )); $c = new xmlrpc_client("/1.0.2/", "api.mynewsletterbuilder.com", 80); $c->return_type = "phpvals"; $r = $c->send($m); if (!$r->faultCode()) echo "Response: " . $r->value(); else { echo "Fault:\n" . " Code: " . htmlentities($r->faultCode()) . "\n" . " Message: " . htmlentities($r->faultString()) . "\n"; }
XML_RPC2
require_once 'XML/RPC2/Client.php'; $api_key = 'XXXXXX'; $options = array(); $client = XML_RPC2_Client::create('http://api.mynewsletterbuilder.com/1.0.2/', $options); try { $result = $client->HelloWorld($api_key, 'Hello, World!'); echo "Response: " . $result; } catch (XML_RPC2_FaultException $e) { // The XMLRPC server returns a XMLRPC error die('Exception #' . $e->getFaultCode() . ' : ' . $e->getFaultString()); } catch (Exception $e) { // Other errors (HTTP or networking problems...) die('Exception : ' . $e->getMessage()); }
HTTP GET / POST
You can use whatever method you like to retrieve the appropriate API URL. We
recommend using cURL
or sockets.This will invoke "HelloWorld" with a JSON response.
http://api.mynewsletterbuilder.com/1.0.2/HelloWorld/json/?api_key=XXXXXX&val=Hello%2C%20World!