From 5015dbb1e896ad24d4cb1335d2e2e2af8e6846f1 Mon Sep 17 00:00:00 2001 From: Gilad Resisi Date: Wed, 1 Jul 2026 22:11:53 +0700 Subject: [PATCH] fix(pinterest): keep analytics within the 90-day window Pinterest's analytics endpoints only serve the last 90 days (evaluated in UTC). postAnalytics requested a 2-year start_date, so Pinterest rejected the call every time and pin analytics were always empty. Clamp postAnalytics to 89 days back and cap the account-level analytics period at 89 days (89 avoids an off-by-one when the server's local date leads UTC). Co-Authored-By: Claude Fable 5 --- .../src/integrations/social/pinterest.provider.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts b/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts index a647f61e2d..078d64bc6d 100644 --- a/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts @@ -391,7 +391,10 @@ export class PinterestProvider date: number ): Promise { const until = dayjs().format('YYYY-MM-DD'); - const since = dayjs().subtract(date, 'day').format('YYYY-MM-DD'); + // Pinterest analytics only cover the last 90 days (89 for a UTC safety margin) + const since = dayjs() + .subtract(Math.min(date, 89), 'day') + .format('YYYY-MM-DD'); const { all: { daily_metrics }, @@ -456,8 +459,8 @@ export class PinterestProvider date: number ): Promise { const today = dayjs().format('YYYY-MM-DD'); - // Use a very long date range (2 years) to capture lifetime metrics for older posts - const since = dayjs().subtract(2, 'year').format('YYYY-MM-DD'); + // Pinterest only serves pin analytics for the last 90 days (89 for a UTC safety margin) + const since = dayjs().subtract(89, 'day').format('YYYY-MM-DD'); try { // Fetch pin analytics from Pinterest API