1
votes

I have a JSON file that contains a query I am using to pull audit history data from Oracle. I need to be able to automate changing the fromDate and toDate parameters daily. I was thinking to create a powershell script and use: Get-Date -format "yyyy-MM-dd" as a variable, but not sure this is the best approach? My JSON file (Oracle.json) looks like this:

{
  "fromDate": "2019-04-18",
  "toDate": "2019-04-18",
  "product": "OPSS",
  "eventType": "RoleMembershipAdd"
}

I am then using curl to make the POST request and output the data to flat file:

curl.exe -i --user username:password -X POST -H "Content-Type: application/json" -d "@C:\Oracle.json" hxxps://someurl.com/fscmRestApi/fndAuditRESTService/audittrail/getaudithistory >> C:\Oracle.txt

What would be the best way to make the dates dynamic so I can have the script run daily and pull from that day without having to change the dates manually?

1

1 Answers

0
votes

I'd use a here string and directly insert the date:

$Json = @"
{
  "fromDate": "$(get-date -format "yyyy-MM-dd")",
  "toDate": "$(get-date -format "yyyy-MM-dd")",
  "product": "OPSS",
  "eventType": "RoleMembershipAdd"
}
"@ | ConvertFrom-Json | ConvertTo-Json -Compress

> $Json
"fromDate":"2019-04-23","toDate":"2019-04-23","product":"OPSS","eventType":"RoleMembershipAdd"}