facebook/facebook-nodejs-business-sdk

GET Requests to Facebook API Failing with Unknown Error, While POST/UPDATE Requests Work

Closed this issue · 1 comments

Title: GET Requests to Facebook API Failing with Unknown Error, While POST/UPDATE Requests Work


Description:

We are experiencing an issue with our Facebook API integration using the facebook-nodejs-business-sdk. Specifically, all GET requests to fetch data are failing with an "Unknown Error" (status code 500), while POST and UPDATE requests (such as creating and updating campaigns) are functioning normally.

Environment:

  • SDK: facebook-nodejs-business-sdk
  • API Version: v20.0
  • Platform: Node.js
  • Runtime Environment: Production
  • Access Token Permissions:
    • ads_management
    • ads_read
    • Additional permissions for campaign and ad management

Steps to Reproduce:

  1. Initialize Facebook SDK with the access token:

    FacebookAdsApi.init(accessToken);
  2. Attempt to fetch a campaign using its ID:

    async getCampaign(campaignId) {
      try {
        const result = await new Campaign(campaignId).get(['id', 'name'], {
          data_preset: 'data_maximum',
        });
        console.log('Campaign data:', result);
        return result;
      } catch (error) {
        console.error('Error fetching campaign:', error.message);
        console.error('Response data:', error.response?.data);
        console.error('Response headers:', error.response?.headers);
        console.error('Error configuration:', error.config);
      }
    }
  3. Observe the error returned:

    Error: 
        at FacebookRequestError.FacebookError [as constructor] 
        at new FacebookRequestError 
        at .../node_modules/facebook-nodejs-business-sdk/dist/api.js:153:15
        at processTicksAndRejections (node:internal/process/task_queues:95:5) {
      message: 'An unknown error has occurred.',
      status: 500,
      response: {
        message: 'An unknown error has occurred.',
        type: 'OAuthException',
        code: 1,
        fbtrace_id: 'AFqA64683bN-UqgjJ9WS1Qv'
      },
    }
    

Expected Behavior:

  • GET requests should return the campaign data without errors if the provided campaign ID and access token are valid.

Observed Behavior:

  • GET requests consistently fail with a 500 status code and the message: "An unknown error has occurred."
  • POST and UPDATE requests (e.g., creating and updating campaigns) work as expected, which confirms that the access token is valid and has the correct permissions.

Troubleshooting Steps Taken:

  1. Checked Access Token:

    • Confirmed that the access token is valid and has the necessary permissions (ads_read, ads_management).
    • Verified that the token works in Graph Explorer and Postman for GET requests with the same URL.
  2. API Versioning:

    • Ensured that the SDK and Graph API version are consistent (v20.0).
  3. Rate Limits:

    • Checked the headers (x-app-usage, x-ad-account-usage) for any signs of rate limiting. No rate limits were hit during the requests.
  4. Error Handling:

    • Implemented detailed logging to capture the response, headers, and configuration of the request.
    • Verified no obvious misconfigurations in the API call setup.
  5. Tested in Different Environments:

    • Confirmed the same behavior in both development and production environments.

Additional Details:

  • Error responses contain a Facebook trace ID (fbtrace_id), but no further useful information.
  • The same request works in Graph API Explorer and Postman, indicating no network or configuration issues.

Impact:

  • This issue prevents us from fetching data, impacting our ability to manage and display campaign details correctly.
  • The GET requests are critical for reporting and monitoring purposes, and the inability to fetch data significantly hampers our operations.

Request for Assistance:

  • Guidance on why GET requests are failing while POST/UPDATE requests work.
  • Confirmation if there are known issues with the current SDK version (facebook-nodejs-business-sdk) or API version (v20.0).
  • Any recommended workarounds or steps to further debug and resolve this problem.

Thank You:

Thank you for reviewing this issue. Any assistance or insights would be greatly appreciated as this is a blocking issue for our team.

Why was this issue closed? How did you fix it?