export type PriceAmount = {value?: string | undefined, currency?: string | undefined}; export type TimePeriod = {endTime?: unknown | undefined, startTime?: unknown | undefined}; export type PromotionPromotionStatusPromotionIssue = {code?: string | undefined, detail?: string | undefined}; export type PromotionPromotionStatusDestinationStatus = {destination?: string | undefined, status?: ('STATE_UNSPECIFIED' | 'IN_REVIEW' | 'REJECTED' | 'LIVE' | 'STOPPED' | 'EXPIRED' | 'PENDING') | undefined}; export type PromotionPromotionStatus = {creationDate?: string | undefined, promotionIssue?: Array | undefined, lastUpdateDate?: string | undefined, destinationStatuses?: Array | undefined}; export type Promotion = {productApplicability?: ('PRODUCT_APPLICABILITY_UNSPECIFIED' | 'ALL_PRODUCTS' | 'SPECIFIC_PRODUCTS') | undefined, itemIdExclusion?: Array | undefined, brandExclusion?: Array | undefined, longTitle?: string | undefined, limitQuantity?: number | undefined, storeApplicability?: ('STORE_APPLICABILITY_UNSPECIFIED' | 'ALL_STORES' | 'SPECIFIC_STORES') | undefined, contentLanguage?: string | undefined, itemGroupId?: Array | undefined, itemGroupIdExclusion?: Array | undefined, moneyBudget?: PriceAmount | undefined, targetCountry?: string | undefined, promotionEffectiveDates?: string | undefined, promotionUrl?: string | undefined, id?: string | undefined, shippingServiceNames?: Array | undefined, productType?: Array | undefined, brand?: Array | undefined, moneyOffAmount?: PriceAmount | undefined, percentOff?: number | undefined, promotionDisplayDates?: string | undefined, promotionDestinationIds?: Array | undefined, freeGiftItemId?: string | undefined, storeCode?: Array | undefined, itemId?: Array | undefined, minimumPurchaseAmount?: PriceAmount | undefined, promotionDisplayTimePeriod?: TimePeriod | undefined, genericRedemptionCode?: string | undefined, redemptionChannel?: (Array<'REDEMPTION_CHANNEL_UNSPECIFIED' | 'IN_STORE' | 'ONLINE'>) | undefined, minimumPurchaseQuantity?: number | undefined, orderLimit?: number | undefined, customRedemptionRestriction?: string | undefined, maxDiscountAmount?: PriceAmount | undefined, getThisQuantityDiscounted?: number | undefined, storeCodeExclusion?: Array | undefined, redemptionRestriction?: ('REDEMPTION_RESTRICTION_UNSPECIFIED' | 'SUBSCRIBE_AND_SAVE' | 'FIRST_ORDER' | 'SIGN_UP_FOR_EMAIL' | 'SIGN_UP_FOR_TEXT' | 'FORMS_OF_PAYMENT' | 'CUSTOM') | undefined, freeGiftValue?: PriceAmount | undefined, freeGiftDescription?: string | undefined, promotionEffectiveTimePeriod?: TimePeriod | undefined, offerType?: ('OFFER_TYPE_UNSPECIFIED' | 'NO_CODE' | 'GENERIC_CODE') | undefined, productTypeExclusion?: Array | undefined, couponValueType?: ('COUPON_VALUE_TYPE_UNSPECIFIED' | 'MONEY_OFF' | 'PERCENT_OFF' | 'BUY_M_GET_N_MONEY_OFF' | 'BUY_M_GET_N_PERCENT_OFF' | 'BUY_M_GET_MONEY_OFF' | 'BUY_M_GET_PERCENT_OFF' | 'FREE_GIFT' | 'FREE_GIFT_WITH_VALUE' | 'FREE_GIFT_WITH_ITEM_ID' | 'FREE_SHIPPING_STANDARD' | 'FREE_SHIPPING_OVERNIGHT' | 'FREE_SHIPPING_TWO_DAY') | undefined, limitValue?: PriceAmount | undefined, promotionId?: string | undefined, promotionStatus?: PromotionPromotionStatus | undefined}; export type CreateApiMerchantIdPromotionsArgs = {merchantId: string, body: Promotion}; export type CreateApiMerchantIdPromotionsOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; /** * Inserts a promotion for your Merchant Center account. If the promotion already exists, then it updates the promotion instead. To [end or delete] (https://developers.google.com/shopping-content/guides/promotions#end_a_promotion) a promotion update the time period of the promotion to a time that has already passed. * * POST /{merchantId}/promotions */ export const createApiMerchantIdPromotions = async (args: CreateApiMerchantIdPromotionsArgs, options?: CreateApiMerchantIdPromotionsOptions) => { const {baseUrl = "https://shoppingcontent.googleapis.com/content/v2.1", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.merchantId))}/promotions${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 res.blob() };