NAV

Resource Balance(Last Updated : 01/04/2017)

An account has several different resources such as credits, keywords, and users. You will be able to get the current balance for those resources. For now, you are able to obtain the domestic and international credit count. We will later enhance this method to provide balances for other resources.

Methods

GET /rest/v1/{user_name}/balance/credit

GET Credit Balance

Lookup the domestic and international credit balance of the account.

Resource Information

Response Formats JSON
Allowed Methods GET
URL http://api.trumpia.com/rest/v1/{user_name}/balance/credit
{user_name} Your account username (this can be found in the Account Settings page after logging in.)

Header Parameters

* required parameters
Parameter Description
Content-Type * application/json
X-Apikey * Your API key (This can be found in the API Settings page after logging in.)

Example value: 123456789abc1011

Code sample for GET Credit Balance

"Request Example:
GET http://api.trumpia.com/rest/v1/{user_name}/balance/credit"

"Response Example:"
{
  "status_code" : "MPCE0000",
  "domestic_credit" : 1000,
  "international_credit" : 100
}


<?
	// GET Credit Balance - Retrieve all distribution lists.
	include "request_rest.php";

	$request_url = "http://api.trumpia.com/rest/v1/{user_name}/balance/credit";

	$request_rest = new RestRequest();

	$request_rest->setRequestURL($request_url);
	$request_rest->setAPIKey("{api_key}");
	$request_rest->setMethod("GET");
	$result = $request_rest->execute();

	$response_status = $result[0];
	$json_response_data = $result[1];

	if ($response_status == "200") {	//success
		echo $json_response_data;
	} else {
		echo $response_status ." - connection failure";
	}
?>


// GET Credit Balance - Retrieve all distribution lists.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.json.simple.JSONArray" %>
<%@ page import="org.json.simple.JSONObject" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.io.Writer" %>
<%@ page import="java.net.HttpURLConnection" %>
<%@ page import="java.net.URL" %>
<html>
<title>Resource Balance Get Sample Code</title>
<body>

<%
	String username = "username";
	String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/balance/credit";

	URL url = new URL(urlStr);
	HttpURLConnection conn = (HttpURLConnection) url.openConnection();
	conn.setRequestProperty("Content-type", "application/json");
	conn.setRequestProperty("X-Apikey", "12345aaaaa67890aaaaa");

	if (conn.getResponseCode() != 200) {
%>
	Error : <%=conn.getResponseMessage()%>
<%
	}else{
	// Buffer the result into a string
	BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
	StringBuilder sb = new StringBuilder();
	String line;
	while ((line = rd.readLine()) != null) {
		sb.append(line);
	}
	rd.close();
	conn.disconnect();
%>
	Response : <%=sb.toString()%>
<%
	}
%>
</body>
</html>


// GET Credit Balance - Retrieve all distribution lists.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace samplecode
{
    class ResourceBalanceInfo
    {
        public string status_code { get; set; }
        public string domestic_credit { get; set; }
        public string international_credit { get; set; }
    }
    class ResourceBalanceDetailGet
    {
        static void Main()
        {
            RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                var apikey = "12345aaaaa67890aaaaa";

                client.BaseAddress = new Uri("http://api.trumpia.com");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("X-Apikey", string.Format("{0}", apikey));

                var username = "username";

                //GET
                HttpResponseMessage response = await client.GetAsync(string.Format("/rest/v1/{0}/balance/credit", username));
                if (response.IsSuccessStatusCode)
                {
                    ResourceBalanceInfo resourceBalanceInfo = await response.Content.ReadAsAsync<ResourceBalanceInfo>();
                    string json = JsonConvert.SerializeObject(resourceBalanceInfo);
                    Console.WriteLine(json);
                }
            }
        }
    }
}