import {z} from 'zod' export type ContactListCreateV1 = Record; export type InMarketCreateV1 = {brandIds?: Array | undefined, buyingPower?: (Array<'Low' | 'Medium' | 'High' | 'VeryHigh'>) | undefined, country: string, gender?: ('Male' | 'Female') | undefined, interestIds?: Array | undefined, priceRange?: (Array<'Low' | 'Medium' | 'High'>) | undefined}; export type PointOfInterestV1 = {latitude?: (number | null) | undefined, longitude?: (number | null) | undefined, name?: (string | null) | undefined}; export type LocationCreateV1 = {pointsOfInterest: Array, radiusInKm: number}; export type LookalikeCreateV1 = {seedSegmentId: string, targetSize?: number | undefined}; export type ProspectingCreateV1 = {daysSinceLastVisitMax?: number | undefined, daysSinceLastVisitMin?: number | undefined, usersType: 'Prospects' | 'ProspectsOrNonBuyers'}; export type RetargetingCreateV1 = {daysSinceLastVisitMax: number, daysSinceLastVisitMin: number, visitorsType: 'All' | 'Buyers' | 'NonBuyers'}; export type AudienceSegmentCreateEntityV1 = {advertiserId: string, contactList?: ContactListCreateV1 | undefined, description?: string | undefined, inMarket?: InMarketCreateV1 | undefined, location?: LocationCreateV1 | undefined, lookalike?: LookalikeCreateV1 | undefined, name: string, prospecting?: ProspectingCreateV1 | undefined, retargeting?: RetargetingCreateV1 | undefined}; export type AudienceSegmentCreateEntityV1Resource = {attributes?: AudienceSegmentCreateEntityV1 | undefined, type?: string | undefined}; export type AudienceSegmentBulkCreateInputV1 = {data?: Array | undefined}; export type CreateApi202601MarketingSolutionsAudienceSegmentsCreateArgs = {body: AudienceSegmentBulkCreateInputV1}; export type CreateApi202601MarketingSolutionsAudienceSegmentsCreateOptions = {baseUrl?: string | undefined, oauth?: string | undefined, fetch?: typeof fetch | undefined}; export const behavioralV1 = z.object({category: z.enum(["Unknown", "Lifestyles", "LifeEvents", "Seasonal", "BuyingPatterns"]), country: z.string().nullable().optional(), endDate: z.string().nullable().optional(), startDate: z.string().nullable().optional()}).nullable(); export const contactListV1 = z.object({isReadOnly: z.boolean().nullable().optional()}).nullable(); export const inMarketV1 = z.object({brandIds: z.array(z.string()).nullable().optional(), buyingPower: z.array(z.enum(["Unknown", "Low", "Medium", "High", "VeryHigh"])).nullable().optional(), country: z.string().nullable().optional(), gender: z.enum(["Unknown", "Male", "Female"]).nullable().optional(), interestIds: z.array(z.string()).nullable().optional(), priceRange: z.array(z.enum(["Unknown", "Low", "Medium", "High"])).nullable().optional()}).nullable(); export const pointOfInterestV1 = z.object({latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), name: z.string().nullable().optional()}); export const locationV1 = z.object({pointsOfInterest: z.array(pointOfInterestV1).nullable().optional(), radiusInKm: z.number().int().nullable().optional(), registryType: z.enum(["Unknown", "PointOfInterest"]).nullable().optional()}).nullable(); export const lookalikeV1 = z.object({seedSegmentId: z.string().nullable().optional(), targetSize: z.number().int().nullable().optional()}).nullable(); export const prospectingV1 = z.object({daysSinceLastVisitMax: z.number().int().nullable().optional(), daysSinceLastVisitMin: z.number().int().nullable().optional(), usersType: z.enum(["Unknown", "Prospects", "ProspectsOrNonBuyers"]).nullable().optional()}).nullable(); export const retargetingV1 = z.object({daysSinceLastVisitMax: z.number().int().nullable().optional(), daysSinceLastVisitMin: z.number().int().nullable().optional(), visitorsType: z.enum(["Unknown", "All", "Buyers", "NonBuyers"]).nullable().optional()}).nullable(); export const audienceSegmentEntityV1 = z.object({advertiserId: z.string().nullable().optional(), behavioral: behavioralV1.optional(), contactList: contactListV1.optional(), createdAt: z.string().nullable().optional(), description: z.string().nullable().optional(), inMarket: inMarketV1.optional(), location: locationV1.optional(), lookalike: lookalikeV1.optional(), name: z.string().nullable().optional(), prospecting: prospectingV1.optional(), retargeting: retargetingV1.optional(), type: z.enum(["Unknown", "InMarket", "Prospecting", "ContactList", "Location", "Behavioral", "Retargeting", "Lookalike"]).nullable().optional(), updatedAt: z.string().nullable().optional()}).nullable(); export const audienceSegmentEntityV1Resource = z.object({attributes: audienceSegmentEntityV1.optional(), id: z.string().nullable().optional(), type: z.string().nullable().optional()}); 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 audienceSegmentEntityV1ListResponse = z.object({data: z.array(audienceSegmentEntityV1Resource).nullable().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/audience-segments/create * * POST /2026-01/marketing-solutions/audience-segments/create */ export const createApi202601MarketingSolutionsAudienceSegmentsCreate = async (args: CreateApi202601MarketingSolutionsAudienceSegmentsCreateArgs, options?: CreateApi202601MarketingSolutionsAudienceSegmentsCreateOptions) => { 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/audience-segments/create${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(audienceSegmentEntityV1ListResponse, await res.json()) };