HOME / COMMUNITY Switch to knowledge base

Google app script accessing the API

Hi I am using Google’s App Script in a google sheet. I am trying to access the https://api.quickfile.co.uk/1_2/Bank/Search url but I need help with my syntax I think.

function getBankDetails(){

  var smn = "11";
  var accNum = "????????????";

  var hash = MD5(accNum+"???????????????????"+smn, false);

  var options = {
  "method" : "post",
  "muteHttpExceptions": true,
  "payload": {
    "Header": {
      "MessageType": "Request",
      "SubmissionNumber": "00000001",
      "Authentication": {
        "AccNumber": "123456",
        "MD5Value": hash,
        "ApplicationID": "appID"
      }
    },
    "Body": {
      "SearchParameters": {
        "ReturnCount": "10",
        "Offset": "0",
        "OrderResultsBy": "TransactionDate",
        "OrderDirection": "ASC",
        "NominalCode": "1200"
      }
    }
  }
};

  
  var response = UrlFetchApp.fetch("https://api.quickfile.co.uk/1_2/bank/search", options);


  var json = response.getContentText();
  Logger.log(json);
  //var bankdata = JSON.parse(json);

}

This it where im stuck. Ive tested the MD5 with the example in the documentation and that is correct.

The Error that I am getting is

{"Errors":{"Error":["Internal Error: Unexpected character encountered while parsing value: H. Path '', line 0, position 0."]}}

I am assuming I have not got the payload syntax correct.

If anyone can let me know the syntax?
Thanks very much

Hi @Vegas

I’m not familiar with Google App Script, but looked at it, it does seem that the payload is incorrect.

As you’re defining settings here, I’m assuming that the content of payload is sent to QuickFile?

If that’s the case, the payload part needs to be part of the payload itself. So what we need to be receiving is:

etc.

There’s an example of what we should be receiving, along with an example response, in the documentation under “JSON”: Bank_Search API Schema

Hope that helps!

Thanks very much your post helped me crack this. For future reference:

function getBankDetails() {

  var smn = "16";
  var accNum = "???????????????";

  var hash = MD5(accNum + "?????????????????" + smn, false);

  var payload = {
    "payload": {
      "Header": header = {
        "MessageType": "Request",
        "SubmissionNumber": smn,
        "Authentication": auth = {
          "AccNumber": accNum,
          "MD5Value": hash,
          "ApplicationID": "???????????????????"
        }

      },
      "Body": {
        "SearchParameters": {
          "ReturnCount": "10",
          "Offset": "0",
          "OrderResultsBy": "TransactionDate",
          "OrderDirection": "ASC",
          "NominalCode": "1200"
        }
      }
    }
  }

  var options = {
    "method": "post",
    "muteHttpExceptions": true,
    "payload": JSON.stringify(payload)
  };

  var response = UrlFetchApp.fetch("https://api.quickfile.co.uk/1_2/bank/search", options);


  var json = response.getContentText();
  Logger.log(json);
  var bankdata = JSON.parse(json);

}
2 Likes