Lua
Lua
Shopware Update Product Data
See more Shopware Examples
Update information about an existing product in Shopware.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
http.login = "api_username"
http.password = "api_key"
http.basic_auth = true
-- The following JSON is sent in the request body.
-- {
-- "name": "Super-Duper Sports Shoes"
-- }
local json = chilkat.JsonObject.new()
json:update_string("name", "Super-Duper Sports Shoes")
-- The id of the product is appended to the path part of the URL.
http:set_url_var("id", "8312")
local url = "https://my-shopware-shop.com/api/articles/{$id}"
local resp = chilkat.HttpResponse.new()
local success = http:http_json("PUT", url, json, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
-- A 200 response code indicates success.
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end
-- 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:bool_of("success")
local dataId = jResp:int_of("data.id")
local dataLocation = jResp:string_of("data.location")