Chilkat Online Tools

Android / Infobip WhatsApp / Delete Media

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

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

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

    // {
    //   "url": "{{exampleImagePath}}"
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("url","{{exampleImagePath}}");

    http.SetRequestHeader("Authorization","App {{INFOBIP_API_KEY}}");
    http.SetRequestHeader("Content-Type","application/json");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);

    CkHttpResponse resp = http.PTextSb("DELETE","https://domain.com/whatsapp/1/senders/:sender/media",sbRequestBody,"utf-8","application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    int respStatusCode = resp.get_StatusCode();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode != 204) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, resp.header());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, resp.bodyStr());
        Log.i(TAG, "Failed.");

        return;
        }

    Log.i(TAG, "Success.");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Curl Command

curl -X DELETE
	-H "Authorization: App {{INFOBIP_API_KEY}}"
	-H "Content-Type: application/json"
	-d '{
    "url": "{{exampleImagePath}}"
}'
https://domain.com/whatsapp/1/senders/:sender/media

Postman Collection Item JSON

{
  "name": "Delete Media",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var firstTest = 0",
          "pm.test(\"Status code is 204, media deleted\", function () {",
          "    firstTest = pm.response.to.have.status(204);",
          "});",
          "",
          "pm.test(\"Media deleted successfully\", function () {",
          "    if (firstTest)",
          "    {",
          "        pm.expect(pm.response.text()).to.empty;  ",
          "    }",
          "    else",
          "    {",
          "        pm.expect.fail('This failed because the previous test failed ...');        ",
          "    }",
          "});",
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "DELETE",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"url\": \"{{exampleImagePath}}\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/whatsapp/1/senders/:sender/media",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "whatsapp",
        "1",
        "senders",
        ":sender",
        "media"
      ],
      "variable": [
        {
          "key": "sender",
          "value": "{{senderNumber}}",
          "description": "(Required) Registered WhatsApp sender number. Must be in international format."
        }
      ]
    },
    "description": "Delete WhatsApp media. May be outbound or inbound media."
  },
  "response": [
    {
      "name": "Media deleted",
      "originalRequest": {
        "method": "DELETE",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"url\": \"{{exampleImagePath}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/whatsapp/1/senders/:sender/media",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "whatsapp",
            "1",
            "senders",
            ":sender",
            "media"
          ],
          "variable": [
            {
              "key": "sender",
              "value": "{{senderNumber}}",
              "description": "(Required) Registered WhatsApp sender number. Must be in international format."
            }
          ]
        }
      },
      "status": "No Content",
      "code": 204,
      "_postman_previewlanguage": "plain",
      "header": [
        {
          "key": "Vary",
          "value": "Origin"
        },
        {
          "key": "Vary",
          "value": "Access-Control-Request-Method"
        },
        {
          "key": "Vary",
          "value": "Access-Control-Request-Headers"
        },
        {
          "key": "Date",
          "value": "Mon, 08 Nov 2021 10:52:03 GMT"
        },
        {
          "key": "Server",
          "value": "SMS API"
        },
        {
          "key": "X-Request-Id",
          "value": "1636368723198695161"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}