export type CreateApiItemsItemnameArgs = {'X-OpenHAB-Source'?: string | undefined, itemname: string, source?: string | undefined, body: {value: string}}; export type CreateApiItemsItemnameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Sends a command to an item. * * POST /items/{itemname} */ export const createApiItemsItemname = async (args: CreateApiItemsItemnameArgs, options: CreateApiItemsItemnameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-OpenHAB-Source'] != null) headers.set("X-OpenHAB-Source", String(args['X-OpenHAB-Source'])) if (args.source != null) query.append("source", String(args.source)) const url = `${baseUrl.replace(/\/+$/, '')}/items/${encodeURIComponent(String(args.itemname))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };