Sample code for 30+ languages & platforms
C#

Shopware Update Product Data

See more Shopware Examples

Update information about an existing product in Shopware.

Chilkat C# Downloads

C#
bool success = false;

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

Chilkat.Http http = new Chilkat.Http();

http.Login = "api_username";
http.Password = "api_key";
http.BasicAuth = true;

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

// {
//   "name": "Super-Duper Sports Shoes"
// }

Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("name","Super-Duper Sports Shoes");

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

string url = "https://my-shopware-shop.com/api/articles/{$id}";
Chilkat.HttpResponse resp = new Chilkat.HttpResponse();
success = http.HttpJson("PUT",url,json,"application/json",resp);
if (success == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());

// A 200 response code indicates success.
int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(resp.Header);
    Debug.WriteLine("Failed.");
    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "success": true,
//   "data": {
//     "id": 8312,
//     "location": "https:\/\/my-shopware-shop.com\/api\/articles\/8312"
//   }
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

success = jResp.BoolOf("success");
int dataId = jResp.IntOf("data.id");
string dataLocation = jResp.StringOf("data.location");