import {z} from 'zod' export type GoogleAdsSearchads360V23CommonKeywordInfo = {matchType?: ('UNSPECIFIED' | 'UNKNOWN' | 'EXACT' | 'PHRASE' | 'BROAD') | undefined, text?: string | undefined}; export type GoogleAdsSearchads360V23ServicesBiddableKeyword = {keyword?: GoogleAdsSearchads360V23CommonKeywordInfo | undefined, maxCpcBidMicros?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesForecastAdGroup = {biddableKeywords?: Array | undefined, maxCpcBidMicros?: unknown | undefined, negativeKeywords?: Array | undefined}; export type GoogleAdsSearchads360V23ServicesManualCpcBiddingStrategy = {dailyBudgetMicros?: unknown | undefined, maxCpcBidMicros?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesMaximizeClicksBiddingStrategy = {dailyTargetSpendMicros?: unknown | undefined, maxCpcBidCeilingMicros?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesMaximizeConversionsBiddingStrategy = {dailyTargetSpendMicros?: unknown | undefined}; export type GoogleAdsSearchads360V23ServicesCampaignToForecastCampaignBiddingStrategy = {manualCpcBiddingStrategy?: GoogleAdsSearchads360V23ServicesManualCpcBiddingStrategy | undefined, maximizeClicksBiddingStrategy?: GoogleAdsSearchads360V23ServicesMaximizeClicksBiddingStrategy | undefined, maximizeConversionsBiddingStrategy?: GoogleAdsSearchads360V23ServicesMaximizeConversionsBiddingStrategy | undefined}; export type GoogleAdsSearchads360V23ServicesCriterionBidModifier = {bidModifier?: number | undefined, geoTargetConstant?: string | undefined}; export type GoogleAdsSearchads360V23ServicesCampaignToForecast = {adGroups?: Array | undefined, biddingStrategy?: GoogleAdsSearchads360V23ServicesCampaignToForecastCampaignBiddingStrategy | undefined, conversionRate?: number | undefined, geoModifiers?: Array | undefined, keywordPlanNetwork?: ('UNSPECIFIED' | 'UNKNOWN' | 'GOOGLE_SEARCH' | 'GOOGLE_SEARCH_AND_PARTNERS') | undefined, languageConstants?: Array | undefined, negativeKeywords?: Array | undefined}; export type GoogleAdsSearchads360V23CommonDateRange = {endDate?: string | undefined, startDate?: string | undefined}; export type GoogleAdsSearchads360V23ServicesGenerateKeywordForecastMetricsRequest = {campaign?: GoogleAdsSearchads360V23ServicesCampaignToForecast | undefined, currencyCode?: string | undefined, forecastPeriod?: GoogleAdsSearchads360V23CommonDateRange | undefined}; export type CreateApiV23CustomersCustomersIdGenerateKeywordForecastMetricsArgs = {customersId: string, body: GoogleAdsSearchads360V23ServicesGenerateKeywordForecastMetricsRequest}; export type CreateApiV23CustomersCustomersIdGenerateKeywordForecastMetricsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleAdsSearchads360V23ServicesKeywordForecastMetrics = z.object({averageCpaMicros: z.string().optional(), averageCpcMicros: z.string().optional(), clickThroughRate: z.number().optional(), clicks: z.number().optional(), conversionRate: z.number().optional(), conversions: z.number().optional(), costMicros: z.string().optional(), impressions: z.number().optional()}); export const googleAdsSearchads360V23ServicesGenerateKeywordForecastMetricsResponse = z.object({campaignForecastMetrics: googleAdsSearchads360V23ServicesKeywordForecastMetrics.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 metrics (such as impressions, clicks, total cost) of a keyword forecast for the given campaign. List of thrown errors: [AuthenticationError]() [AuthorizationError]() [CollectionSizeError]() [HeaderError]() [InternalError]() [QuotaError]() [RequestError]() * * POST /v23/customers/{customersId}:generateKeywordForecastMetrics */ export const createApiV23CustomersCustomersIdGenerateKeywordForecastMetrics = async (args: CreateApiV23CustomersCustomersIdGenerateKeywordForecastMetricsArgs, options?: CreateApiV23CustomersCustomersIdGenerateKeywordForecastMetricsOptions) => { 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))}:generateKeywordForecastMetrics${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(googleAdsSearchads360V23ServicesGenerateKeywordForecastMetricsResponse, await res.json()) };