REST
Two public endpoints, both on api.iapguard.com. Use them directly, or through one of the SDKs.
| Endpoint | Path | Method |
|---|---|---|
| Validate Receipt | /v1/receipt/{appid} | POST |
| Get User | /v1/user/{appid}/{userid} | GET |
{appid} is the application identifier from App Setup.
Validate Receipt
Send a receipt to be checked against the store. Only a successful, new purchase increases your transaction count — a failed check or a restore costs nothing. See Errors for what can come back.
Do not send every receipt the user owns on each app launch. Those requests come back as duplicates. Validate during or straight after the purchase flow, and for transactions still pending.
Request
JSON encoded values in request body.
| Field | Description |
|---|---|
store | The originating App Store. GooglePlay, AppleAppStore or PayPal |
bid | Your application bundle identifier as displayed on the App Store. Not validated on PayPal. |
pid | The product identifier that was purchased, as displayed on the App Store. On PayPal for reference only. |
type | Product type. Consumable, Non-Consumable or Subscription. This is required as we do not store or read your App Store IAP data. Note: on Apple, non-renewing subscriptions should use the type Non-Consumable. |
user | Optional. User ID uniquely identifying the currently authenticated user in your application. See User Storage. |
receipt | App Store-generated unique transaction identifier. |
Response
Success: HTTP Status 200.
Failed: HTTP Status 400 (see Errors).
| Field | Description |
|---|---|
store | The originating App Store. GooglePlay, AppleAppStore or PayPal |
user | The client-provided or server generated user identifier. |
transaction | App Store-generated unique transaction identifier. Can be different to the request, if there is an updated transaction available. |
data (object) | Receipt data of the accountable purchase. Please see below for a separate listing. |
| Data Field | Description |
|---|---|
status | Subscription only. 0: active, 1: cancelled, 2: expired, 3: billing retry period, 4: billing grace period, 5: revoked/refunded, 6: paused (Google Play) |
type | Product type. Consumable, Non-Consumable or Auto-Renewable Subscription. |
expiresDate | Subscription only. UNIX time in milliseconds when the subscription expires or renews. |
autoRenew | Subscription only. true or false. false when expired or cancelled. |
cancelReason | Subscription only. Not always present, except on status = 1. 0: User canceled, 1: canceled by system, i.e. test cycle ends or on billing errors, 2: replaced (Google Play), 3: canceled by developer (Google Play), 4: declined price increase (Apple), 5: product unavailable at renewal (Apple) |
billingRetry | Subscription only. true or false. true when billing is attempting to renew an expired subscription. |
productId | The product identifier that was purchased, as displayed on the App Store. On PayPal for reference only. |
groupId | Subscription only. Apple only. Group identifier the subscription belongs to. |
sandbox | true: Sandbox environment, false: Production environment |
Example
- PHP
- NodeJS
- C#
//IAPGUARD endpoint URL
$url = 'https://api.iapguard.com/v1/receipt/yourapplicationid';
//Request content
$data = json_encode(array(
"store" => "GooglePlay",
"bid" => "com.flobuk.SimpleIAPSystem",
"pid" => "coins",
"type" => "Consumable",
"user" => "userX",
"receipt" => "ihmndabonhehhfcbiiakbnmp..."));
//Initialize CURL session
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Execute Request
$result = curl_exec($ch);
//Close CURL session
curl_close($ch);
//Print Request result
print_r ($result);
//IAPGUARD endpoint URL
const https = require("https");
const url = "https://api.iapguard.com/v1/receipt/yourapplicationid";
//Request content
var data = JSON.stringify({
'store' : 'GooglePlay',
'bid' : 'com.flobuk.SimpleIAPSystem',
'pid' : 'coins',
'type' : 'Consumable',
'user' : 'userX',
'receipt' : 'ihmndabonhehhfcbiiakbnmp...'
});
var options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
};
//Initialize Request session
var req = https.request(url, options, (resp) => {
let data = "";
//Received chunk of data
resp.on("data", (chunk) => {
data += chunk;
});
//Received response result, print out
resp.on("end", () => {
console.log(data);
});
})
.on("error", (err) => {
console.log("Error: " + err.message);
});
//Execute Request
req.write(data);
req.end();
using System;
using System.Net;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Text.Json;
//IAPGUARD endpoint URL
var url = new Uri("https://api.iapguard.com/v1/receipt/yourapplicationid");
//Request content
Dictionary<string,string> postData = new Dictionary<string,string>();
postData.Add("store","GooglePlay");
postData.Add("bid","com.flobuk.SimpleIAPSystem");
postData.Add("pid","coins");
postData.Add("type","Consumable");
postData.Add("user","userX");
postData.Add("receipt","ihmndabonhehhfcbiiakbnmp...");
string data = JsonSerializer.Serialize(postData);
//Initialize Request session
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.UserAgent = ".NET Framework";
request.ContentType = "application/json";
request.ContentLength = data.Length;
//Execute Request
StreamWriter streamWriter = new StreamWriter(request.GetRequestStream());
streamWriter.Write(data);
streamWriter.Flush();
streamWriter.Close();
//Read response from stream
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
//Received response result, print out
Console.WriteLine (readStream.ReadToEnd ());
response.Close();
readStream.Close();
Get User
Call this function from a client to retrieve all of its current and most recent in-app purchases. For subscription products, only the most recent transaction and status is returned. Note that this method not only returns active, but also expired / on hold / cancelled subscriptions, allowing you to reactively give users more information or incentive to resubscribe. Always check the product status before granting it.
Do not try to request the user's inventory too often, e.g. every time the user enters your shop, or every few minutes. This will cause bandwidth overhead and failed requests. Instead, cache your user's inventory in memory for the session duration, at least minimizing calls down to one request per application launch.
If you expect your application to be opened frequently over the course of a day, even try to minimize calls down to one request per day using an internal timer and cache the user's inventory locally. If users do not have a purchase registered locally, usually an inventory request would not return any results either, so in this case it could be skipped too.
Also there is no need to request the user inventory following a receipt validation request. Simply add the successful purchase response to your local user inventory for the current session.
Request
This endpoint does not have any required input parameters.
Response
| Field | Description |
|---|---|
purchases | Array of purchase data objects in the user's inventory. For details please see the data object in the validation response. |
expiresDate | Optional. Only returned for existing users. UNIX time in milliseconds when the record expires. |
Example
- PHP
- NodeJS
- C#
//IAPGUARD endpoint URL
$url = 'https://api.iapguard.com/v1/user/yourapplicationid/userX';
//Initialize CURL session
$ch = curl_init($url);
//Execute Request
curl_exec($ch);
//Close CURL session
curl_close($ch);
//IAPGUARD endpoint URL
const https = require("https");
const url = "https://api.iapguard.com/v1/user/yourapplicationid/userX";
//Initialize Request session
https.get(url, (resp) => {
let data = "";
//Received chunk of data
resp.on("data", (chunk) => {
data += chunk;
});
//Received response result, print out
resp.on("end", () => {
console.log(data);
});
})
.on("error", (err) => {
console.log("Error: " + err.message);
});
using System;
using System.Net;
using System.Text;
using System.IO;
//IAPGUARD endpoint URL
var url = new Uri("https://api.iapguard.com/v1/user/yourapplicationid/userX");
//Initialize Request session
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = ".NET Framework";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Read response from stream
Stream receiveStream = response.GetResponseStream ();
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
//Received response result, print out
Console.WriteLine (readStream.ReadToEnd ());
response.Close();
readStream.Close();