Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Activix CRM Create a Communication

See more Activix CRM Examples

Create a communication. Returns the created communication.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        http.setAuthToken("ACCESS_TOKEN");

        http.setAccept("application/json");

        // The following JSON is sent in the request body:

        // {
        //   "lead_id": "LEAD_ID",
        //   "method": "phone",
        //   "type": "outgoing",
        //   "call_status": "calling"
        // }

        // Use this online tool to generate the code from sample JSON:
        // Generate Code to Create JSON

        JsonObject jsonRequestBody = new JsonObject();
        jsonRequestBody.updateString("lead_id", "LEAD_ID");
        jsonRequestBody.updateString("method", "phone");
        jsonRequestBody.updateString("type", "outgoing");
        jsonRequestBody.updateString("call_status", "calling");

        String url = "https://crm.activix.ca/api/v2/communications";

        HttpResponse resp = new HttpResponse();
        try {
            http.httpJson("POST", url, jsonRequestBody, "application/json", resp);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response Status Code: " + resp.getStatusCode());

        JsonObject jsonResponse = new JsonObject();
        jsonResponse.load(resp.getBodyStr());
        jsonResponse.setEmitCompact(false);
        System.out.println(jsonResponse.emit());

        if (resp.getStatusCode() >= 300) {
            System.out.println("Failed.");
            return;
        }

        // Sample output...
        // (See the parsing code below..)
        //
        // Use the this online tool to generate parsing code from sample JSON:
        // Generate Parsing Code from JSON

        // {
        //   "data": {
        //     "id": 5411998,
        //     "created_at": "2019-06-10T13:01:40+00:00",
        //     "updated_at": "2019-06-10T13:01:40+00:00",
        //     "lead_id": 7135833,
        //     "user_id": 13705,
        //     "method": "phone",
        //     "type": "outgoing",
        //     "email_subject": null,
        //     "email_body": null,
        //     "email_client": null,
        //     "email_user": null,
        //     "call_duration": null,
        //     "call_phone": null,
        //     "call_status": "calling"
        //   }
        // }
        //

        int dataId = jsonResponse.intOf("data.id");
        String dataCreated_at = jsonResponse.stringOf("data.created_at");
        String dataUpdated_at = jsonResponse.stringOf("data.updated_at");
        int dataLead_id = jsonResponse.intOf("data.lead_id");
        int dataUser_id = jsonResponse.intOf("data.user_id");
        String dataMethod = jsonResponse.stringOf("data.method");
        String dataType = jsonResponse.stringOf("data.type");
        String dataEmail_subject = jsonResponse.stringOf("data.email_subject");
        String dataEmail_body = jsonResponse.stringOf("data.email_body");
        String dataEmail_client = jsonResponse.stringOf("data.email_client");
        String dataEmail_user = jsonResponse.stringOf("data.email_user");
        String dataCall_duration = jsonResponse.stringOf("data.call_duration");
        String dataCall_phone = jsonResponse.stringOf("data.call_phone");
        String dataCall_status = jsonResponse.stringOf("data.call_status");
    }
}