Sample code for 30+ languages & platforms
Unicode C++

ShopwareDelete Product

See more Shopware Examples

Deletes a product in Shopware.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    http.put_Login(L"api_username");
    http.put_Password(L"api_key");
    http.put_BasicAuth(true);

    // The id of the product is appended to the path part of the URL.
    http.SetUrlVar(L"id",L"8312");

    const wchar_t *url = L"https://my-shopware-shop.com/api/articles/{$id}";

    // Send a DELETE request with nothing in the request body.
    CkHttpResponseW resp;
    success = http.HttpNoBody(L"DELETE",url,resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp.GetBodySb(sbResponseBody);

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    // A 200 response code indicates success (i.e. the request was sent and a response was received).
    int respStatusCode = resp.get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp.header());
        wprintf(L"Failed.\n");
        return;
    }

    // Sample JSON response:

    // {
    //   "success": true
    // }

    bool bDeleted = jResp.BoolOf(L"success");
    wprintf(L"Deleted: %d\n",bDeleted);

    // A failed response would look like this:

    // {
    //   "success": false,
    //   "message": "Product by \"id\" 8312 not found"
    // }
    }