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
Mitchblue006
Advocate I
Advocate I

List Generate in advanced editor

Hi everyone

 

I am receiving errors in syntax when I try loop my scroll ID through my base url, I guess I should paste the screenshot, however the error seems to be at the end...

    each [data]
)

what other syntax will allow this query to run?

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Mitchblue006 

 

Authorization should be sent as part of a Headers record e.g.

 

data= Json.Document(Web.Contents(api_url,
   [ 
     Headers = [#"Authorization"=EncodedCredentials]
   ]
   )
   )

 

Typically the Auth credentials would be encoded before sending too, something like this

    ClientID = "xxxxxxxx",
    Secret = "xxxxxxxx",
    
    EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),

 

Apart from this I don't get any other syntax errors in the code.

 

This article has info and examples of connecting to an API that requires authentication

 

Connecting to an OAuth API Like PayPal With Power Query • My Online Training Hub 

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

7 REPLIES 7
v-henryk-mstf
Community Support
Community Support

Hi @Mitchblue006 ,

 

Whether the advice given by @PhilipTreacy  has solved your confusion, if the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.


Looking forward to your feedback.


Best Regards,
Henry

Unfortunately, the solution had not solved the problem, the authorization in M language was one issue, and don't know how else to authenticate API keys other than the PayPal example, still trying to solve problem of recursive API calls in M query

Hi @Mitchblue006 

 

Please explain what the issue you are now facing is.  You mention recursion but I'm guessing you are trying to call an API repeatedly to get several pages of data?

 

If you can provide as much detail as possible that'll help.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Philip, you have helped me realize how to write M Query with the authentication keys, but my problem is actually the recursive API call problem...

 

I tried the following which has been featured on the community...

let
    Source = List.Generate(
    () => [ data = Json.Document(Web.Contents("https://api.paystack.co/subscription/?perPage=100&page=1",[Authorization = [bearer sk_live_***]]), 
            ScrollID = "subscription_code"
          ],

    each [ScrollID] < "null" ,  // What is the condition to terminate the loop ?

    each [ ScrollID = [data][ScrollID], data = Json.Document(Web.Contents("https://api.paystack.co/subscription/?perPage=100&page=1&scrollid="&[ScrollID], [Authorization = [sk_live_***]])) ],

    each [data]
)
in
    Source

The issue is that I am able to call this query in simple web connection, but 'cancelled date' is missing, so the advice from Paystack admin was to call each [subscription/sub_code] recursively, because the power query would not know what the parameter is without the first call, therefore the above code tries to insert the text that will call the subsequent API call to generate 'cancelled date'...I am sending you screenshots showing you the API call results when called individually...

 

Mitchblue006_0-1664798074705.png

Then, as you can see, there is no "cancelledAt" which is the result I need!

Now it only shows on subsequent call, on item 15...

Mitchblue006_1-1664798203454.png

Hope that makes sense! 

I need subsequent API call to list all these results, and I am struggling with M query.

PhilipTreacy
Super User
Super User

Hi @Mitchblue006 

 

Authorization should be sent as part of a Headers record e.g.

 

data= Json.Document(Web.Contents(api_url,
   [ 
     Headers = [#"Authorization"=EncodedCredentials]
   ]
   )
   )

 

Typically the Auth credentials would be encoded before sending too, something like this

    ClientID = "xxxxxxxx",
    Secret = "xxxxxxxx",
    
    EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),

 

Apart from this I don't get any other syntax errors in the code.

 

This article has info and examples of connecting to an API that requires authentication

 

Connecting to an OAuth API Like PayPal With Power Query • My Online Training Hub 

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Mitchblue006
Advocate I
Advocate I

l

let
    Source = List.Generate(
    () => [ data = Json.Document(Web.Contents("https://api.paystack.co/subscription/?perPage=100&page=1",[Authorization = [sk_live_***]]), 
            ScrollID = "subscription_code"
          ],

    each [ScrollID] < "null" ,  // What is the condition to terminate the loop ?

    each [ ScrollID = [data][ScrollID], data = Json.Document(Web.Contents("https://api.paystack.co/subscription/?perPage=100&page=1&scrollid="&[ScrollID], [Authorization = [sk_live_***]])) ],

    each [data]
)
in
    Source
PhilipTreacy
Super User
Super User

Hi @Mitchblue006 

Sorry, can't debufg this without the code, please supply the file with your code.

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.