OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"messages\": [\n {\n \"originator\": \"{{originator}}\",\n \"content\": {\n \"preview_url\": false,\n \"message_type\": \"TEMPLATE\",\n \"template\": {\n \"template_id\": \"{{template_id}}\",\n \"body_parameter_values\": {\n \"0\": \"parameter1\",\n \"1\": \"parameter2\"\n },\n \"carousel\": {\n \"cards\": [\n {\n \"card_index\": \"0\",\n \"components\": [\n {\n \"type\": \"header\",\n \"parameters\": [\n {\n \"type\": \"image\",\n \"image\": {\n \"id\": \"1585106238959535\"\n }\n }\n ]\n },\n {\n \"type\": \"body\",\n \"parameters\": [\n {\n \"type\": \"text\",\n \"text\": \"parameter1\"\n },\n {\n \"type\": \"text\",\n \"text\": \"parameter2\"\n }\n ]\n },\n {\n \"type\": \"button\",\n \"sub_type\": \"quick_reply\",\n \"index\": \"0\",\n \"parameters\": [\n {\n \"type\": \"payload\",\n \"payload\": \"59NqSd\"\n }\n ]\n }\n ]\n },\n {\n \"card_index\": \"1\",\n \"components\": [\n {\n \"type\": \"header\",\n \"parameters\": [\n {\n \"type\": \"image\",\n \"image\": {\n \"id\": \"1585106238959535\"\n }\n }\n ]\n },\n {\n \"type\": \"body\",\n \"parameters\": [\n {\n \"type\": \"text\",\n \"text\": \"parameter1\"\n },\n {\n \"type\": \"text\",\n \"text\": \"parameter2\"\n }\n ]\n },\n {\n \"type\": \"button\",\n \"sub_type\": \"quick_reply\",\n \"index\": \"0\",\n \"parameters\": [\n {\n \"type\": \"payload\",\n \"payload\": \"59NqSdd\"\n }\n ]\n }\n ]\n }\n ]\n }\n }\n },\n \"recipients\": [\n {\n \"recipient\": \"{{recipient1}}\",\n \"recipient_type\": \"individual\"\n }\n ],\n \"report_url\": \"https://the_url_to_recieve_delivery_report.com\"\n }\n ]\n}\n");
Request request = new Request.Builder()
.url("https://api.d7networks.com/whatsapp/v2/send")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer {{api_access_token}}")
.build();
Response response = client.newCall(request).execute();