I am trying to pass an object to my API but it keeps showing the object as NULL in the API.
My Ajax call:
$.ajax({
type: "GET",
url: url,
data: tranData,
dataType: "json",
success: function(response){
var itemcount = response.itemsCount;
var dataReturned = response.data;
}});
My API Method:
[HttpGet]
[Route("Api/ReportApi/SummaryReport")]
public IHttpActionResult SummaryReport(JObject tranData)
{
dynamic oData = tranData;
BankTransactionsViewModelResults transactions = new BankTransactionsViewModelResults();
transactions = oData;
var summarisedTransactions = SummariseResults(transactions.BankTransactionsViewModelList, "Test Ref");
var response = new
{
data = summarisedTransactions,
itemsCount = summarisedTransactions.Count(),
};
return Request.GetOKRequest(response);
}
The object I am trying to pass:
[{"id":16,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"DEPOSIT","reference":"TEST10a","description":"TEST10d","amount":600000.0,"balance":600000.0,"tranDate":1494374400000},
{"id":17,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"WITHDRAWAL","reference":"TEST10b","description":"TEST10d","amount":-400000.0,"balance":200000.0,"tranDate":1494460800000},
{"id":18,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"DEPOSIT","reference":"TEST10c","description":"TEST10c","amount":700000.0,"balance":900000.0,"tranDate":1494547200000},
{"id":19,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"TRANSFER","reference":"TEST10d","description":"TEST10d","amount":-600000.0,"balance":300000.0,"tranDate":1494633600000},
{"id":20,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"DEPOSIT","reference":"TEST10e","description":"TEST10e","amount":800000.0,"balance":1100000.0,"tranDate":1494720000000},
{"id":21,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"WITHDRAWAL","reference":"TEST10f","description":"TEST10f","amount":-800000.0,"balance":300000.0,"tranDate":1494806400000},
{"id":22,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"DEPOSIT","reference":"TEST10g","description":"TEST10g","amount":900000.0,"balance":1.2E7,"tranDate":1494892800000},
{"id":23,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"TRANSFER","reference":"TEST10h","description":"TEST10h","amount":-400000.0,"balance":800000.0,"tranDate":1494979200000},
{"id":24,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"DEPOSIT","reference":"TEST10i","description":"TEST10i","amount":800000.0,"balance":1.6E7,"tranDate":1495065600000},
{"id":25,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"TRANSFER","reference":"TEST10j","description":"TEST10j","amount":-800000.0,"balance":800000.0,"tranDate":1495152000000},
{"id":26,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"DEPOSIT","reference":"TEST10k","description":"TEST10k","amount":900000.0,"balance":1.7E7,"tranDate":1495238400000},
{"id":27,"accountId":11111000010,"clientId":1,"agentId":1,"tranType":"WITHDRAWAL","reference":"TEST10l","description":"TEST10l","amount":-700000.1,"balance":0.0,"tranDate":1495324800000}]
How can I pass this to my API? tranData
is appearing as null but before being sent I can see the data is there...? I get this data from an external API call and get it from the response:
var tranData = JSON.parse(req.response);