import {z} from 'zod' export type GoogleAdsSearchads360V23CommonKeywordPlanAggregateMetrics = {aggregateMetricTypes?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'DEVICE'>) | undefined}; export type GoogleAdsSearchads360V23CommonYearMonth = {month?: ('UNSPECIFIED' | 'UNKNOWN' | 'JANUARY' | 'FEBRUARY' | 'MARCH' | 'APRIL' | 'MAY' | 'JUNE' | 'JULY' | 'AUGUST' | 'SEPTEMBER' | 'OCTOBER' | 'NOVEMBER' | 'DECEMBER') | undefined, year?: unknown | undefined}; export type GoogleAdsSearchads360V23CommonYearMonthRange = {end?: GoogleAdsSearchads360V23CommonYearMonth | undefined, start?: GoogleAdsSearchads360V23CommonYearMonth | undefined}; export type GoogleAdsSearchads360V23CommonHistoricalMetricsOptions = {includeAverageCpc?: boolean | undefined, yearMonthRange?: GoogleAdsSearchads360V23CommonYearMonthRange | undefined}; export type GoogleAdsSearchads360V23ServicesKeywordAndUrlSeed = {keywords?: Array | undefined, url?: string | undefined}; export type GoogleAdsSearchads360V23ServicesKeywordSeed = {keywords?: Array | undefined}; export type GoogleAdsSearchads360V23ServicesSiteSeed = {site?: string | undefined}; export type GoogleAdsSearchads360V23ServicesUrlSeed = {url?: string | undefined}; export type GoogleAdsSearchads360V23ServicesGenerateKeywordIdeasRequest = {aggregateMetrics?: GoogleAdsSearchads360V23CommonKeywordPlanAggregateMetrics | undefined, geoTargetConstants?: Array | undefined, historicalMetricsOptions?: GoogleAdsSearchads360V23CommonHistoricalMetricsOptions | undefined, includeAdultKeywords?: boolean | undefined, keywordAndUrlSeed?: GoogleAdsSearchads360V23ServicesKeywordAndUrlSeed | undefined, keywordAnnotation?: (Array<'UNSPECIFIED' | 'UNKNOWN' | 'KEYWORD_CONCEPT'>) | undefined, keywordPlanNetwork?: ('UNSPECIFIED' | 'UNKNOWN' | 'GOOGLE_SEARCH' | 'GOOGLE_SEARCH_AND_PARTNERS') | undefined, keywordSeed?: GoogleAdsSearchads360V23ServicesKeywordSeed | undefined, language?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined, siteSeed?: GoogleAdsSearchads360V23ServicesSiteSeed | undefined, urlSeed?: GoogleAdsSearchads360V23ServicesUrlSeed | undefined}; export type CreateApiV23CustomersCustomersIdGenerateKeywordIdeasArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesGenerateKeywordIdeasRequest}; export type CreateApiV23CustomersCustomersIdGenerateKeywordIdeasOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23CommonKeywordPlanDeviceSearches = z.object({device: z.enum(["UNSPECIFIED", "UNKNOWN", "MOBILE", "TABLET", "DESKTOP", "CONNECTED_TV", "OTHER"]).optional(), searchCount: z.string().optional()}); export const googleAdsSearchads360V23CommonKeywordPlanAggregateMetricResults = z.object({deviceSearches: z.array(googleAdsSearchads360V23CommonKeywordPlanDeviceSearches).optional()}); export const googleAdsSearchads360V23CommonConceptGroup = z.object({name: z.string().optional(), type: z.enum(["UNSPECIFIED", "UNKNOWN", "BRAND", "OTHER_BRANDS", "NON_BRAND"]).optional()}); export const googleAdsSearchads360V23CommonKeywordConcept = z.object({conceptGroup: googleAdsSearchads360V23CommonConceptGroup.optional(), name: z.string().optional()}); export const googleAdsSearchads360V23CommonKeywordAnnotations = z.object({concepts: z.array(googleAdsSearchads360V23CommonKeywordConcept).optional()}); export const googleAdsSearchads360V23CommonMonthlySearchVolume = z.object({month: z.enum(["UNSPECIFIED", "UNKNOWN", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]).optional(), monthlySearches: z.string().optional(), year: z.string().optional()}); export const googleAdsSearchads360V23CommonKeywordPlanHistoricalMetrics = z.object({averageCpcMicros: z.string().optional(), avgMonthlySearches: z.string().optional(), competition: z.enum(["UNSPECIFIED", "UNKNOWN", "LOW", "MEDIUM", "HIGH"]).optional(), competitionIndex: z.string().optional(), highTopOfPageBidMicros: z.string().optional(), lowTopOfPageBidMicros: z.string().optional(), monthlySearchVolumes: z.array(googleAdsSearchads360V23CommonMonthlySearchVolume).optional()}); export const googleAdsSearchads360V23ServicesGenerateKeywordIdeaResult = z.object({closeVariants: z.array(z.string()).optional(), keywordAnnotations: googleAdsSearchads360V23CommonKeywordAnnotations.optional(), keywordIdeaMetrics: googleAdsSearchads360V23CommonKeywordPlanHistoricalMetrics.optional(), text: z.string().optional()}); export const googleAdsSearchads360V23ServicesGenerateKeywordIdeaResponse = z.object({aggregateMetricResults: googleAdsSearchads360V23CommonKeywordPlanAggregateMetricResults.optional(), nextPageToken: z.string().optional(), results: z.array(googleAdsSearchads360V23ServicesGenerateKeywordIdeaResult).optional(), totalSize: z.string().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 }; /** * Returns a list of keyword ideas. List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CollectionSizeError]() [HeaderError]() [InternalError]() [KeywordPlanIdeaError]() [QuotaError]() [RequestError]() * * POST /v23/customers/{customersId}:generateKeywordIdeas */ export const createApiV23CustomersCustomersIdGenerateKeywordIdeas = async (args: CreateApiV23CustomersCustomersIdGenerateKeywordIdeasArgs, options?: CreateApiV23CustomersCustomersIdGenerateKeywordIdeasOptions) => { const {baseUrl = "https://searchads360.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v23/customers/${encodeURIComponent(String(args.customersId))}:generateKeywordIdeas${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(googleAdsSearchads360V23ServicesGenerateKeywordIdeaResponse, await res.json()) };