Java
Chilkat2 Java
Activix CRM Update a Phone
See more Activix CRM Examples
Updates a phone and returns the updated phone.Chilkat Java Downloads
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:
// {
// "number": "+15141234459",
// "type": "home",
// "mobile": true
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
JsonObject jsonRequestBody = new JsonObject();
jsonRequestBody.updateString("number", "+15141234459");
jsonRequestBody.updateString("type", "home");
jsonRequestBody.updateBool("mobile", true);
String url = "https://crm.activix.ca/api/v2/lead-phones/PHONE_ID";
HttpResponse resp = new HttpResponse();
try {
http.httpJson("PUT", 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:07: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");
boolean dataValidated = jsonResponse.boolOf("data.validated");
boolean dataMobile = jsonResponse.boolOf("data.mobile");
}
}