NATS4 REST API Overview

From TMM Wiki
Revision as of 16:29, 11 March 2015 by Tmmtobias0185 (talk | contribs)
Jump to navigationJump to search
NATS 4
Members Admin
The Members Admin
View Member Details
Add Member
MySQL Auth
Mod Authn DB
Multisite Access
Member Logging
Member Password Retrieval
OpenID Connect
Mod Auth OpenIDC
ID Numbers
SOAP API
API
API Best Practices
WSDL Cache
Add Affiliate
Add Member Note
Admin Get Adtools
Adtool Categories
Adtool Types
Affiliate Get Campaigns
Bulk Import Adtools
Caching
Decode Natscode
Expire Manual Member
Get Affiliate Campaigns
Get Affiliate Hit Data
Get Affiliate Loginids
Get Affiliate Nats Codes
Get Affiliate Payout
Get Affiliate Program Campaign List
Get_Affiliate_Program_Campaign_List
Get Member Details
Get Member Instant Upgrade String
Get Member Package Upgrade String
Get Member Token Rebuy String
Get Member Upsell String
Get Payment Data
Get Payvia Rule
Get Profit Loss Report
Ping
Record Member Login
Search Affiliate Info
Search Member Info
Send Email API Function
Set Affiliate Admin Settings
Set Affiliate Customs
Set Affiliate Defaults
Set Affiliate Information
Set Affiliate Settings
Set Member Details
Set Payment Status
Set Payvia Rule
REST API
API Overview
API Best Practices
REST API PATH UPDATES
Adtools
GET /adtools/admin
GET /adtools/categories
GET /adtools/types
POST /adtools/importdump
Affiliate
GET /affiliate/campaigns
GET /affiliate/hitdata
GET /affiliate/payout
GET /affiliate/searchinfo
POST /affiliate/addaffiliate
POST /affiliate/invoice
PATCH /affiliate/setadminsettings
PATCH /affiliate/setcustoms
PATCH /affiliate/setdefaults
PATCH /affiliate/setinformation
PATCH /affiliate/setpayviainfo
PATCH /affiliate/setsettings
PATCH /affiliate/status
Member
GET /member/authstring
GET /member/details
GET /member/searchinfo
GET /suggestedcanceloffers
PATCH /member/setdetails
PATCH /member/setexpiration
POST /member/addnote
POST /member/recordlogin
PUT /member/expiremanual
PATCH /member/forget
Option
GET /option/options
GET /option/rule
PATCH /option/rule
PATCH/option/text
POST /option/rule
Payments
GET /payments/getpayments
GET /payviarule
PATCH /payments/setstatus
PATCH /payviarule
Report
GET /profitlossreport
Get /transactionpayouts
GET /report/transaction
Service
GET /service/decodenatscode
GET /service/ping
POST /service/sendemail


The NATS Admin API is accessible at http://<domain>/api/v1/<endpoint>/<item>

  • Replace <domain> with your NATS install domain name.
  • Replace <endpoint> with the resource endpoint that you are trying to access
  • Some of the resources do not require <item> in the url and all of the urls will be specified in the documentation

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.

Allowed HTTP Request Methods

  • GET
  • POST
  • PUT
  • PATCH

Authentication

The NATS REST API uses HTTP Header Authentication. Each REST API request requires the Affiliate username and the Affiliate API key to be sent with the HTTP headers of the request. 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 Authentication

Authentication can be handled in various ways using different programming languages. Below are some complete example calls to the Ping endpoint with HTTP Header authentication.

PHP

<?php 
$url = 'http://domain/api/v1/ping
$curl = curl_init(); 
 
$headers = array( 
    'api_key: 44b5498dbcb481a0d00b404c0169af62', 
    'api_username: tmm1phrvezsbu' 
); 
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_URL, $url); 
                                                                                                                                                               
$resp = curl_exec($curl); 
//dumps an associative array representation of the json 
var_dump(json_decode($resp, true)); 
// Close request to clear up some resources 
curl_close($curl); 
?> 

Python

  • This example requires pip and the request library which can be installed via pip by: 'pip install requests'
import requests

url = 'http://domain/api/v1/ping'
headers = {
	'api_key': '44b5498dbcb481a0d00b404c0169af62',
	'api_username': 'tmm1phrvezsbu'
}
 params =  { 
        'payvia_type_id': 1, 
        'rule_type': 'enabled' 
 }
	
res = requests.get(url, params=params, headers=headers)
print res.json()

node.js

  • This example requires npm and the request module which can be installed via npm by: 'npm install request'
var request = require('request');
                          
var options = {           
    url: 'http://domain/api/v1/ping',
    method: 'GET',        
    json: true,           
    headers: {            
        'api_key': '44b5498dbcb481a0d00b404c0169af62',
        'api_username': 'tmm1phrvezsbu'
    }                     
};                        
                          
function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }                     
    else{                 
        console.log(body);                                                                                                                                     
    }                     
                          
}                         
                          
request(options, callback);

Curl

curl -X GET 'http://domain/api/v1/ping' -H "api_key: 44b5498dbcb481a0d00b404c0169af62" -H "api_username: tmm1phrvezsbu"

And this is the output:

true