Message-ID: <2146080913.15719.1614957811749.JavaMail.confluence@wiki> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_15718_1674721788.1614957811749" ------=_Part_15718_1674721788.1614957811749 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html A few Simple Uses - Java

A few Simple Uses - Java

=20
=20
=20
=20

 

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

=09=09try {
=09=09=09tmClient.sendSMS("Hello SMS World!", "447000000000&=
quot;, "SenderName", 72, "", "", null);
=09=09} catch (RestClientException e) {
=09=09=09e.printStackTrace();
=09=09}
=09}
}
=20
=20
=20
=20
=20
import uk.co.textmarketer.RestAPI.RestClient;
import uk.co.textmarketer.RestAPI.RestClientException;
public class CheckBalance {
=09public static void main(String[] args) {
=09=09RestClient tmClient =3D new RestClient("MyUser", "MyPa=
ss", RestClient.ENV_PRODUCTION);
=09=09try {
=09=09=09int creditsAvailable =3D tmClient.getCredits();
=09=09=09System.out.println("Account have " + creditsAvailable + =
" credits.");
=09=09} catch (RestClientException e) {
=09=09=09e.printStackTrace();
=09=09}
=09}
}
=20
=20
=20
=20
=20
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 {
=09public static void main(String[] args) {
=09=09RestClient tmClient =3D new RestClient("MyUser", "MyPa=
ss", RestClient.ENV_PRODUCTION);

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

 

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

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

It is up to you to decide how t= o handle the errors. We also recommend that you log them for debugging purp= oses.

 

=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20

You must know!

=20 =20

Our example code is an illustra= tion of how you might integrate with our systems and is not certified for p= roduction environments. You are responsible for testing and QA.


=20
=20
=20
=20
=20
=20
=20
=20

 

=20
=20
=20
=20 =20
=20
=20

 

=20
=20
=20
=20

 

=20
=20
=20
------=_Part_15718_1674721788.1614957811749--