import {z} from 'zod' export type CreateAdSetAttributionConfigurationV24Q3 = {attributionMethod?: ('unknown' | 'criteoAttribution' | 'googleAnalyticsLastClick' | 'googleAnalyticsDataDriven' | 'lastClick' | 'postClick') | undefined, lookbackWindow?: ('unknown' | '30M' | '24H' | '7D' | '30D' | null) | undefined}; export type CreateAdSetBiddingV24Q3 = {bidAmount?: (number | null) | undefined, costController: 'COS' | 'maxCPC' | 'CPI' | 'CPM' | 'CPO' | 'CPSV' | 'CPV' | 'dailyBudget' | 'targetCPM'}; export type CreateAdSetBudgetV24Q3 = {budgetAmount?: (number | null) | undefined, budgetDeliverySmoothing?: ('accelerated' | 'standard') | undefined, budgetDeliveryWeek?: ('undefined' | 'mondayToSunday' | 'tuesdayToMonday' | 'wednesdayToTuesday' | 'thursdayToWednesday' | 'fridayToThursday' | 'saturdayToFriday' | 'sundayToSaturday') | undefined, budgetRenewal?: ('undefined' | 'daily' | 'monthly' | 'lifetime' | 'weekly') | undefined, budgetStrategy: 'capped' | 'uncapped'}; export type CreateAdSetScheduleV24Q3 = {endDate?: (string | null) | undefined, startDate: string}; export type AdSetDeliveryLimitationsV24Q3 = {devices?: (Array<'other' | 'desktop' | 'mobile' | 'tablet'> | null) | undefined, environments?: (Array<'web' | 'inApp'> | null) | undefined, operatingSystems?: (Array<'android' | 'ios' | 'unknown'> | null) | undefined} | null; export type AdSetFrequencyCappingV24Q3 = {frequency?: ('hourly' | 'daily' | 'lifetime' | 'advanced' | null) | undefined, maximumImpressions?: (number | null) | undefined} | null; export type AdSetTargetingRuleV24Q3 = {operand?: ('undefined' | 'in' | 'notIn') | undefined, values?: (Array | null) | undefined}; export type CreateAdSetGeoLocationV24Q3 = {countries?: AdSetTargetingRuleV24Q3 | undefined, subdivisions?: AdSetTargetingRuleV24Q3 | undefined, zipCodes?: AdSetTargetingRuleV24Q3 | undefined}; export type CreateAdSetTargetingV24Q3 = {deliveryLimitations?: AdSetDeliveryLimitationsV24Q3 | undefined, frequencyCapping: AdSetFrequencyCappingV24Q3, geoLocation?: CreateAdSetGeoLocationV24Q3 | undefined}; export type CreateAdSetV24Q3 = {attributionConfiguration?: CreateAdSetAttributionConfigurationV24Q3 | undefined, bidding: CreateAdSetBiddingV24Q3, budget?: CreateAdSetBudgetV24Q3 | undefined, campaignId: string | null, datasetId: string, mediaType: 'display' | 'video', name: string | null, objective: 'customAction' | 'clicks' | 'conversions' | 'displays' | 'appPromotion' | 'revenue' | 'storeConversions' | 'value' | 'reach' | 'visits' | 'videoViews', schedule: CreateAdSetScheduleV24Q3, targeting: CreateAdSetTargetingV24Q3, trackingCode: string | null}; export type CreateAdSetV24Q3Resource = {attributes?: CreateAdSetV24Q3 | undefined, type?: string | undefined}; export type CreateAdSetV24Q3Request = {data?: CreateAdSetV24Q3Resource | undefined}; export type CreateApi202601MarketingSolutionsAdSetsArgs = {body: CreateAdSetV24Q3Request}; export type CreateApi202601MarketingSolutionsAdSetsOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const readAdSetAttributionConfigurationV24Q3 = z.object({attributionMethod: z.enum(["unknown", "criteoAttribution", "googleAnalyticsLastClick", "googleAnalyticsDataDriven", "lastClick", "postClick"]).nullable().optional(), lookbackWindow: z.enum(["unknown", "30M", "24H", "7D", "30D"]).nullable().optional()}).nullable(); export const readAdSetBiddingV24Q3 = z.object({bidAmount: z.number().nullable().optional(), costController: z.enum(["COS", "maxCPC", "CPI", "CPM", "CPO", "CPSV", "CPV", "dailyBudget", "targetCPM"]).nullable().optional()}).nullable(); export const readAdSetBudgetV24Q3 = z.object({budgetAmount: z.number().nullable().optional(), budgetDeliverySmoothing: z.enum(["accelerated", "standard"]).nullable().optional(), budgetDeliveryWeek: z.enum(["undefined", "mondayToSunday", "tuesdayToMonday", "wednesdayToTuesday", "thursdayToWednesday", "fridayToThursday", "saturdayToFriday", "sundayToSaturday"]).nullable().optional(), budgetRenewal: z.enum(["undefined", "daily", "monthly", "lifetime", "weekly"]).nullable().optional(), budgetStrategy: z.enum(["capped", "uncapped"]).nullable().optional()}).nullable(); export const nillableDateTime = z.object({value: z.string().nullable().optional()}).nullable(); export const readAdSetScheduleV24Q3 = z.object({activationStatus: z.enum(["on", "off"]).nullable().optional(), deliveryStatus: z.enum(["draft", "inactive", "live", "notLive", "pausing", "paused", "scheduled", "ended", "notDelivering", "archived"]).nullable().optional(), endDate: nillableDateTime.optional(), startDate: nillableDateTime.optional()}).nullable(); export const adSetDeliveryLimitationsV24Q3 = z.object({devices: z.array(z.enum(["other", "desktop", "mobile", "tablet"])).nullable().optional(), environments: z.array(z.enum(["web", "inApp"])).nullable().optional(), operatingSystems: z.array(z.enum(["android", "ios", "unknown"])).nullable().optional()}).nullable(); export const adSetFrequencyCappingV24Q3 = z.object({frequency: z.enum(["hourly", "daily", "lifetime", "advanced"]).nullable().optional(), maximumImpressions: z.number().int().nullable().optional()}).nullable(); export const adSetTargetingRuleV24Q3 = z.object({operand: z.enum(["undefined", "in", "notIn"]).optional(), values: z.array(z.string()).nullable().optional()}); export const nillableAdSetTargetingRuleV24Q3 = z.object({value: adSetTargetingRuleV24Q3.nullable().optional()}).nullable(); export const adSetGeoLocationV24Q3 = z.object({countries: nillableAdSetTargetingRuleV24Q3.optional(), subdivisions: nillableAdSetTargetingRuleV24Q3.optional(), zipCodes: nillableAdSetTargetingRuleV24Q3.optional()}).nullable(); export const adSetTargetingV24Q3 = z.object({deliveryLimitations: adSetDeliveryLimitationsV24Q3.optional(), frequencyCapping: z.object({value: adSetFrequencyCappingV24Q3.optional()}).nullable().optional(), geoLocation: adSetGeoLocationV24Q3.optional()}).nullable(); export const readAdSetV24Q3 = z.object({advertiserId: z.string().nullable().optional(), attributionConfiguration: readAdSetAttributionConfigurationV24Q3.optional(), bidding: readAdSetBiddingV24Q3.optional(), budget: readAdSetBudgetV24Q3.optional(), campaignId: z.string().nullable().optional(), datasetId: z.string().nullable().optional(), destinationEnvironment: z.enum(["undefined", "web", "app"]).nullable().optional(), mediaType: z.enum(["display", "video"]).nullable().optional(), name: z.string().nullable().optional(), objective: z.enum(["customAction", "clicks", "conversions", "displays", "appPromotion", "revenue", "storeConversions", "value", "reach", "visits", "videoViews"]).nullable().optional(), schedule: readAdSetScheduleV24Q3.optional(), targeting: adSetTargetingV24Q3.optional(), videoChannel: z.enum(["olv", "ctv"]).nullable().optional()}).nullable(); export const readModelReadAdSetV24Q3 = z.object({attributes: readAdSetV24Q3.optional(), id: z.string().nullable().optional(), type: z.string().nullable().optional()}).nullable(); export const commonProblem = z.object({code: z.string().nullable().optional(), detail: z.string().nullable().optional(), instance: z.string().nullable().optional(), source: z.record(z.string(), z.string()).nullable().optional(), stackTrace: z.string().nullable().optional(), title: z.string().nullable().optional(), traceId: z.string().nullable().optional(), traceIdentifier: z.string().nullable().optional(), type: z.enum(["unknown", "access-control", "authentication", "authorization", "availability", "deprecation", "quota", "validation"]).nullable().optional()}); export const responseReadAdSetV24Q3 = z.object({data: readModelReadAdSetV24Q3.optional(), errors: z.array(commonProblem).nullable().optional(), warnings: z.array(commonProblem).nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * /2026-01/marketing-solutions/ad-sets * * POST /2026-01/marketing-solutions/ad-sets */ export const createApi202601MarketingSolutionsAdSets = async (args: CreateApi202601MarketingSolutionsAdSetsArgs, options?: CreateApi202601MarketingSolutionsAdSetsOptions) => { const {baseUrl = "https://api.criteo.com", fetch: fetchFn = fetch, oauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth !== undefined) headers.set('authorization', `Bearer ${oauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/2026-01/marketing-solutions/ad-sets${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 validateResponse(responseReadAdSetV24Q3, await res.json()) };