Forum Discussion
REST API Call with Cookie Session ID
- 1 year ago
About fields:
Since you didn't provide complete documentation, I can't give you a more accurate answer. Based on my previous experience, it may be used in the following way:
// Step 2: Call the ct-results API to get Job ID GetJobId = (mySessionId as text) as text => let ctResultsReq = Web.Contents("https://mycompany-wfm.nicecloudsvc.com/SMARTSync/services/rs/exporters/v1/ct-results", [ Headers = [ Cookie = "JSESSIONID=" & mySessionId, #"Content-Type"="application/json" ], Content=Json.FromValue([ startDate = STARTDATE, endDate = ENDDATE, outputFormat = "PIPE", dateFormat = "mmddyyyy", timeFormat = 24, ctIds = Text.Split(CTIDS, ",") // This is an array object, it should be surrounded by []. fields = "[{""name"":""date""},{""name"":""period""},{""name"":""ctID""},{""name"":""ctName""},{""name"":""actContactsReceived""}]" ]) ]), ctResultsJson = Json.Document(ctResultsReq), jobId = ctResultsJson[jobId] in jobIdI think you should read the documentation about fields carefully and try to solve it.
About loops:
Since I am not familiar with the workflow of the server, I cannot tell you exactly what to do. I guess the possible problem is that your data volume is large, which takes longer time, and you need to add loops to perform multiple accesses. Perhaps you can refer to the following code (if you don't have a better code):
let // An example function GetData = (arg) => Number.Random(), // Example function parameters, maximum number of retries, interval between each retry (default 5 seconds) fx = (arg, MaxCount, optional sec) => List.Accumulate( {1..MaxCount}, [status = false, result = null], (s, v) => // If status is true, the program will loop again, but without delay. if s[status] then s else let r1= Function.InvokeAfter(() => GetData(arg), #duration(0, 0, 0, sec ?? 5)), // If the result meets the requirements, set status to true and get the result r2 = if r1 <= 0.1 then [status = true, result = r1] else s in r2 ) in fx("arg_test", 3)
About fields:
Since you didn't provide complete documentation, I can't give you a more accurate answer. Based on my previous experience, it may be used in the following way:
// Step 2: Call the ct-results API to get Job ID
GetJobId = (mySessionId as text) as text =>
let
ctResultsReq = Web.Contents("https://mycompany-wfm.nicecloudsvc.com/SMARTSync/services/rs/exporters/v1/ct-results", [
Headers = [
Cookie = "JSESSIONID=" & mySessionId,
#"Content-Type"="application/json"
],
Content=Json.FromValue([
startDate = STARTDATE,
endDate = ENDDATE,
outputFormat = "PIPE",
dateFormat = "mmddyyyy",
timeFormat = 24,
ctIds = Text.Split(CTIDS, ",")
// This is an array object, it should be surrounded by [].
fields = "[{""name"":""date""},{""name"":""period""},{""name"":""ctID""},{""name"":""ctName""},{""name"":""actContactsReceived""}]"
])
]),
ctResultsJson = Json.Document(ctResultsReq),
jobId = ctResultsJson[jobId]
in
jobId
I think you should read the documentation about fields carefully and try to solve it.
About loops:
Since I am not familiar with the workflow of the server, I cannot tell you exactly what to do. I guess the possible problem is that your data volume is large, which takes longer time, and you need to add loops to perform multiple accesses. Perhaps you can refer to the following code (if you don't have a better code):
let
// An example function
GetData = (arg) =>
Number.Random(),
// Example function parameters, maximum number of retries, interval between each retry (default 5 seconds)
fx = (arg, MaxCount, optional sec) =>
List.Accumulate(
{1..MaxCount},
[status = false, result = null],
(s, v) =>
// If status is true, the program will loop again, but without delay.
if s[status] then s
else
let
r1= Function.InvokeAfter(() => GetData(arg), #duration(0, 0, 0, sec ?? 5)),
// If the result meets the requirements, set status to true and get the result
r2 = if r1 <= 0.1 then [status = true, result = r1] else s
in
r2
)
in
fx("arg_test", 3)
Thank you so much. You were a great help!