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 WebhookSigningSecret = {algorithm?: string | undefined, secret?: string | undefined}; export type Webhook = {id?: string | undefined, name: string, description?: string | undefined, endpoint: string, http_method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', request_format: 'json' | 'xml' | 'form_encoded', status: 'active' | 'inactive', subscriptions?: Array | undefined, authentication?: (BasicAuthAuthentication | BearerTokenAuthentication | ApiKeyAuthentication) | undefined, custom_headers?: {[key: string]: string} | undefined, signing_secret?: WebhookSigningSecret | undefined, external_source?: ({name?: string | undefined, version?: string | undefined}) | undefined, created_at?: string | undefined, created_by?: string | undefined, updated_at?: string | undefined, updated_by?: string | undefined}; export type WebhookUpdateRequest = {webhook: Webhook}; export type UpdateApiApiV2WebhooksWebhookIdArgs = {webhook_id: string, body: WebhookUpdateRequest}; export type UpdateApiApiV2WebhooksWebhookIdOptions = {baseUrl?: string | undefined, apiTokenAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Update Webhook * * PUT /api/v2/webhooks/{webhook_id} */ export const updateApiApiV2WebhooksWebhookId = async (args: UpdateApiApiV2WebhooksWebhookIdArgs, options?: UpdateApiApiV2WebhooksWebhookIdOptions) => { 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: "PUT", 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 };