export type CreateApiReviewsSiteidArgs = {siteid: number, xml?: boolean | undefined, body: {token: string, name?: string | undefined, orderid: string, products?: string | undefined, email: string, followup: string, test?: boolean | undefined, custom_questions?: string | undefined}}; export type CreateApiReviewsSiteidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new review entry. * * POST /reviews/{siteid} */ export const createApiReviewsSiteid = async (args: CreateApiReviewsSiteidArgs, options?: CreateApiReviewsSiteidOptions) => { const {baseUrl = "https://api.shopperapproved.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") if (args.xml != null) query.append("xml", String(args.xml)) const url = `${baseUrl.replace(/\/+$/, '')}/reviews/${encodeURIComponent(String(args.siteid))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };