export type PinterestLibIntegerFormatType = string; export type AttributionModel = 'first_touch' | 'last_touch' | 'multi_touch' | 'mmm'; export type AttributionScope = 'view' | 'engagement' | 'click'; export type Currency = 'UNK' | 'USD' | 'GBP' | 'CAD' | 'EUR' | 'AUD' | 'NZD' | 'SEK' | 'ILS' | 'CHF' | 'HKD' | 'JPY' | 'SGD' | 'KRW' | 'NOK' | 'DKK' | 'PLN' | 'RON' | 'HUF' | 'CZK' | 'BRL' | 'MXN' | 'ARS' | 'CLP' | 'COP' | 'INR' | 'TRY'; export type MsotEventName = 'add_to_cart' | 'checkout' | 'lead' | 'signup'; export type ConversionMSOTEventsCreate = {action_timestamps?: Array | undefined, ad_group_id: PinterestLibIntegerFormatType, attribution_model?: AttributionModel | undefined, attribution_scope?: AttributionScope | undefined, attribution_score?: number | undefined, campaign_id?: PinterestLibIntegerFormatType | undefined, click_window?: string | undefined, currency?: Currency | undefined, event_id: string, event_name: MsotEventName, event_timestamp: number, total_event_touchpoints?: number | undefined, total_events?: number | undefined, total_events_fractional?: number | undefined, value?: number | undefined, view_window?: string | undefined}; export type CreateApiAdAccountsAdAccountIdMsotEventsArgs = {ad_account_id: string, body: ConversionMSOTEventsCreate}; export type CreateApiAdAccountsAdAccountIdMsotEventsOptions = {baseUrl?: string | undefined, pinterestOauth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * Send Measurement Source Of Truth (MSOT) attributed conversion events * * POST /ad_accounts/{ad_account_id}/msot/events */ export const createApiAdAccountsAdAccountIdMsotEvents = async (args: CreateApiAdAccountsAdAccountIdMsotEventsArgs, options?: CreateApiAdAccountsAdAccountIdMsotEventsOptions) => { const {baseUrl = "https://api.pinterest.com/v5", fetch: fetchFn = fetch, pinterestOauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (pinterestOauth2 !== undefined) headers.set('authorization', `Bearer ${pinterestOauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/ad_accounts/${encodeURIComponent(String(args.ad_account_id))}/msot/events${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 };