Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JasperNL
Regular Visitor

Cursor API that has to feed back its own data

Hello. Im working on a dashboard that pulls sensordata from an API. However, I'm struggeling to understand how this API expects me to handle its calls as i have not seen anything like this before.

The documentation describes the following:

 

Get a Batch of New Samples

Returns all the samples since the last delivered sample id, from all streams to which the client has access. sampleID and backfillHours are mutually exclusive; if you define both, backfillHours is ignored. If neither is defined, the API returns a batch of samples since its internal last delivered sample id.

The recommended use of this API is as follows:

1. The first time you call this API, specify a sampleID or backfillHours to define the starting point from which to provide the batch of samples. In addition, set enableAck to true so that the system will not update its internal last delivered sample id field based on the last sample sent in this batch.
2. After each getSamplesBatch call, call ackSamplesBatch to set the internal `last delivered sample id.

3. In all getSamplesBatch calls except the first one, do not specify a sampleID or backfillHours.

If the batch consists of over 10,000 samples, it is broken down into chunks of no more than 10,000 samples each, sent consecutively. The hasMore return flag indicates whether a given chunk is the last chunk.

Note that samples are not sent in chronological order. You may receive a sample from today followed by a sample from yesterday, depending on when each device transmitted its data.

 

GetAck: https://XXXXXXXX/batch/ack?id=&agent=

GetSample: https://XXXXXXX/batch?enableAck=&sampleID=&backfillHours=

 

So, basically, i have to call the API for the first time with parameters and after that, I have to check wether the hasMore flag returns true and if so, pull out the last SampleID from the data, feed it to the acklink and call the getsample api again without any parameters and continue looping this until the hasMore flag returns False.

I'm quite new to M-code so i think i lack the knowledge of how to handle this best.


So far i have this. It returns an error. I use parameters for the headers:

 

let
GetPage2 = (id as text) =>
let
Ack = Web.Contents("https://XXXXX/batch/ack?sampleId=" & id & "&agent=",
[Headers = [#"Authorization"=#"Get Security Key"]]),

data = Web.Contents("https://XXXXX/batch?enableAck=false&sampleID=&backfillHours=",
[Headers = [#"Authorization"=#"Get Security Key"]]),
result = Json.Document(data),
hasmore = result[hasMore],
samples = result[samples],
samples1 = List.Last(samples),
id = samples1[id],
pages = List.Combine(result,lijst),
continue =
if hasmore = "TRUE"
then @GetPage2(id)
else pages
in
continue,

data = Web.Contents("https://XXXXX/batch?enableAck=false&sampleID=&backfillHours=168",
[Headers = [#"Authorization"=#"Get Security Key"]]),
lijst= Json.Document(data),
hasmore = lijst[hasMore],
samples = lijst[samples],
samples1 = List.Last(samples),
id = Text.From(samples1[id]),
Complete = @GetPage2(id)
in
Complete

 

4 REPLIES 4
v-janeyg-msft
Community Support
Community Support

@JasperNL  Any updates?

v-janeyg-msft
Community Support
Community Support

Hi, @JasperNL 

 

Can you authenticate successfully? What is the error message?

You can follow the steps:

Call Power BI Rest API with Dynamic Access Token From Power BI Desktop |Power BI Rest API | Part Two...

Hope it helps.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

The error i get now happens when the last line (Complete = @Getpage2(id)) tries to call the function.

The error reads:

 

Expression.Error: 2 arguments were passed to a function that expects 1.
Details:
Pattern=
Arguments=[List]

Hi,  @JasperNL 

 

You should check if there may be multiple results here. It may cause errors.

vjaneygmsft_1-1623999177084.png

For your question, few people actually understand this aspect, so it may be difficult to help you.

 

Best Regards

Janey Guo

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.