C++ Google Cloud Storage: Delete Bucket

Back to Index

Permanently deletes an empty bucket. The path parameter is the name of the bucket to delete. In this example, we are deleting the bucket "chilkat-test-bucket". Success is indicated by a 204 response status code with an empty response body.

Documentation: https://cloud.google.com/storage/docs/json_api/v1/buckets/delete

CURL Command

curl -X DELETE https://www.googleapis.com/storage/v1/b/chilkat-test-bucket?project=MY_CLOUD_STORAGE_PROJECT \
    --header "Authorization: Bearer CLOUD_STORAGE_TOKEN"

C++ Example

#include <CkRest.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    CkRest rest;
    bool success;

    //  URL: https://www.googleapis.com/storage/v1/b/chilkat-test-bucket?project=MY_CLOUD_STORAGE_PROJECT
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect("www.googleapis.com",port,bTls,bAutoReconnect);
    if (success != true) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    rest.AddHeader("Authorization","Bearer CLOUD_STORAGE_TOKEN");

    CkStringBuilder sbResponseBody;
    success = rest.FullRequestNoBodySb("DELETE","/storage/v1/b/chilkat-test-bucket?project=MY_CLOUD_STORAGE_PROJECT",sbResponseBody);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        std::cout << "Response Status Code = " << respStatusCode << "\r\n";
        std::cout << "Response Header:" << "\r\n";
        std::cout << rest.responseHeader() << "\r\n";
        std::cout << "Response Body:" << "\r\n";
        std::cout << sbResponseBody.getAsString() << "\r\n";
        return;
    }
    }