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

Activix CRM Create a Phone

See more Activix CRM Examples

Create a phone. Returns the created phone.

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": 7135833,
        //   "number": "+15141234455",
        //   "type": "home"
        // }

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

        JsonObject jsonRequestBody = new JsonObject();
        jsonRequestBody.updateInt("lead_id", 7135833);
        jsonRequestBody.updateString("number", "+15141234455");
        jsonRequestBody.updateString("type", "home");

        String url = "https://crm.activix.ca/api/v2/lead-phones";

        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": 34566,
        //         "created_at": "2018-04-09T18:05:00+00:00",
        //         "updated_at": "2018-04-09T18:05:00+00:00",
        //         "lead_id": 3466512,
        //         "number": "+15141234455",
        //         ...
        //     }
        // }

        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");
        String dataExtension = jsonResponse.stringOf("data.extension");
        String dataNumber = jsonResponse.stringOf("data.number");
        String dataType = jsonResponse.stringOf("data.type");
        boolean dataValid = jsonResponse.boolOf("data.valid");
        String dataValidated = jsonResponse.stringOf("data.validated");
        boolean dataMobile = jsonResponse.boolOf("data.mobile");
    }
}