import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class SendSMS {
	public static void main(String[] args) {
		RestClient tmClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);

		try {
			tmClient.sendSMS("Hello SMS World!", "447000000000", "SenderName", 72, "", "", null);
		} catch (RestClientException e) {
			e.printStackTrace();
		}
	}
}
import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class CheckBalance {
	public static void main(String[] args) {
		RestClient tmClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
		try {
			int creditsAvailable = tmClient.getCredits();
			System.out.println("Account have " + creditsAvailable + " credits.");
		} catch (RestClientException e) {
			e.printStackTrace();
		}
	}
}
import java.util.Hashtable;
import uk.co.textmarketer.RestAPI.DeliveryReport;
import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class DeliveryReports {
	public static void main(String[] args) {
		RestClient tmClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);

		DeliveryReport[] reports;
		try {
			reports = tmClient.getDeliveryReport("all");
			for(DeliveryReport report: reports) {
				System.out.println(report);
				for(Hashtable<String, String> row: report.getRows()) {
					System.out.println("\tMessage ID: " + row.get("message_id"));
					System.out.println("\tLast Updated: " + row.get("last_updated"));
					System.out.println("\tMobile Number: " + row.get("mobile_number"));
					System.out.println("\tStatus: " + row.get("status"));
					System.out.println("\tCustom Tag: " + row.get("custom"));
				}
			}
		} catch (RestClientException e) {
			e.printStackTrace();
		}
	}
}
import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class CreateAccount {
	public static void main(String[] args) {
		RestClient tmClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
		try {
			tmClient.createSubAccount("My client", null, null, null, null, null, false);
		} catch (RestClientException e) {
			e.printStackTrace();
		}
	}
}
package Examples;
import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class CreditTransfer {
	public static void main(String[] args) {
		RestClient tmClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);
		try {
			tmClient.transferCreditsToUser(5000, "targetAPIusername", "targetAPIpassword");
		} catch (RestClientException e) {
			e.printStackTrace();
		}
	}
}
To complete your code you should add some error handing, to catch exceptions. All you need to do is put the wrapper function calls in a try-catch block as follows.

 

import java.util.Hashtable;
import java.util.Map;
import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class ErrorCapture {
	public static void main(String[] args) {
		RestClient tmClient = new RestClient("MyUser", "MyPass", RestClient.ENV_PRODUCTION);

		try {
			tmClient.sendSMS("Hello SMS World!", "447000000000", "SenderName", 72, "", "", null);
			// if the send fails, execution jumps to the start of the catch-block
			int creditsAvailable = tmClient.getCredits();
			System.out.println("Account have " + creditsAvailable + " credits.");
		} catch (RestClientException e) {
			Hashtable<String, String> errors = tmClient.getLastErrors();
			for(Map.Entry<String, String> error: errors.entrySet())
				System.out.println("Error code " + error.getKey() + ": " + error.getValue());
		}
	}
}

It is up to you to decide how to handle the errors. We also recommend that you log them for debugging purposes.

 

Our example code is an illustration of how you might integrate with our systems and is not certified for production environments. You are responsible for testing and QA.