Sample code for 30+ languages & platforms
C

WhatsApp - Delete Media

Demonstrates how to delete media previously uploaded to the WhatsApp Business API client

Chilkat C Downloads

C
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    HCkHttpResponse resp;
    int respStatusCode;

    success = FALSE;

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

    http = CkHttp_Create();

    // Implements the following CURL command:

    // curl -X DELETE \
    //   https://your-webapp-hostname:your-webapp-port/v1/media/media-id \
    //   -H 'Authorization: Bearer your-auth-token'

    // Use the following online tool to generate HTTP code from a CURL command
    // Convert a cURL Command to HTTP Source Code

    // Adds the "Authorization: Bearer your-auth-token" header.
    CkHttp_putAuthToken(http,"your-auth-token");

    resp = CkHttpResponse_Create();
    success = CkHttp_HttpNoBody(http,"DELETE","https://your-webapp-hostname:your-webapp-port/v1/media/media-id",resp);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(resp);
        return;
    }

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Response Body:\n");
        printf("%s\n",CkHttpResponse_bodyStr(resp));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(resp);
        return;
    }

    printf("Success.\n");


    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(resp);

    }