Postman: (Get request time rely on server timezone)
Request: GET ->
https://<D365FO URL>/data/BatchJobs?$filter=Status eq Microsoft.Dynamics.DataEntities.BatchStatus'Executing' and StartDate eq {{currentdate}} and StartTime gt {{currentTime}} &cross-company=true
or
https://<D365FO URL>/data/RetailTransactions?$filter=ChannelReferenceId eq '' and CustomerAccount eq '' and TransactionDate eq 2022-08-23 &cross-company=true
Pre-Request script:
var moment = require('moment');
pm.globals.set('currentdate', moment().format(("YYYY-MM-DD")));
pm.globals.set("currentTime", new Date().setTime(new Date().getTime()-10800)); (As per postman installed machine time Zone GMT)
//setting
postman.setEnvironmentVariable("currentdate", moment().format(("YYYY-MM-DD")));
Set Global variables:
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("access_token", jsonData.access_token);
Select field list
&$select=CustomerAccount,OrganizationName
Test samples:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
var json = JSON.parse(responseBody);
tests["<Collection request name>"] = !json.error && responseBody !== '' && responseBody !== '{}' && json.Id !== '';
postman.setEnvironmentVariable("<Global variable name>", json.AmountDue);
var json = JSON.parse(responseBody);
tests["<Collection request name>"] = !json.error && responseBody !== '' && responseBody !== '{}' && json.CartLines !== '';
postman.setEnvironmentVariable("<Global variable name>", json.CartLines[0].LineId);