Difference between revisions of "NATS4 API"
m (→Authentication) |
|||
(12 intermediate revisions by 6 users not shown) | |||
Line 2: | Line 2: | ||
| show_api_admin_section = true | | show_api_admin_section = true | ||
}} | }} | ||
− | + | The NATS Admin API is accessible at http://<domain>/admin_api.php | |
+ | *Replace <domain> with your NATS install domain name. | ||
== Gaining Access to the Admin API == | == Gaining Access to the Admin API == | ||
− | In order to access NATS API your IP address must be in the | + | In order to access NATS API your IP address must be in the ADMIN_API_ALLOWED_IPS list. You can add or remove IP addresses to this list via the Configurations Admin under the "Security" tab. |
+ | |||
+ | If you're also using [[NATS4 Configuration Admin#Security|ADMIN_IPS]] to restrict access to your admin, you must also add the IP to that list, as this is also an admin page. | ||
== Authentication == | == Authentication == | ||
− | The NATS API uses HTTP Authentication where the username is the Affiliate username and the password is the Affiliate API key. To retrieve your API key simply select it from the login table of your NATS database or put in a support ticket and we can retrieve it for you. | + | The NATS API uses HTTP Authentication where the username is the Affiliate username and the password is the Affiliate API key. To retrieve your API key simply select it from the login table of your NATS database or put in a support ticket and we can retrieve it for you. If you do not have an API key, you can set one by going to the Affiliates Admin and clicking the icon labeled, "Change API Key". ''Please note that only full admin accounts are authorized to use the API and set an API key.'' |
+ | |||
+ | == Example == | ||
+ | The easiest way to use SOAP when using PHP is using the [http://sourceforge.net/projects/nusoap/ NuSOAP Toolkit]. Assuming you've downloaded the toolkit into a directory called nusoap, here is an example of how to connect: | ||
+ | |||
+ | <pre> | ||
+ | <? | ||
+ | require_once('nusoap/lib/nusoap.php'); | ||
+ | |||
+ | $url = 'http://nats.site.com/admin_api.php'; // change to be the domain of your NATS install | ||
+ | $username = 'NATSADMIN'; // your admin username | ||
+ | $apikey = '3385e1b470b0864e27a9b648da6c0692'; // your api key | ||
+ | |||
+ | $client = new nusoap_client($url.'?wsdl', true); | ||
+ | $client->setCredentials($username,$apikey); | ||
+ | // Check for an error | ||
+ | $err = $client->getError(); | ||
+ | if ($err) { | ||
+ | // Display the error | ||
+ | echo 'Constructor error' . $err . "\n"; | ||
+ | exit; // At this point, you know the call that follows will fail | ||
+ | |||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | To give a complete example of this, here's an example using the [[NATS4_API_Ping|ping]] function. This is how to call it: | ||
+ | <pre> | ||
+ | <? | ||
+ | require_once('nusoap/lib/nusoap.php'); | ||
+ | |||
+ | $url = 'http://nats.site.com/admin_api.php'; // change to be the domain of your NATS install | ||
+ | $username = 'NATSADMIN'; // your admin username | ||
+ | $apikey = '3385e1b470b0864e27a9b648da6c0692'; // your api key | ||
+ | |||
+ | $client = new nusoap_client($url.'?wsdl', true); | ||
+ | $client->setCredentials($username,$apikey); | ||
+ | // Check for an error | ||
+ | $err = $client->getError(); | ||
+ | if ($err) { | ||
+ | // Display the error | ||
+ | echo 'Constructor error' . $err . "\n"; | ||
+ | exit; // At this point, you know the call that follows will fail | ||
+ | |||
+ | } | ||
+ | $result = $client->call('ping', Array(), 'natsapiadmin_wsdl'); | ||
+ | var_dump($result); | ||
+ | </pre> | ||
+ | |||
+ | And this is the output: | ||
+ | <pre> | ||
+ | bool(true) | ||
+ | </pre> | ||
+ | |||
+ | [[Category:NATS4 API Articles]] |
Latest revision as of 17:21, 25 June 2014
The NATS Admin API is accessible at http://<domain>/admin_api.php
- Replace <domain> with your NATS install domain name.
Gaining Access to the Admin API
In order to access NATS API your IP address must be in the ADMIN_API_ALLOWED_IPS list. You can add or remove IP addresses to this list via the Configurations Admin under the "Security" tab.
If you're also using ADMIN_IPS to restrict access to your admin, you must also add the IP to that list, as this is also an admin page.
Authentication
The NATS API uses HTTP Authentication where the username is the Affiliate username and the password is the Affiliate API key. To retrieve your API key simply select it from the login table of your NATS database or put in a support ticket and we can retrieve it for you. If you do not have an API key, you can set one by going to the Affiliates Admin and clicking the icon labeled, "Change API Key". Please note that only full admin accounts are authorized to use the API and set an API key.
Example
The easiest way to use SOAP when using PHP is using the NuSOAP Toolkit. Assuming you've downloaded the toolkit into a directory called nusoap, here is an example of how to connect:
<? require_once('nusoap/lib/nusoap.php'); $url = 'http://nats.site.com/admin_api.php'; // change to be the domain of your NATS install $username = 'NATSADMIN'; // your admin username $apikey = '3385e1b470b0864e27a9b648da6c0692'; // your api key $client = new nusoap_client($url.'?wsdl', true); $client->setCredentials($username,$apikey); // Check for an error $err = $client->getError(); if ($err) { // Display the error echo 'Constructor error' . $err . "\n"; exit; // At this point, you know the call that follows will fail }
To give a complete example of this, here's an example using the ping function. This is how to call it:
<? require_once('nusoap/lib/nusoap.php'); $url = 'http://nats.site.com/admin_api.php'; // change to be the domain of your NATS install $username = 'NATSADMIN'; // your admin username $apikey = '3385e1b470b0864e27a9b648da6c0692'; // your api key $client = new nusoap_client($url.'?wsdl', true); $client->setCredentials($username,$apikey); // Check for an error $err = $client->getError(); if ($err) { // Display the error echo 'Constructor error' . $err . "\n"; exit; // At this point, you know the call that follows will fail } $result = $client->call('ping', Array(), 'natsapiadmin_wsdl'); var_dump($result);
And this is the output:
bool(true)