Snippets

Purvesh Khona Create Email

Created by Purvesh Khona

File Create Email Added

  • Ignore whitespace
  • Hide word diff
+/**
+ * 
+ */
+package com.braango.virtualdealer.email;
+
+import java.util.List;
+import java.util.Map;
+
+import com.braango.client.ApiCallback;
+import com.braango.client.ApiClient;
+import com.braango.client.ApiException;
+import com.braango.client.braangoapi.EmailsApi;
+import com.braango.client.braangomodel.EmailOutputBodyData;
+import com.braango.client.braangomodel.RequestHeader;
+import com.braango.client.braangomodel.EmailInput;
+import com.braango.client.braangomodel.EmailInputBody;
+import com.braango.client.braangomodel.EmailOutput;
+
+/**
+ * @author braango
+ * 
+ *    Sample code showing how to create add email for personnel
+ *
+ */
+public class CreateEmail {
+
+	static String basePath = "https://testapi2.braango.com/v2/braango";
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		// TODO Auto-generated method stub
+
+		ApiClient braangoApiClient = new ApiClient();
+		// TEST auth token. Please contact
+		// sales@braango.com to have one
+		// created for you
+		String authToken = "ISNWF0P30WM0CMK";
+		braangoApiClient.setBasePath(basePath);
+
+		// Set the auth_token for api client to
+		// interact with Braango system
+		braangoApiClient.setApiKey(authToken);
+
+		// Api key is authorization to to access
+		// resources within braango system
+		//
+		// This key is different than auth_token
+		// that is used to validate the master account
+
+		String apiKey = "ISNfTMNOumV3xYNDd2g";
+
+		// Create personnel api. Personnel is hosted by subDealer
+		EmailsApi emailApi = new EmailsApi(braangoApiClient);
+		
+		final Boolean typeAdfCrmEmail = false;
+
+		ApiCallback<EmailOutput> callBack = new ApiCallback<EmailOutput>() {
+
+			@Override
+			public void onUploadProgress(long bytesWritten, 
+					long contentLength,
+					boolean done) {
+
+				System.out
+						.println("Place holder for tracking"
+								+ " request progress");
+
+			}
+
+			@Override
+			public void onSuccess(EmailOutput result, int statusCode,
+					Map<String, List<String>> responseHeaders) {
+
+				EmailOutputBodyData emailList = result.getBody()
+						.getData();
+				
+				List<String> emails = null;
+				if(typeAdfCrmEmail) {
+					emails = emailList.getCrmEmailList();
+				} else {
+					emails = emailList.getEmailList();
+				}
+				
+
+				System.out.println("Email LIST : " + emails);
+
+			}
+
+			@Override
+			public void onFailure(ApiException e, int statusCode,
+					Map<String, List<String>> responseHeaders) {
+				System.out.println("Error is " + statusCode + " "
+						+ e.getResponseBody());
+
+			}
+
+			@Override
+			public void onDownloadProgress(long bytesRead, long contentLength,
+					boolean done) {
+
+			}
+		};
+
+		// PersonnelRequestInput wraps RequestHeader and personnelRequestBody
+		EmailInput emailInput = new EmailInput();
+
+		/*
+		 * { "api_key": "ISNGvAzwuy4X7vAqrtV", "id": "any value",
+		 * "account_type": "partner" }
+		 */
+		RequestHeader hdr = new RequestHeader();
+
+		// Set the account type to partner for
+		// virtual dealer and partner hosted
+		// accounts
+
+		hdr.setAccountType("partner");
+
+		// dealer_api_key returned
+		// when partner_dealer was created
+
+		hdr.setApiKey(apiKey);
+
+		// ID that will be reflected back
+		hdr.setId("email-create-s1002r2");
+		emailInput.setHeader(hdr);
+
+		EmailInputBody body = new EmailInputBody();
+
+		// Create new SMS number for this personnel
+		body.email("test6@subdealers1002.com");
+		body.setTypeAdfCrm(typeAdfCrmEmail);
+
+		emailInput.setBody(body);
+
+		try {
+			String subDealerId = "subdealers1002";
+			String salesPersonId = "0550c168-6117-45d5-a95f-e66593e6336b";
+			emailApi.createEmailAsync(subDealerId, salesPersonId, emailInput,
+					callBack);
+		} catch (ApiException e1) {
+			e1.printStackTrace();
+		}
+	}
+
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.