export type IncomingWebhook = {name: string, function_source: string, respond_result: boolean, options?: ({secret?: string | undefined, secretAsQueryParam?: boolean | undefined}) | undefined}; export type CreateApiGroupsGroupIdAppsAppIdServicesServiceIdIncomingWebhooksArgs = {body: IncomingWebhook}; export type CreateApiGroupsGroupIdAppsAppIdServicesServiceIdIncomingWebhooksOptions = {baseUrl?: string | undefined, tokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a webhook * * POST /groups/{groupId}/apps/{appId}/services/{serviceId}/incoming_webhooks */ export const createApiGroupsGroupIdAppsAppIdServicesServiceIdIncomingWebhooks = async (args: CreateApiGroupsGroupIdAppsAppIdServicesServiceIdIncomingWebhooksArgs, options?: CreateApiGroupsGroupIdAppsAppIdServicesServiceIdIncomingWebhooksOptions) => { const {baseUrl = "https://services.cloud.mongodb.com/api/admin/v3.0", fetch: fetchFn = fetch, tokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (tokenAuth !== undefined) headers.set('authorization', `Bearer ${tokenAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/groups/${encodeURIComponent(String(args.groupId))}/apps/${encodeURIComponent(String(args.appId))}/services/${encodeURIComponent(String(args.serviceId))}/incoming_webhooks${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 };