export type BasicAuthAuthentication = {type: 'basic_auth', data?: ({username: string, password?: string | undefined}) | undefined}; export type BearerTokenAuthentication = {type: 'bearer_token', data?: ({token?: string | undefined}) | undefined}; export type ApiKeyAuthentication = {type: 'api_key', data?: ({name: string, value?: string | undefined}) | undefined, add_position: 'header' | 'query_string'}; export type WebhookPatchRequest = {webhook?: ({name?: string | undefined, description?: string | undefined, endpoint?: string | undefined, http_method?: ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE') | undefined, request_format?: ('json' | 'xml' | 'form_encoded') | undefined, status?: ('active' | 'inactive') | undefined, subscriptions?: Array | undefined, authentication?: (BasicAuthAuthentication | BearerTokenAuthentication | ApiKeyAuthentication) | undefined, custom_headers?: {[key: string]: string} | undefined}) | undefined}; export type PatchApiApiV2WebhooksWebhookIdArgs = {webhook_id: string, body: WebhookPatchRequest}; export type PatchApiApiV2WebhooksWebhookIdOptions = {baseUrl?: string | undefined, apiTokenAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Patch Webhook * * PATCH /api/v2/webhooks/{webhook_id} */ export const patchApiApiV2WebhooksWebhookId = async (args: PatchApiApiV2WebhooksWebhookIdArgs, options?: PatchApiApiV2WebhooksWebhookIdOptions) => { const {baseUrl = "https://example.zendesk.com", fetch: fetchFn = fetch, apiTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiTokenAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiTokenAuth.username}:${apiTokenAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/webhooks/${encodeURIComponent(String(args.webhook_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 };