Request Template not giving updated response

Hi Team,

I’ve been using a request template to make API call to a third-party service. The implementation seems to have worked without any issues for a while.
But recently the API response changed with updated details. The request method is still fetching the old request and not bringing in the updated response in the front-end application.

I invoked the template by disabling the cache as well but it doesn’t seem to work. Please refer to my code below.
Request Template

  "getOrderDetails": {
    "schema": {
      "protocol": "https",
      "method": "GET",
      "host": "batechinternal.com",
      "path": "/sellingpartner_ordertool/api/get_product.php?order_id=<%= context.order_id %>",
      "headers": {
        "Authorization": "Basic <%= iparam.key %>",
        "Content-Type": "application/json"
      }
    }
  },

Invoke Function

async function fetchOrderDetails(orderId) {
  try {
    let response = await client.request.invokeTemplate("getOrderDetails", {
      context: { orderId, cache: false },
    });
    let parsedResponse = JSON.parse(response.response);
    if (parsedResponse?.status !== "error") {
      return parsedResponse;
    }
  } catch (e) {
    console.log("Error in fetching order details : ", e);
  }
}

Kindly let me know if there is a solution for this. Thanks in advance :slightly_smiling_face:

Is this happening in production or local testing using FDK? It sounds like a caching issue because everything else looks alright. If it is local testing, can you try removing the local .fdk/ directory, setting up iparams again, and then testing it?

If it is production, I wonder if it might be due to browser cache.

1 Like

Hey @kaustavdm,

Thanks for your reply. Yes its happening in both the production and local testing.

In production i cleared all my session and local storage. But still im getting an old response from the third party API. I’m still trying find how this is occurring.

For local testing ill clear the .fdk file and try.

Then, could this be a cache on the 3rd party API’s end? Request method does not cache responses, so it will respond with what the external service responds with.

Actually, the application was already built using fdk version 8. Now after the planned upgrade to version 9 i’m facing this issue. I installed both the application and the older one is returning the correct response i had it verified with postman request as well.
Is there any way to debug this?

Hey @mohammed,
I suspect something with the browser’s cache.

However, I noticed something in invokeTemplate method

    let response = await client.request.invokeTemplate("getOrderDetails", {
      context: { orderId, cache: false },
    });

Are you setting the request method’s cache as false (which is the default value)? Then it should look like -

    let response = await client.request.invokeTemplate("getOrderDetails", {
      context: { orderId }, 
      cache: false
    });

Hey Jones,

Thanks for your reply.
I tried setting the cache as false as well. But didn’t seem to have worked for me. Is the cache in the request method set to true by default?
So I took the query to the client side and that seem to have worked for me.

"getOrderDetails": {
    "schema": {
      "protocol": "https",
      "method": "GET",
      "host": "batechinternal.com",
      "path": "/sellingpartner_ordertool/api/get_product.php?<%= context.query %>",
      "headers": {
        "Authorization": "Basic <%= iparam.key %>",
        "Content-Type": "application/json"
      }
    }
  },

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