PrestaShop
PrestaShop
Let agents check orders, customers, products and stock. Write access also permits status/tracking updates, stock changes, and product/customer creation, edits and permanent deletion. Order changes can email customers.
Read access requires a View (GET)-only PrestaShop key. A key with write permissions can change store data regardless of Houston's Access setting.
Supports PrestaShop 1.7, 8 and 9; editing existing records requires version 8+. Customer password hashes and private order keys stay hidden.
Setup instructions
Setup instructions
Connect PrestaShop
Requires PrestaShop 1.7, 8 or 9 over HTTPS at the domain root, and a back-office account allowed to manage Advanced Parameters.
Use a separate View (GET)-only key for connections with Read access. PrestaShop can turn read requests into changes; a write-enabled key can change data regardless of Houston's Access setting.
- Under Advanced Parameters → Webservice, enable the webservice.
- Select Add new webservice key, generate a key and keep it enabled.
- Grant View (GET) for the resources agents need:
addresses,carriers,cart_rules,carts,categories,combinations,countries,currencies,customers,languages,manufacturers,order_carriers,order_details,order_histories,order_invoices,order_payments,order_slip,order_states,orders,products,stock_availables,suppliers. Leave write columns off and save. - In Houston, enter Store domain without
https://or a path, paste Webservice key, choose Read for Access and save.
Advanced
Changes and multiple stores
For a separate connection with Write access, allow Add (POST) for customers, order histories and products; Patch (PATCH) for customers, order carriers, products and stock (version 8+); and Delete (DELETE) for customers/products only if permanent deletion is intended. Status and tracking changes can email customers. Use Store association to limit stores the key may access.
Connection problems
Use the final HTTPS domain; subdirectories and redirects are unsupported. The API
must answer at /api. Save the key to regenerate Apache's .htaccess, or configure
the /api rewrite on nginx. If PHP receives no key, enable CGI mode for PHP and
save the key again, or ask your host to forward the Authorization header.
Files
Files
connector.luau
-- PrestaShop Webservice API (PrestaShop 1.7, 8 and 9). Arguments and results keep PrestaShop's native field names. type Options = {[string]: any} local STORE = string.lower(config.store_host) local API = "https://" .. STORE .. "/api/" local DOCS = "https://devdocs.prestashop-project.org/9/webservice/resources/" local NONE: Options = table.freeze({}) -- Each resource's singular and plural JSON nodes, its path where that is not the -- plural, and the writes connections with write access get. type Resource = {one: string, many: string, path: string?, writes: {string}?} local RESOURCES: {Resource} = { {one = "address", many = "addresses"}, {one = "carrier", many = "carriers"}, {one = "cart", many = "carts"}, {one = "cart_rule", many = "cart_rules"}, {one = "category", many = "categories"}, {one = "combination", many = "combinations"}, {one = "country", many = "countries"}, {one = "currency", many = "currencies"}, {one = "customer", many = "customers", writes = {"create", "update", "delete"}}, {one = "language", many = "languages"}, {one = "manufacturer", many = "manufacturers"}, {one = "order", many = "orders"}, {one = "order_carrier", many = "order_carriers", writes = {"update"}}, {one = "order_detail", many = "order_details"}, {one = "order_history", many = "order_histories", writes = {"create"}}, {one = "order_invoice", many = "order_invoices"}, {one = "order_payment", many = "order_payments"}, {one = "order_slip", many = "order_slips", path = "order_slip"}, {one = "order_state", many = "order_states"}, {one = "product", many = "products", writes = {"create", "update", "delete"}}, {one = "stock_available", many = "stock_availables", writes = {"update"}}, {one = "supplier", many = "suppliers"}, } -- Only these resources email customers, when sendemail is set. local SENDS_EMAIL = {createOrderHistory = true, updateOrderCarrier = true} -- Password hashes, reset tokens and the guest order-tracking key never leave the -- connector, and cannot be filtered or sorted on, which would reveal them. Only a new -- customer's passwd, a plain password PrestaShop hashes, can be written: setting an -- existing customer's password, like a reset token, would take over their account. local SECRET = {passwd = true, secure_key = true, reset_password_token = true, reset_password_validity = true, last_passwd_gen = true} local CREATE_ONLY = {passwd = true} local function camel(node: string): string return (string.gsub("_" .. node, "_(%a)", string.upper)) end local function field(value: any, name: string): string assert(type(value) == "string" and string.match(value, "^[%a_][%w_]*$"), name .. " must be a PrestaShop field name") return value end local function readable(value: any, name: string): string assert(not SECRET[field(value, name)], value .. " is withheld by the connector") return value end local function id(value: any, name: string): string assert(type(value) == "number" and value >= 1 and value % 1 == 0 and value <= 9007199254740991, name .. " must be a positive integer ID") return string.format("%d", value) end local function integer(value: any, name: string, min: number, max: number): number assert(type(value) == "number" and value % 1 == 0 and value >= min and value <= max, name .. " must be an integer from " .. min .. " to " .. max) return value end -- PrestaShop reads ps_method (the HTTP method) and url (the resource) from any query -- string, overriding the request and the proxy's path rules. Every query is built -- from these closed option lists, so callers can never add a parameter. local function options(input: any, allowed: {[string]: boolean}): Options if input == nil then return NONE end assert(type(input) == "table", "opts must be an object") for key in input do assert(type(key) == "string" and allowed[key], tostring(key) .. " is not a supported option") end return input end local function scalar(value: any, name: string): string local kind = type(value) if kind == "boolean" then return if value then "1" else "0" end if kind == "number" then return if value % 1 == 0 and math.abs(value) <= 9007199254740991 then string.format("%d", value) else tostring(value) end assert(kind == "string", name .. " must be a string, number or boolean") return value end local function list(value: any, name: string, empty: boolean?): {any} assert(type(value) == "table" and (empty or #value > 0), name .. " must be a nonempty array") local count = 0 for _ in value do count += 1 end assert(count == #value, name .. " must be an array") return value end -- Filters take PrestaShop's syntax as a string, such as ">[10]" or "%[mug]%"; -- a number or an array of numbers and strings matches those exact values. local function filterValue(value: any, name: string): string if type(value) == "string" then assert(value ~= "", name .. " must be nonempty") return value end if type(value) == "table" then local values: {string} = {} for _, item in list(value, name) do local text = scalar(item, name) -- These would turn an exact match into an OR, a range or another value. assert(text ~= "" and not string.find(text, "[|,%[%]]"), name .. " values must be nonempty without | , [ or ]; use a filter string") table.insert(values, text) end return "[" .. table.concat(values, "|") .. "]" end return "[" .. scalar(value, name) .. "]" end local function shop(opts: Options, parts: {string}) if opts.language ~= nil then table.insert(parts, "language=" .. id(opts.language, "language")) end if opts.id_shop ~= nil then table.insert(parts, "id_shop=" .. (if opts.id_shop == "all" then "all" else id(opts.id_shop, "id_shop"))) end end local LIST_OPTIONS = {display = true, filter = true, sort = true, limit = true, offset = true, language = true, id_shop = true} local function listQuery(input: any): string local opts = options(input, LIST_OPTIONS) local parts: {string} = {} local display = opts.display or "full" if display ~= "full" then local fields: {string} = {} for _, name in list(display, "display") do table.insert(fields, readable(name, "display")) end display = url.encode("[" .. table.concat(fields, ",") .. "]") end table.insert(parts, "display=" .. display) local dates = false if opts.filter ~= nil then assert(type(opts.filter) == "table", "filter must be an object") local names: {string} = {} for name in opts.filter do table.insert(names, readable(name, "filter")) end assert(#names > 0, "filter must name at least one field") table.sort(names) for _, name in names do dates = dates or name == "date_add" or name == "date_upd" table.insert(parts, url.encode("filter[" .. name .. "]") .. "=" .. url.encode(filterValue(opts.filter[name], "filter." .. name))) end end if opts.sort ~= nil then local sorts: {string} = {} local given: {any} = if type(opts.sort) == "string" then {opts.sort} else list(opts.sort, "sort") for _, sort in given do local name = type(sort) == "string" and (string.match(sort, "^(.+)_ASC$") or string.match(sort, "^(.+)_DESC$")) assert(name, "sort must be field_ASC or field_DESC, or an array of those") readable(name, "sort") dates = dates or name == "date_add" or name == "date_upd" table.insert(sorts, sort) end table.insert(parts, "sort=" .. url.encode("[" .. table.concat(sorts, ",") .. "]")) end local offset = integer(if opts.offset == nil then 0 else opts.offset, "offset", 0, 9007199254740991) local limit = integer(if opts.limit == nil then 50 else opts.limit, "limit", 1, 100) table.insert(parts, "limit=" .. string.format("%d", offset) .. "%2C" .. string.format("%d", limit)) if dates then table.insert(parts, "date=1") end shop(opts, parts) return table.concat(parts, "&") end -- XML 1.0 forbids these control characters; PrestaShop would answer HTTP 500 and echo -- the whole body, a customer password included. local function escape(value: string, name: string): string assert(not string.find(value, "[%z\1-\8\11\12\14-\31]") and not string.find(value, "\239\191[\190\191]"), name .. " must not contain control characters or U+FFFE/U+FFFF") return (string.gsub(value, "[&<>\"]", {["&"] = "&", ["<"] = "<", [">"] = ">", ['"'] = """})) end -- A field is a scalar, or a translated value as [{id = languageID, value}]; -- associations map names to arrays of objects, such as {categories = {{id = 2}}}. local function element(name: string, value: any): string if type(value) ~= "table" then return "<" .. name .. ">" .. escape(scalar(value, name), name) .. "</" .. name .. ">" end local languages: {string} = {} for _, item in list(value, name) do assert(type(item) == "table" and item.value ~= nil, name .. " must be a scalar or an array of {id, value}") table.insert(languages, '<language id="' .. id(item.id, name .. ".id") .. '">' .. escape(scalar(item.value, name), name) .. "</language>") end return "<" .. name .. ">" .. table.concat(languages) .. "</" .. name .. ">" end local function sortedKeys(value: Options, name: string): {string} local keys: {string} = {} for key in value do table.insert(keys, field(key, name)) end table.sort(keys) return keys end local function xml(node: string, recordID: string?, fields: any): string assert(type(fields) == "table", "fields must be an object") assert(fields.id == nil, "fields must not contain id; pass the ID as the first argument") local parts = {"<?xml version=\"1.0\" encoding=\"UTF-8\"?><prestashop><" .. node .. ">"} if recordID then table.insert(parts, "<id>" .. recordID .. "</id>") end for _, name in sortedKeys(fields, "fields") do assert(not SECRET[name] or (recordID == nil and CREATE_ONLY[name]), name .. " cannot be written by the connector") local value = fields[name] if name == "associations" then assert(type(value) == "table", "associations must be an object") table.insert(parts, "<associations>") for _, association in sortedKeys(value, "associations") do table.insert(parts, "<" .. association .. ">") for _, item in list(value[association], "associations." .. association, true) do assert(type(item) == "table", "associations." .. association .. " must contain objects") table.insert(parts, "<item>") for _, key in sortedKeys(item, "associations." .. association) do table.insert(parts, element(key, item[key])) end table.insert(parts, "</item>") end table.insert(parts, "</" .. association .. ">") end table.insert(parts, "</associations>") else table.insert(parts, element(name, value)) end end table.insert(parts, "</" .. node .. "></prestashop>") return table.concat(parts) end local function header(response: HttpResponse, name: string): string? local values = response.headers[name] return if values then values[1] else nil end -- PrestaShop's XML errors and PHP warnings quote the request body, so a new customer's -- password never appears in an error, raw or XML-escaped. -- Host firewalls answer with HTML pages; keep their visible text and comments, which -- name the blocking layer. local function excerpt(raw: string): string local text = string.gsub(raw, "<!%-%-(.-)%-%->", " %1 ") for _, tag in {"script", "style"} do text = string.gsub(text, "<" .. tag .. "[%s>].-</" .. tag .. ">", " ") end text = string.gsub(string.gsub(text, "<[^>]*>", " "), "%s+", " ") return string.sub((string.gsub(text, "^ ", "")), 1, 300) end -- A write that failed late or answered unreadably may still have been applied. local SAVED = "; the change may have been saved: read the record before repeating it" local function redact(message: string, secret: string?): string if secret == nil or secret == "" then return message end for _, form in {secret, escape(secret, "passwd")} do message = string.gsub(message, (string.gsub(form, "%W", "%%%0")), "[redacted]") end return message end local function failStatus(name: string, response: HttpResponse, method: string, secret: string?): never local message = "PrestaShop HTTP " .. tostring(response.statusCode) local raw = await(response.body:readPrefix(16 * 1024)) local ok, value = pcall(json.decode, raw) local envelope = ok and type(value) == "table" and type(value.errors) == "table" and #value.errors > 0 if envelope then for index = 1, math.min(#value.errors, 5) do local item = value.errors[index] if type(item) == "table" then if item.code ~= nil then message ..= " [" .. tostring(item.code) .. "]" end -- An XML error [127] echoes the request body, which can hold a customer password. local text = string.match(tostring(item.message), "^(.-)%s*Original XML") or tostring(item.message) message ..= " " .. string.sub(text, 1, 600) end end elseif string.match(raw, "%S") then -- A body cut by the prefix limit no longer decodes; still drop the echoed XML. message ..= ": " .. excerpt(string.match(raw, "^(.-)Original XML") or raw) end if response.statusCode == 401 and string.match(raw, "^%s*401 Unauthorized%s*$") then message ..= ". PrestaShop received no key: the web server may drop the Authorization header" end local location = header(response, "location") if response.statusCode >= 300 and response.statusCode < 400 and location then message ..= "; redirected to " .. string.sub(location, 1, 200) .. ". Set the connection's store domain to the final host." end local retry = header(response, "retry-after") if retry then message ..= "; Retry-After: " .. string.sub(retry, 1, 40) end local write = method ~= "GET" if write and response.statusCode >= 500 then message ..= SAVED end -- PrestaShop reports its own failures, such as a duplicate email or a disabled -- webservice, as 5xx with an error list; those fail again on retry. Other 5xx -- are retryable only for reads, as a write may have been applied. return houston.fail({operation = name, layer = "upstream", upstream_status = response.statusCode, retryable = response.statusCode == 429 or (response.statusCode >= 500 and not envelope and not write), message = redact(message, secret)}) end local function withhold(value: any) if type(value) ~= "table" then return end for key, item in value do if SECRET[key] then value[key] = nil else withhold(item) end end end local function request(name: string, method: string, path: string, query: string, body: string?, secret: string?): any local headers: HttpHeaders = {Accept = {"application/json"}, ["Output-Format"] = {"JSON"}} if body then headers["Content-Type"] = {"application/xml"} end local target = API .. path .. (if query ~= "" then "?" .. query else "") local response = await(http.request({method = method, url = target, headers = headers, body = body})) if response.statusCode < 200 or response.statusCode >= 300 then failStatus(name, response, method, secret) end local raw = await(response.body:readAll()) if method == "DELETE" and not string.match(raw, "%S") then return true end local ok, value = pcall(json.decode, raw) if not ok or type(value) ~= "table" then return houston.fail({operation = name, layer = "upstream", upstream_status = response.statusCode, retryable = false, message = "PrestaShop returned a response that is not JSON; check that the webservice is enabled and served at https://" .. STORE .. "/api" .. (if method == "GET" then "" else SAVED)}) end withhold(value) return value end -- PrestaShop 8+ drops a lone record's "0", empty and false fields unless display is -- set, which returns it as a one-item list instead; unwrap that list. local function single(name: string, value: any, one: string, many: string): any local records = value[many] if type(records) ~= "table" or type(records[1]) ~= "table" then return houston.fail({operation = name, layer = "upstream", retryable = false, message = "PrestaShop returned no " .. one .. " record" .. (if string.sub(name, 1, 3) == "get" then "" else SAVED)}) end return {[one] = records[1]} end local GET_OPTIONS = {language = true, id_shop = true} local exports: {[string]: any} = {} local signatures: {[string]: string} = {} for _, resource in RESOURCES do local one, many, path = resource.one, resource.many, resource.path or resource.many local listName, getName = "list" .. camel(many), "get" .. camel(one) exports[listName] = function(opts: Options?): any local value = request(listName, "GET", path, listQuery(opts), nil) -- PrestaShop answers an empty list with [] instead of its usual wrapper. if next(value) == nil then return {[many] = json.decode("[]")} end return value end exports[getName] = function(recordID: number, opts: Options?): any local segment = id(recordID, "id") local parts = {"display=full"} shop(options(opts, GET_OPTIONS), parts) return single(getName, request(getName, "GET", path .. "/" .. segment, table.concat(parts, "&"), nil), one, many) end signatures[listName] = "({display?, filter?, sort?, limit?, offset?, language?, id_shop?}?) -> {" .. many .. ": [...]}" signatures[getName] = "(id, {language?, id_shop?}?) -> {" .. one .. ": {...}}" if resource.writes and houston.allows("data:write") then for _, verb in resource.writes do local name = verb .. camel(one) local allowed = {id_shop = true, sendemail = SENDS_EMAIL[name]} local function query(input: Options?): string local opts = options(input, allowed) local parts: {string} = if verb == "delete" then {} else {"display=full"} shop(opts, parts) if opts.sendemail ~= nil then assert(type(opts.sendemail) == "boolean", "sendemail must be a boolean") if opts.sendemail then table.insert(parts, "sendemail=1") end end return table.concat(parts, "&") end local email = if SENDS_EMAIL[name] then ", sendemail?" else "" if verb == "create" then exports[name] = function(fields: Options, opts: Options?): any local q = query(opts) local body = xml(one, nil, fields) local secret = if fields.passwd ~= nil then scalar(fields.passwd, "passwd") else nil return single(name, request(name, "POST", path, q, body, secret), one, many) end signatures[name] = "(fields, {id_shop?" .. email .. "}?) -> {" .. one .. ": {...}}" elseif verb == "update" then exports[name] = function(recordID: number, fields: Options, opts: Options?): any local segment, q = id(recordID, "id"), query(opts) return single(name, request(name, "PATCH", path .. "/" .. segment, q, xml(one, segment, fields)), one, many) end signatures[name] = "(id, fields, {id_shop?" .. email .. "}?) -> {" .. one .. ": {...}}" else exports[name] = function(recordID: number, opts: Options?): any local segment, q = id(recordID, "id"), query(opts) return request(name, "DELETE", path .. "/" .. segment, q, nil) end signatures[name] = "(id, {id_shop?}?) -> true" end end end end exports.help = function(): string local names: {string} = {} for name in signatures do table.insert(names, name) end table.sort(names) local lines = { "PrestaShop Webservice API for " .. STORE .. ". Results keep PrestaShop's native snake_case fields and wrappers: lists return {<plural>: [...]}, an empty list included, and get, create and update return {<singular>: {...}}. IDs are numbers and most other values strings. Translated fields are [{id, value}] per language, or one string when language=<id> is passed or the store has a single active language; links sit under associations. Password hashes, reset tokens and secure_key are removed from results and cannot be filtered, sorted or displayed. Connector calls return completed values: use them directly, without await.", "Lists fetch one page with every field (display='full'): pass limit (1-100, default 50) and offset (default 0), and fetch the next offset while a page returns limit records; PrestaShop gives no total. display={'id','reference'} returns only those fields. filter maps a field to a value: a number or array matches exactly ({current_state={2,3}}), and a string uses PrestaShop's syntax: '[v]' equal, '[a|b]' either, '[1,10]' between, '>[v]', '<[v]', '![v]' not, '[mug]%' starts with, '%[mug]%' contains. Dates are 'YYYY-MM-DD HH:MM:SS' in the store's time zone, for example filter={date_upd='>[2026-10-01 00:00:00]'}. sort is 'field_ASC', 'field_DESC' or an array of those. language and id_shop (an ID, or 'all') pick a language and a multistore shop; the default shop is used otherwise.", "Examples: listOrders({filter={current_state=2}, sort='date_add_DESC', limit=20}); getOrder(123); listOrderDetails({filter={id_order=123}}); listOrderHistories({filter={id_order=123}, sort='date_add_DESC'}); listOrderStates({language=1, display={'id','name'}}); listCustomers({filter={email='[[email protected]]'}}); listProducts({filter={reference='%[MUG]%'}, display={'id','reference','price','name'}, language=1}); listStockAvailables({filter={id_product=9}}).", "Orders link to customers, addresses, carts, carriers and currencies through id_* fields; an order's current status is current_state, an order_states ID. The webservice key's own resource and method permissions apply: a resource it does not allow fails with HTTP 401 [26], a method with HTTP 405 [25]. Errors report the HTTP status and PrestaShop's [code] messages; a plain 401 Unauthorized means the key did not reach PrestaShop. Houston retries HTTP 429 at most twice unless Retry-After asks for more than 5 seconds.", } if houston.allows("data:write") then table.insert(lines, "Writes take fields as an object of PrestaShop field names (see the field reference below), sent as PrestaShop's XML; the result is the saved record. Translated fields take [{id=languageID, value='...'}] or one string for every language, associations take arrays of objects such as associations={categories={{id=2}}} and replace the whole set (json.decode('[]') clears it), and booleans become 1 or 0. Updates use PATCH and change only the given fields, which needs PrestaShop 8 or later; on PrestaShop 1.7 only creates and deletes work. createProduct needs at least price; createCustomer needs firstname, lastname, email and passwd (the plain password, which PrestaShop hashes; updates cannot change it). createOrderHistory({id_order=123, id_order_state=4}, {sendemail=true}) changes an order's status and, with sendemail, emails the customer when that status sends emails. updateOrderCarrier(id, {tracking_number='1Z...'}, {sendemail=true}) sets a shipment's tracking number and sends the in-transit email; if that email fails, PrestaShop answers HTTP 500 [46] although the number was saved. updateStockAvailable(id, {quantity=12}) sets a quantity: find the row with listStockAvailables({filter={id_product=9, id_product_attribute=0}}), but for a product with combinations update each combination's row (id_product_attribute=<combination ID>), as PrestaShop recomputes the 0 row as their total. Deleting a product or customer is permanent. Only HTTP 429 is retried: after a timeout or 5xx, read the record again before repeating a write.") end table.insert(lines, "Field reference: " .. DOCS .. "<path>/, where the path is the plural, or order_slip for credit slips.") for _, name in names do table.insert(lines, name .. signatures[name]) end return table.concat(lines, "\n") end return exportshouston.json
{ "schema_version": 2, "name": "PrestaShop", "files": [ "connector.luau" ], "icon": "icon.svg", "access": [ { "name": "data", "label": "Access", "description": "Read access is only guaranteed by your PrestaShop key. Houston sends no changes with Read access, but PrestaShop lets any request turn a read into an edit or a delete, so give a Read connection a key with only View (GET) ticked. A key with Add, Modify, Patch or Delete ticked can change or delete store data.", "levels": [ { "value": "read", "label": "Read" }, { "value": "write", "label": "Write" } ], "default": "read" } ], "config": { "store_host": { "description": "The domain your store is served from, without https:// or a path.", "label": "Store domain", "max_length": 253, "order": 2, "placeholder": "shop.example.com", "required": true, "type": "string" } }, "auth": { "key": { "config": { "token": { "label": "Webservice key", "order": 1, "required": true, "type": "secret", "min_length": 32, "max_length": 32 } }, "label": "PrestaShop webservice key", "type": "manual" } }, "proxy": [ { "action": { "basic_auth": { "password": "", "username": "{{auth.key.token}}" } }, "if": "{{ allows access.data \"write\" }}", "match": { "host": [ "{{config.store_host}}" ], "method": [ "POST" ], "path": [ "/api/customers", "/api/order_histories", "/api/products" ], "protocol": "http" } }, { "action": { "basic_auth": { "password": "", "username": "{{auth.key.token}}" } }, "if": "{{ allows access.data \"write\" }}", "match": { "host": [ "{{config.store_host}}" ], "method": [ "PATCH" ], "path": [ "/api/customers/{id}", "/api/order_carriers/{id}", "/api/products/{id}", "/api/stock_availables/{id}" ], "protocol": "http" } }, { "action": { "basic_auth": { "password": "", "username": "{{auth.key.token}}" } }, "if": "{{ allows access.data \"write\" }}", "match": { "host": [ "{{config.store_host}}" ], "method": [ "DELETE" ], "path": [ "/api/customers/{id}", "/api/products/{id}" ], "protocol": "http" } }, { "action": { "basic_auth": { "password": "", "username": "{{auth.key.token}}" } }, "match": { "host": [ "{{config.store_host}}" ], "method": [ "GET" ], "path": [ "/api/addresses", "/api/addresses/{id}", "/api/carriers", "/api/carriers/{id}", "/api/cart_rules", "/api/cart_rules/{id}", "/api/carts", "/api/carts/{id}", "/api/categories", "/api/categories/{id}", "/api/combinations", "/api/combinations/{id}", "/api/countries", "/api/countries/{id}", "/api/currencies", "/api/currencies/{id}", "/api/customers", "/api/customers/{id}", "/api/languages", "/api/languages/{id}", "/api/manufacturers", "/api/manufacturers/{id}", "/api/order_carriers", "/api/order_carriers/{id}", "/api/order_details", "/api/order_details/{id}", "/api/order_histories", "/api/order_histories/{id}", "/api/order_invoices", "/api/order_invoices/{id}", "/api/order_payments", "/api/order_payments/{id}", "/api/order_slip", "/api/order_slip/{id}", "/api/order_states", "/api/order_states/{id}", "/api/orders", "/api/orders/{id}", "/api/products", "/api/products/{id}", "/api/stock_availables", "/api/stock_availables/{id}", "/api/suppliers", "/api/suppliers/{id}" ], "protocol": "http" } } ] }icon.svg
README.md
--- description: Check orders, customers, products and stock in your PrestaShop store, and update order statuses, tracking numbers, stock and products. Read access requires a view-only PrestaShop key. --- # PrestaShop Let agents check orders, customers, products and stock. **Write** access also permits status/tracking updates, stock changes, and product/customer creation, edits and permanent deletion. Order changes can email customers. > Read access requires a **View (GET)**-only PrestaShop key. A key with write > permissions can change store data regardless of Houston's Access setting. Supports PrestaShop 1.7, 8 and 9; editing existing records requires version 8+. Customer password hashes and private order keys stay hidden. [Connect PrestaShop](SETUP.md).SETUP.md
# Connect PrestaShop Requires PrestaShop 1.7, 8 or 9 over HTTPS at the domain root, and a back-office account allowed to manage **Advanced Parameters**. > Use a separate **View (GET)**-only key for connections with **Read** access. PrestaShop can > turn read requests into changes; a write-enabled key can change data regardless > of Houston's Access setting. 1. Under **Advanced Parameters → Webservice**, enable the webservice. 2. Select **Add new webservice key**, generate a key and keep it enabled. 3. Grant **View (GET)** for the resources agents need: `addresses`, `carriers`, `cart_rules`, `carts`, `categories`, `combinations`, `countries`, `currencies`, `customers`, `languages`, `manufacturers`, `order_carriers`, `order_details`, `order_histories`, `order_invoices`, `order_payments`, `order_slip`, `order_states`, `orders`, `products`, `stock_availables`, `suppliers`. Leave write columns off and save. 4. In Houston, enter **Store domain** without `https://` or a path, paste **Webservice key**, choose **Read** for **Access** and save. [Official webservice guide](https://devdocs.prestashop-project.org/9/webservice/tutorials/creating-access/). ## Advanced ### Changes and multiple stores For a separate connection with **Write** access, allow **Add (POST)** for customers, order histories and products; **Patch (PATCH)** for customers, order carriers, products and stock (version 8+); and **Delete (DELETE)** for customers/products only if permanent deletion is intended. Status and tracking changes can email customers. Use **Store association** to limit stores the key may access. ### Connection problems Use the final HTTPS domain; subdirectories and redirects are unsupported. The API must answer at `/api`. Save the key to regenerate Apache's `.htaccess`, or configure the `/api` rewrite on nginx. If PHP receives no key, enable **CGI mode for PHP** and save the key again, or ask your host to forward the Authorization header.tests
authentication.luau
return { contract = function(m) m.authentication({ { auth = { token = "synthetic-method-secret-32-chars" }, config = { store_host = "shop.example.com" }, endpoint = { "GET", "https://shop.example.com/api/orders" }, expected = "Basic c3ludGhldGljLW1ldGhvZC1zZWNyZXQtMzItY2hhcnM6", header = "Authorization", method = "key", publisher = {}, }, }) end, }errors.luau
return { scenario = {publisher = {}, access = {data = "write"}, config = {store_host = "shop.example.com"}, auth_method = "key", auth_config = {token = "0123456789ABCDEF0123456789ABCDEF"}}, configure = function() calls = 0 status = 200 payload = "{}" responseHeaders = {} http = {request = function(req) calls += 1 return fixture.operation({statusCode = status, headers = responseHeaders, body = fixture.reader(payload)}) end} end, run = function(shop) local function rejected(fn, expected) local before = calls local ok, err = pcall(fn) assert(not ok and string.find(tostring(err), expected, 1, true), "wrong validation error: " .. tostring(err)) assert(calls == before, "invalid input reached PrestaShop") end rejected(function() shop.getOrder() end, "id must be a positive integer ID") for _, value in {"1", 0, -1, 1.5, "../configurations"} do rejected(function() shop.getOrder(value) end, "id must be a positive integer ID") end rejected(function() shop.deleteProduct("9") end, "id must be a positive integer ID") rejected(function() shop.listOrders("processing") end, "opts must be an object") -- PrestaShop reads ps_method from the query string, which would turn a read into a delete. for _, key in {"ps_method", "ws_key", "url", "output_format", "io_format", "price", "date"} do rejected(function() shop.listOrders({[key] = "DELETE"}) end, key .. " is not a supported option") rejected(function() shop.getOrder(1, {[key] = "DELETE"}) end, key .. " is not a supported option") end rejected(function() shop.deleteProduct(1, {ps_method = "GET"}) end, "ps_method is not a supported option") rejected(function() shop.listOrders({filter = {["id]=1&ps_method=DELETE&filter[id"] = 1}}) end, "filter must be a PrestaShop field name") rejected(function() shop.listOrders({filter = {}}) end, "filter must name at least one field") rejected(function() shop.listOrders({filter = {reference = ""}}) end, "filter.reference must be nonempty") rejected(function() shop.listOrders({filter = {id = json.decode("[]")}}) end, "filter.id must be a nonempty array") rejected(function() shop.listOrders({filter = {id = {nested = 1}}}) end, "filter.id must be") for _, value in {"A|B", "10,20", "[x]", ""} do rejected(function() shop.listProducts({filter = {reference = {"MUG", value}}}) end, "filter.reference values must be nonempty without") end -- Filtering on a withheld field would reveal it one character at a time. rejected(function() shop.listCustomers({filter = {passwd = "[$2y]%"}}) end, "passwd is withheld") rejected(function() shop.listOrders({filter = {secure_key = "[a]%"}}) end, "secure_key is withheld") rejected(function() shop.listCustomers({sort = "reset_password_token_ASC"}) end, "reset_password_token is withheld") rejected(function() shop.listCustomers({display = {"id", "passwd"}}) end, "passwd is withheld") rejected(function() shop.listOrders({sort = "date_add"}) end, "sort must be field_ASC or field_DESC") rejected(function() shop.listOrders({sort = "date add_ASC"}) end, "sort must be a PrestaShop field name") rejected(function() shop.listOrders({display = "id"}) end, "display must be a nonempty array") rejected(function() shop.listOrders({limit = 0}) end, "limit must be an integer from 1 to 100") rejected(function() shop.listOrders({limit = 101}) end, "limit must be an integer from 1 to 100") rejected(function() shop.listOrders({offset = -1}) end, "offset must be an integer") rejected(function() shop.listOrders({language = "fr"}) end, "language must be a positive integer ID") rejected(function() shop.getOrder(1, {id_shop = "default"}) end, "id_shop must be a positive integer ID") rejected(function() shop.listOrders({schema = "synopsis"}) end, "schema is not a supported option") rejected(function() shop.createProduct("mug") end, "fields must be an object") rejected(function() shop.createProduct({id = 3, price = 1}) end, "fields must not contain id") rejected(function() shop.updateProduct(3, {["price><id>1</id><price"] = 1}) end, "fields must be a PrestaShop field name") rejected(function() shop.updateProduct(3, {name = {{value = "Mug"}}}) end, "name.id must be a positive integer ID") rejected(function() shop.updateProduct(3, {name = {lang = "Mug"}}) end, "name must be a nonempty array") rejected(function() shop.updateProduct(3, {associations = {categories = {2}}}) end, "associations.categories must contain objects") rejected(function() shop.updateProduct(3, {associations = {["a></associations><price>0</price><x"] = {{id = 1}}}}) end, "associations must be a PrestaShop field name") rejected(function() shop.updateProduct(3, {associations = {categories = {{["id></id><price>0</price><x"] = 1}}}}) end, "associations.categories must be a PrestaShop field name") rejected(function() shop.updateProduct(3, {associations = "categories"}) end, "associations must be an object") rejected(function() shop.createCustomer({firstname = "Bo\0", passwd = "secret"}) end, "firstname must not contain control characters") rejected(function() shop.updateProduct(3, {name = {{id = 1, value = "Mug\27"}}}) end, "name must not contain control characters") rejected(function() shop.createCustomer({firstname = "Bo", website = "a\u{FFFE}", passwd = "secret"}) end, "website must not contain control characters or U+FFFE/U+FFFF") -- A chosen reset token would let its writer take over the customer's account. rejected(function() shop.updateCustomer(3, {reset_password_token = "known"}) end, "reset_password_token cannot be written") rejected(function() shop.updateCustomer(3, {secure_key = "known"}) end, "secure_key cannot be written") rejected(function() shop.updateCustomer(3, {passwd = "known"}) end, "passwd cannot be written") rejected(function() shop.createProduct({price = 1}, {sendemail = true}) end, "sendemail is not a supported option") rejected(function() shop.createOrderHistory({id_order = 1, id_order_state = 4}, {sendemail = "yes"}) end, "sendemail must be a boolean") local function upstream(code, body, headers, expected) status, payload, responseHeaders = code, body, headers local before = calls local ok, err = pcall(function() shop.updateOrderCarrier(1, {tracking_number = "1Z"}) end) for _, text in expected do assert(not ok and string.find(tostring(err), text, 1, true), "missing " .. text .. " in " .. tostring(err)) end assert(calls == before + 1, "failed write was retried") end upstream(401, '{"errors":[{"code":26,"message":"No permission for this key"}]}', {}, {"PrestaShop HTTP 401 [26] No permission for this key", '"retryable":false'}) upstream(401, "401 Unauthorized", {["www-authenticate"] = {"Basic realm=\"Welcome to PrestaShop Webservice\""}}, {"HTTP 401: 401 Unauthorized", "may drop the Authorization header"}) upstream(405, '{"errors":[{"code":25,"message":"Method PATCH is not allowed for this resource"}]}', {}, {"[25] Method PATCH"}) upstream(400, json.encode({errors = {{code = 85, message = "Validation error: " .. string.rep("x", 5000)}, {code = 41, message = "parameter \"id_order\" required"}}}), {}, {"[85] Validation error", "[41] parameter", "id_order"}) upstream(500, "<br />\n<b>Fatal error</b>: Allowed memory size exhausted", {}, {"HTTP 500: Fatal error : Allowed memory", "may have been saved", '"retryable":false'}) upstream(503, '{"errors":[{"code":22,"message":"The PrestaShop webservice is disabled. Please activate it in the PrestaShop Back Office"}]}', {}, {"[22] The PrestaShop webservice is disabled", '"retryable":false'}) upstream(500, '{"errors":[{"code":46,"message":"Unable to save resource"}]}', {}, {"HTTP 500 [46] Unable to save resource", '"retryable":false'}) upstream(500, '{"errors":[{"message":"Unknown failure"}]}', {}, {"HTTP 500 Unknown failure"}) status, payload, responseHeaders = 500, json.encode({errors = {{code = 127, message = "XML error : String could not be parsed as XML\nOriginal XML : <customer><passwd>correct horse</passwd></customer>"}}}), {} local ok, err = pcall(function() shop.createCustomer({firstname = "Bo", lastname = "Lee", email = "[email protected]", passwd = "correct horse"}) end) assert(not ok and string.find(tostring(err), "[127] XML error : String could not be parsed as XML", 1, true), tostring(err)) assert(not string.find(tostring(err), "correct horse", 1, true), "the error echoed the password") -- A read that failed upstream is safe to repeat. status, payload, responseHeaders = 502, "<html><body>Bad gateway</body></html>", {} local readOK, readErr = pcall(function() shop.getOrder(1) end) assert(not readOK and string.find(tostring(readErr), '"retryable":true', 1, true) and not string.find(tostring(readErr), "may have been saved", 1, true), tostring(readErr)) local function hidden(code, body) status, payload, responseHeaders = code, body, {} local failed, message = pcall(function() shop.createCustomer({firstname = "Bo", lastname = "Lee", email = "[email protected]", passwd = "correct & horse"}) end) assert(not failed and string.find(tostring(message), "HTTP " .. code, 1, true), tostring(message)) for _, form in {"correct & horse", "correct & horse"} do assert(not string.find(tostring(message), form, 1, true), "the error echoed the password: " .. tostring(message)) end return tostring(message) end -- PHP warnings quote the XML being parsed. local warned = hidden(500, json.encode({errors = {{code = 3, message = "[PHP Warning #2] SimpleXMLElement::__construct(): <passwd>correct & horse</passwd>"}}})) assert(string.find(warned, "<passwd>[redacted]</passwd>", 1, true), warned) -- An error body beyond the 16 KiB prefix no longer decodes as JSON. hidden(500, '{"errors":[{"code":127,"message":"XML error Original XML : <customer><passwd>correct & horse</passwd><website>' .. string.rep("x", 17000)) hidden(500, "<b>Warning</b>: correct & horse") upstream(400, '{"errors":{"email":"taken"}}', {}, {"HTTP 400: {", "taken"}) upstream(503, "<html><head><style>\nbody { color: red }</style><script>var challenge = 1</script></head><body><!-- WAF --><h1>Blocked</h1></body></html>", {}, {"HTTP 503: WAF Blocked ;"}) upstream(429, "Too many requests", {["retry-after"] = {"30"}}, {"HTTP 429: Too many requests", "Retry-After: 30", '"retryable":true'}) upstream(301, "", {location = {"https://www.shop.example.com/api/order_carriers/1"}}, {"HTTP 301", "redirected to https://www.shop.example.com/", "store domain"}) upstream(200, '<?xml version="1.0" encoding="UTF-8"?><prestashop><order_carrier/></prestashop>', {}, {"not JSON", "https://shop.example.com/api", "may have been saved"}) upstream(200, "", {}, {"not JSON"}) -- Without display=full's one-item list, PrestaShop 8+ may have dropped fields. upstream(200, '{"order_carrier":{"id":1}}', {}, {"PrestaShop returned no order_carrier record; the change may have been saved"}) upstream(200, '{"order_carriers":[]}', {}, {"PrestaShop returned no order_carrier record"}) end, }manifest.luau
return { contract = function(m) -- TestPrestaShopStoreHostAndAccessBoundaries do local key = "0123456789ABCDEF0123456789ABCDEF" for _, host in { "", "https://shop.example.com", "shop.example.com/store", "*.example.com" } do do local _, err = m.resolve(nil, { store_host = host }, { token = key }, "key") if err == nil then m.fail("accepted store domain %s", host) end end end do local _, err = m.resolve(nil, { store_host = "shop.example.com" }, { token = "short" }, "key") if err == nil then m.fail("accepted a key that is not 32 characters") end end local basic = "Basic " .. m.base64(key .. ":") local api = "https://shop.example.com/api/" for _, access in { "read", "write" } do local r, err = m.resolve( nil, { store_host = "Shop.Example.com" }, { token = key }, "key", { data = access } ) assert(not err, tostring(err)) if (r.PublicConfig["store_host"] ~= "Shop.Example.com") or (m.count(r.PublicConfig) ~= 1) then m.fail("unexpected Lua config: %s", r.PublicConfig) end m.routes(r, basic, true, { "GET " .. api .. "orders?display=full&limit=0%2C50", "GET " .. api .. "orders/1", "GET " .. api .. "order_details", "GET " .. api .. "order_histories/2", "GET " .. api .. "order_slip/3", "GET " .. api .. "order_states", "GET " .. api .. "order_carriers/4", "GET " .. api .. "customers/5", "GET " .. api .. "addresses", "GET " .. api .. "carts/6", "GET " .. api .. "products/7", "GET " .. api .. "combinations", "GET " .. api .. "categories/8", "GET " .. api .. "stock_availables/9", "GET " .. api .. "cart_rules", "GET " .. api .. "languages", }) m.routes(r, basic, (access == "write"), { "POST " .. api .. "products", "POST " .. api .. "customers", "POST " .. api .. "order_histories?sendemail=1", "PATCH " .. api .. "products/1", "PATCH " .. api .. "customers/1", "PATCH " .. api .. "order_carriers/1", "PATCH " .. api .. "stock_availables/1", "DELETE " .. api .. "products/1", "DELETE " .. api .. "customers/1", }) m.routes(r, basic, false, { "GET " .. api .. "configurations", "GET " .. api .. "translated_configurations", "GET " .. api .. "employees/1", "GET " .. api .. "shop_urls", "GET " .. api .. "images/customizations/1/1", "GET " .. api, "GET " .. api .. "orders/1/extra", "GET https://shop.example.com/webservice/dispatcher.php?url=configurations", "PUT " .. api .. "products/1", "POST " .. api .. "orders", "PATCH " .. api .. "orders/1", "DELETE " .. api .. "orders/1", "POST " .. api .. "products/1", "DELETE " .. api .. "order_histories/1", "HEAD " .. api .. "orders", "DELETE " .. api .. "products?id=%5B1%2C2%5D", "DELETE " .. api .. "customers", "GET https://www.shop.example.com/api/orders", "GET https://shop.example.com.attacker.test/api/orders", "GET https://shop.example.com:8443/api/orders", "GET http://shop.example.com/api/orders", "GET " .. api .. "orders/%2e%2e/configurations", }) end end end, }read_only.luau
return { scenario = {publisher = {}, config = {store_host = "Shop.Example.com"}, auth_method = "key", auth_config = {token = "0123456789ABCDEF0123456789ABCDEF"}}, configure = function() requests = {} payload = "{}" http = {request = function(req) table.insert(requests, req) return fixture.operation({statusCode = 200, headers = {}, body = fixture.reader(payload)}) end} end, run = function(shop) local API = "https://shop.example.com/api/" local function last() return requests[#requests] end local names = {} for name in shop do if name ~= "help" then table.insert(names, name) end end table.sort(names) assert(table.concat(names, ",") == "getAddress,getCarrier,getCart,getCartRule,getCategory,getCombination,getCountry,getCurrency,getCustomer,getLanguage,getManufacturer,getOrder,getOrderCarrier,getOrderDetail,getOrderHistory,getOrderInvoice,getOrderPayment,getOrderSlip,getOrderState,getProduct,getStockAvailable,getSupplier," .. "listAddresses,listCarriers,listCartRules,listCarts,listCategories,listCombinations,listCountries,listCurrencies,listCustomers,listLanguages,listManufacturers,listOrderCarriers,listOrderDetails,listOrderHistories,listOrderInvoices,listOrderPayments,listOrderSlips,listOrderStates,listOrders,listProducts,listStockAvailables,listSuppliers", "wrong read-only surface: " .. table.concat(names, ",")) assert(#requests == 0, "initialization reached PrestaShop") payload = '{"orders":[{"id":7,"reference":"XKBKNABJK","current_state":"2","secure_key":"b44a6d9efd7a0076a0fbce6b15eaf3b1","associations":{"order_rows":[{"id":"1","product_id":"9"}]}}]}' local page = shop.listOrders() assert(last().method == "GET" and last().body == nil) assert(last().url == API .. "orders?display=full&limit=0%2C50", last().url) assert(last().headers["Output-Format"][1] == "JSON" and last().headers.Accept[1] == "application/json") assert(last().headers.Authorization == nil, "connector set credentials") assert(page.orders[1].reference == "XKBKNABJK" and page.orders[1].associations.order_rows[1].product_id == "9") assert(page.orders[1].secure_key == nil, "secure_key was returned") local opts = {filter = {current_state = {2, 3}, date_upd = ">[2026-10-01 00:00:00]"}, sort = "date_add_DESC", limit = 20, offset = 40, language = 1, id_shop = "all"} shop.listOrders(opts) assert(last().url == API .. "orders?display=full&filter%5Bcurrent_state%5D=%5B2%7C3%5D&filter%5Bdate_upd%5D=%3E%5B2026-10-01%2000%3A00%3A00%5D&sort=%5Bdate_add_DESC%5D&limit=40%2C20&date=1&language=1&id_shop=all", last().url) assert(opts.filter.current_state[2] == 3 and opts.limit == 20, "caller options were modified") shop.listProducts({display = {"id", "reference", "price"}, filter = {reference = "%[MUG]%"}, sort = {"price_ASC", "id_DESC"}}) assert(last().url == API .. "products?display=%5Bid%2Creference%2Cprice%5D&filter%5Breference%5D=%25%5BMUG%5D%25&sort=%5Bprice_ASC%2Cid_DESC%5D&limit=0%2C50", last().url) shop.listOrderSlips({filter = {id_order = 12}, limit = 100}) assert(last().url == API .. "order_slip?display=full&filter%5Bid_order%5D=%5B12%5D&limit=0%2C100", last().url) payload = "[]" local empty = shop.listOrderHistories({filter = {id_order = 5}}) assert(last().url == API .. "order_histories?display=full&filter%5Bid_order%5D=%5B5%5D&limit=0%2C50") assert(json.encode(empty.order_histories) == "[]", "empty list lost its wrapper") -- PrestaShop 8+ drops a lone record's "0", empty and false fields; display=full keeps them in a one-item list. payload = '{"customers":[{"id":5,"email":"[email protected]","newsletter":"0","note":"","passwd":"$2y$10$abcdefghijklmnopqrstuv","secure_key":"0f3b","reset_password_token":"tok","reset_password_validity":"0000-00-00 00:00:00","last_passwd_gen":"2026-01-01 00:00:00","associations":{"groups":[{"id":"3"}]}}]}' local customer = shop.getCustomer(5) assert(last().url == API .. "customers/5?display=full", last().url) local record = customer.customer assert(record.email == "[email protected]" and record.newsletter == "0" and record.note == "" and record.associations.groups[1].id == "3") for _, secret in {"passwd", "secure_key", "reset_password_token", "reset_password_validity", "last_passwd_gen"} do assert(record[secret] == nil, secret .. " was returned") end payload = '{"products":[{"id":9,"name":[{"id":"1","value":"Mug"},{"id":"2","value":"Tasse"}]}]}' local product = shop.getProduct(9, {language = 1, id_shop = 2}) assert(last().url == API .. "products/9?display=full&language=1&id_shop=2", last().url) assert(product.product.name[2].value == "Tasse") payload = '{"stock_availables":[{"id":31,"id_product":"9","quantity":"0","out_of_stock":"0"}]}' assert(shop.getStockAvailable(31).stock_available.quantity == "0", "an empty stock lost its quantity") assert(last().url == API .. "stock_availables/31?display=full") assert(#requests == 8) end, }writes.luau
return { scenario = {publisher = {}, access = {data = "write"}, config = {store_host = "shop.example.com"}, auth_method = "key", auth_config = {token = "0123456789ABCDEF0123456789ABCDEF"}}, configure = function() requests = {} payload = "{}" http = {request = function(req) table.insert(requests, req) return fixture.operation({statusCode = if req.method == "POST" then 201 else 200, headers = {}, body = fixture.reader(payload)}) end} end, run = function(shop) local API = "https://shop.example.com/api/" local XML = '<?xml version="1.0" encoding="UTF-8"?><prestashop>' local function last() return requests[#requests] end local function sentXML() return last().headers["Content-Type"][1] == "application/xml" end -- The reads are read_only.luau's exact 44; everything else must be these writes. local names, reads = {}, 0 for name in shop do if string.match(name, "^get%u") or string.match(name, "^list%u") then reads += 1 elseif name ~= "help" then table.insert(names, name) end end assert(reads == 44, "wrong read count: " .. reads) table.sort(names) assert(table.concat(names, ",") == "createCustomer,createOrderHistory,createProduct,deleteCustomer,deleteProduct,updateCustomer,updateOrderCarrier,updateProduct,updateStockAvailable", "wrong writes: " .. table.concat(names, ",")) payload = '{"products":[{"id":"10","price":"9.500000","active":"1","name":[{"id":"1","value":"Mug & co"}]}]}' local product = shop.createProduct({price = 9.5, active = true, name = {{id = 1, value = "Mug & co"}}, description_short = "<b>New</b>", associations = {categories = {{id = 2}, {id = 5}}}}) assert(last().method == "POST" and last().url == API .. "products?display=full" and sentXML()) assert(last().headers.Authorization == nil, "connector set credentials") assert(last().body == XML .. '<product><active>1</active><associations><categories><item><id>2</id></item><item><id>5</id></item></categories></associations><description_short><b>New</b></description_short><name><language id="1">Mug & co</language></name><price>9.5</price></product></prestashop>', last().body) assert(product.product.id == "10") shop.updateProduct(10, {price = "12.00", name = "Mug"}, {id_shop = 2}) assert(last().method == "PATCH" and last().url == API .. "products/10?display=full&id_shop=2" and sentXML()) assert(last().body == XML .. "<product><id>10</id><name>Mug</name><price>12.00</price></product></prestashop>", last().body) -- An empty association clears it; PrestaShop replaces the whole set. shop.updateProduct(10, {associations = {categories = json.decode("[]")}}) assert(last().body == XML .. "<product><id>10</id><associations><categories></categories></associations></product></prestashop>", last().body) payload = '{"stock_availables":[{"id":31,"quantity":"12"}]}' assert(shop.updateStockAvailable(31, {quantity = 12}).stock_available.quantity == "12") assert(last().method == "PATCH" and last().url == API .. "stock_availables/31?display=full") assert(last().body == XML .. "<stock_available><id>31</id><quantity>12</quantity></stock_available></prestashop>", last().body) payload = '{"order_histories":[{"id":"88","id_order":"123","id_order_state":"4"}]}' local history = shop.createOrderHistory({id_order = 123, id_order_state = 4}, {sendemail = true}) assert(last().method == "POST" and last().url == API .. "order_histories?display=full&sendemail=1", last().url) assert(last().body == XML .. "<order_history><id_order>123</id_order><id_order_state>4</id_order_state></order_history></prestashop>", last().body) assert(history.order_history.id_order_state == "4") payload = '{"order_carriers":[{"id":7,"tracking_number":"1Z999"}]}' assert(shop.updateOrderCarrier(7, {tracking_number = "1Z999"}, {sendemail = false}).order_carrier.tracking_number == "1Z999") assert(last().method == "PATCH" and last().url == API .. "order_carriers/7?display=full", last().url) assert(last().body == XML .. "<order_carrier><id>7</id><tracking_number>1Z999</tracking_number></order_carrier></prestashop>") payload = '{"customers":[{"id":"6","email":"[email protected]","passwd":"$2y$10$hash","secure_key":"abcd"}]}' local customer = shop.createCustomer({firstname = "Bo", lastname = "Lee", email = "[email protected]", passwd = "correct horse", newsletter = false}) assert(last().method == "POST" and last().url == API .. "customers?display=full") assert(last().body == XML .. "<customer><email>[email protected]</email><firstname>Bo</firstname><lastname>Lee</lastname><newsletter>0</newsletter><passwd>correct horse</passwd></customer></prestashop>", last().body) assert(customer.customer.email == "[email protected]" and customer.customer.passwd == nil and customer.customer.secure_key == nil) payload = "" assert(shop.deleteProduct(10) == true) assert(last().method == "DELETE" and last().url == API .. "products/10" and last().body == nil) assert(shop.deleteCustomer(6, {id_shop = 1}) == true) assert(last().method == "DELETE" and last().url == API .. "customers/6?id_shop=1") payload = '{"products":[{"id":10}]}' assert(shop.listProducts({display = {"id"}}).products[1].id == 10) assert(last().method == "GET" and last().url == API .. "products?display=%5Bid%5D&limit=0%2C50") assert(#requests == 10) end, }