/** * */ package com.braango.virtualdealer.personnel.webhooks; 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.braangoapi.GroupsApi; import com.braango.client.braangoapi.WebhooksApi; import com.braango.client.braangomodel.EmailOutputBodyData; import com.braango.client.braangomodel.GroupOutput; import com.braango.client.braangomodel.GroupOutputBodyData; import com.braango.client.braangomodel.RequestHeader; import com.braango.client.braangomodel.EmailInput; import com.braango.client.braangomodel.EmailInputBody; import com.braango.client.braangomodel.EmailOutput; import com.braango.client.braangomodel.WebhkInput; import com.braango.client.braangomodel.WebhookInput; import com.braango.client.braangomodel.WebhookInputBody; import com.braango.client.braangomodel.WebhookOutput; import com.braango.client.braangomodel.WebhookOutputBodyData; /** * @author braango * * Sample code showing how to get all webhooks * * * */ public class CreateWebhook { 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 webhookApi api. WebhooksApi webhookApi = new WebhooksApi(braangoApiClient); final Boolean typeAdfCrmEmail = false; ApiCallback callBack = new ApiCallback() { @Override public void onUploadProgress(long bytesWritten, long contentLength, boolean done) { System.out .println("Place holder for tracking" + " request progress"); } @Override public void onSuccess(WebhookOutput result, int statusCode, Map> responseHeaders) { WebhookOutputBodyData webhookData = result.getBody() .getData(); System.out.println("Webhooks : " + webhookData.getRestEndPoints()); } @Override public void onFailure(ApiException e, int statusCode, Map> responseHeaders) { System.out.println("Error is " + statusCode + " " + e.getResponseBody()); } @Override public void onDownloadProgress(long bytesRead, long contentLength, boolean done) { } }; // Create input for the webhook // WebHook Input wraps hdr and webhook body WebhookInput webhookInput = new WebhookInput(); RequestHeader hdr = new RequestHeader(); hdr.setAccountType("partner"); hdr.setApiKey(apiKey); hdr.setId("create-webhook"); webhookInput.setHeader(hdr); WebhookInputBody body = new WebhookInputBody(); // This is partner generated authid that partner // uses to track the webhook // Braango uses that to index the entry // This needs to be unique for given // personnel body.setAuthId("webhook-auth-id"); // Partner generated auth key for webhook // Braango will use this in its // request when posting message body.setAuthKey("partner-webhook-auth-key"); body.setEnable(true); // Url where the webhook needs to be posted body.setPostUrl("https://test.partner.webhook/someresource"); webhookInput.setBody(body); // End create input for the webhook try { String subDealerId = "subdealers1002"; String salesPersonId = "0550c168-6117-45d5-a95f-e66593e6336b"; String accountType = "partner"; webhookApi.createWebhookAsync(subDealerId, salesPersonId, webhookInput, callBack); } catch (ApiException e1) { e1.printStackTrace(); } } }