yikart/AiToEarn · error · InstagramPlatformException

ChannelPlatformResponseInvalid

ChannelPlatformResponseInvalid

Error message

Failed to fetch permalink for media ${mediaId}

What it means

InstagramPublishProvider.fetchPermalink calls instagramService.getMediaInfo to read mediaInfo.permalink for a published IG media item. If the Graph API call fails or the response has no permalink, it logs 'Failed to fetch permalink for media <mediaId>' and throws InstagramPlatformException.validation with code ChannelPlatformResponseInvalid (category PlatformUnavailable, endpoint fetchPermalink). Raised via permalink(), typically after publishing to return the post URL.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/instagram/instagram-publish.provider.ts:492

            raw: lastStatus,
          },
          retryable: true,
        }),
      },
    )
  }

  private async fetchPermalink(
    accessToken: string,
    mediaId: string,
  ): Promise<string> {
    try {
      const mediaInfo = await this.instagramService.getMediaInfo(accessToken, mediaId)
      if (mediaInfo.permalink)
        return mediaInfo.permalink
    }
    catch (err) {
      this.logger.warn(err, `Failed to fetch permalink for media ${mediaId}`)
    }
    throw InstagramPlatformException.validation({
      code: ResponseCode.ChannelPlatformResponseInvalid,
      category: PlatformErrorCategory.PlatformUnavailable,
      context: {
        endpoint: 'fetchPermalink',
        platformWorkId: mediaId,
      },
    })
  }

  private isImage(media: PublishMediaInput): boolean {
    if (media.metadata?.type === PublishMediaType.Image)
      return true
    if (media.metadata?.type === PublishMediaType.Video)
      return false
    return hasUrlPathExtension(media.url, ['.jpg', '.jpeg'])
  }

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Retry after a short delay — permalink may not be available until Instagram finishes processing the just-published media.
  2. Reconnect the Instagram channel to refresh the access token; verify scopes include instagram_basic/instagram_manage_insights.
  3. Check the logged inner error for Graph API error_subcode and handle 190 (token invalid) via channel re-auth flow.
  4. If the media was deleted on Instagram, treat as permanent failure and surface a platform-unavailable message.

Example fix

// before: fetch immediately after publish
const url = await provider.permalink(mediaId) // media processing -> ChannelPlatformResponseInvalid
// after
await delay(30_000)
const url = await provider.permalink(mediaId)
Defensive patterns

Strategy: retry

Validate before calling

// Verify token validity before fetching permalink
const isValid = await instagramService.validateToken(accessToken)
if (!isValid) throw new Error('Instagram token expired; reconnect channel')

Type guard

function isInstagramPlatformException(e: unknown): e is InstagramPlatformException {
  return e instanceof InstagramPlatformException
}

Try / catch

async function permalinkWithRetry(provider, mediaId, attempts = 3) {
  for (let i = 0; i < attempts; i++) {
    try {
      return await provider.permalink(mediaId)
    } catch (e) {
      if (i === attempts - 1) throw e
      await new Promise(r => setTimeout(r, 30_000 * (i + 1))) // media may still be processing
    }
  }
}

Prevention

When it happens

Trigger: getMediaInfo returns an error (expired/insufficient-scope access token, IG account not linked to a FB page, media still processing and lacking permalink yet), the API responds without a permalink field, or a transient Graph API outage occurs.

Common situations: Long-lived token expired or user deauthorized the app; requesting permalink immediately after publish before Instagram finishes processing the media; IG professional account demoted/re-linked; Graph API partial outages.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/953ec7055b0b2aee. Report an issue: GitHub.