How to handle response?

Hello,
We are using below code in our app.js file:
function renderContactName() {
var textElement = document.getElementById('apptext');

  client.data.get('contact')
    .then(function getData(data) {
      var getContact = client.request.post("https://example.com/index.php?route=test/test", {
          body: JSON.stringify({
            id: data.contact.id,
          })
         });

  getContact.then(showContact).catch(handleErr);

  function showContact(payload) {
    var response = JSON.parse(payload.response);

    var html = '<b>' + response.contact.name + '</b>' + '<i>' + response.contact.id + '</i>';

    textElement.innerHTML = html;
  }
})
.catch(errorHandler);

}
The code was working earlier bit now it is calling our URL without id. So our questions are:

  1. Why id is not sent in request?
  2. We are not receiving the response?
  3. How to handle html response?
  4. How to handle json response with nested array?
    Any help will be appriciated.
    Thanks!
1 Like
  1. Can you please try sending any other data along with id just to ensure your service is not dropping it?
  2. Can you please elaborate a bit more?
  3. Requests made using the Request method should return String, JSON, or XML data type. So, you need to send HTML as XML response
  4. Can you please elaborate a bit more?
1 Like
  1. We have tried to send name, email etc but not working. Even our URL was called before but when we are testing now, even URL is not called.
  2. The response is second part of first query. When we send the request, some times URL is called but we are not receiving any response in our payload. We got the response few days before but same code is not working at all.
  3. We prefer to send the json response but was unable to get it. So is their doc, we find that we can send the text/html also. So we were trying to send html.
  4. Basically we will send the array of array converted to json by json_encode in php. For example we are trying to send the response:
    {“orders” : {“order_id” : 1}}
    Please let us know if you need any further details to help us.
1 Like
  1. Can you please try with some other url? May be like pastbin or ngrok?
  2. I suspect it is due to app code changes since interface or library had not modified from last few days

Can you please elaborate on this
4. I am not well versed with php. May be this will get fixed if the above points are fixed.

1 Like
  1. We have already tried with localohost, ngrok but not working.
  2. Are you asking us to update the library while running the fdk validate?
  3. We are sending the response in json.
  4. OK.
1 Like

Sorry for the late reply

  1. Can you please explain more on what is not working with ngrok? Is it not at all hitting ngrok endpoint or just id is not sent to ngrok?
  2. No. I mean nothing had changed from our side in this use case.
1 Like