API fetch inconsistency

Issue Description:

Current Behavior
When fetching product details via the Square API, we observe inconsistent results between localhost and the Vercel-deployed environment. Specifically:

  • On localhost, the image_ids field in the response includes all associated images (e.g., two images for a product).
  • On Vercel, the image_ids field returns only one image, even when additional images were recently added.

Expected Behavior
The image_ids field should consistently return all associated images for a product across both environments, ensuring data uniformity.


Steps to Reproduce:

  1. Deploy the API endpoint to Vercel.
  2. Fetch product details for a specific product using the following API route:
    https://connect.squareup.com/v2/catalog/object/{product_id}
    
  3. Compare the image_ids field in the JSON response between localhost and the Vercel deployment.

Example Response Discrepancy:

  • Localhost:
    "image_ids": ["img_1", "img_2"]
    
  • Vercel:
    "image_ids": ["img_1"]
    

Configuration and Environment Details:

  • Project URL: [Your Project URL]

  • Framework: Next.js

  • Environment:

    • Localhost: Node.js version [Your Local Version]
    • Vercel: Node.js version [Configured on Vercel]
  • Square API Endpoint Used:
    GET /v2/catalog/object/{id}


Code Snippet:

Below is the relevant code used to fetch the product data:

const response = await fetch(`https://connect.squareup.com/v2/catalog/object/${id}`, {
    method: 'GET',
    headers: {
        'Authorization': `Bearer ${process.env.SQUARE_ACCESS_TOKEN}`,
        'Content-Type': 'application/json',
    },
});
const data = await response.json();

Troubleshooting Done:

  1. Confirmed that the API endpoint works as expected in a local environment.
  2. Verified that the process.env.SQUARE_ACCESS_TOKEN is correctly configured and accessible in both environments.
  3. Reproduced the issue consistently, ruling out transient API issues.

Hypothesis:

The issue may stem from:

  • API response caching or rate-limiting behavior on Vercel.
  • Differences in environment settings (e.g., headers, middleware, or proxy configurations).
  • A potential bug in how the Vercel deployment interacts with Square’s API.

Request:

Please advise on debugging steps or potential fixes for ensuring consistent API responses between local and deployed environments. Additionally, let us know if there are any specific Vercel-related configurations or settings that might influence this behavior.

Hey, welcome to the Vercel Community!

The issue you have reported appears to be due to data caching. Vercel Data cache is automatically enabled for you when you deploy a Next.js project thats uses App Router and Next.js Cache to Vercel. To invalidate the cache, you can use any of the revalidation methods mentioned here - Vercel Data Cache

You can also delete all cached data from your dashboard - Managing Vercel Data Cache

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.