cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
krixtsup3r
Helper IV
Helper IV

Hand Authored Queries

 

Hi Can I ask for help in changing the query below to make it work for schedule refresh? I've been going around in the community and web but really can't find a fix for my problem. Thank you so much!

 

let
    baseuri = "https://app.asana.com/api/1.0/projects?limit=100&workspace=*****************&opt_fields=team,name,owner,current_status,due_on,start_on,created_at,modified_at,public,members,custom_fields,custom_field_settings,color,notes,html_notes,workspace,archived",
    headers = [Headers=[#"Content-Type"="application/json", Authorization="Bearer 1/**************************"]],

    initReq = Json.Document(Web.Contents("https://app.asana.com/api/1.0/projects?limit=100&workspace=*****************&opt_fields=team,name,owner,current_status,due_on,start_on,created_at,modified_at,public,members,custom_fields,custom_field_settings,color,notes,html_notes,workspace,archived", headers)),
    initData = initReq[data],
    gather = (data as list, uri) =>
        let
            newOffset = Json.Document(Web.Contents(uri, headers))[next_page][offset],
            newUri = baseuri & "&offset=" & newOffset,
            newReq = Json.Document(Web.Contents(newUri, headers)),
            newdata = newReq[data],
            data = List.Combine({data, newdata}),
            check = if newReq[next_page] = null then data else @gather(data, newUri)
        in check,
    outputList = if initReq[next_page] = null then initData else gather(initData, baseuri),
    expand = Table.FromRecords(outputList),
    
    #"Changed Type" = Table.TransformColumnTypes(expand,{{"created_at", type datetime}, {"modified_at", type datetime}, {"due_on", type date}, {"start_on", type date}}),
    #"Expanded team" = Table.ExpandRecordColumn(#"Changed Type", "team", {"gid"}, {"team.gid"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded team",{ "workspace"}),
    #"Expanded owner" = Table.ExpandRecordColumn(#"Removed Columns", "owner", {"gid"}, {"owner.gid"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded owner",{"current_status", "custom_fields", "custom_field_settings", "members", "html_notes",  "color"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"gid", "created_at", "modified_at", "start_on", "due_on", "name", "notes", "owner.gid", "team.gid"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"archived", type text}, {"public", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1","true","Yes",Replacer.ReplaceText,{"archived", "public"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","false","No",Replacer.ReplaceText,{"archived", "public"})
in
    #"Replaced Value1"

 

9 REPLIES 9
v-jingzhang
Community Support
Community Support

Hi @krixtsup3r 

 

In your gather function, below codes would create dynamic url. Maybe this is the cause.

newOffset = Json.Document(Web.Contents(uri, headers))[next_page][offset],
newUri = baseuri & "&offset=" & newOffset,

 

You could refer to Chris Webb's BI Blog: Web.Contents(), M Functions And Dataset Refresh Errors In Power BI

 (as well as other links in this blog directing to his previous blogs). Try using RelativePath and Query options with Web.Contents() to query data. Use a valid static URL as a base URL and put dynamic part in RelativePath or Query options. 

 

Hope this would be helpful.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

parry2k
Super User
Super User

@krixtsup3r check these posts

 

Power BI: Gateway Monitoring & Administrating- Par... - Microsoft Power BI Community

 

Solved: Refreshing data from REST API works on Desktop, fa... - Microsoft Power BI Community

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Not sure why but the gateway option  is not showing on my end.

krixtsup3r_0-1638753568132.png

 

parry2k
Super User
Super User

@krixtsup3r you need a gateway to make it work. Power BI Gateway | Microsoft Power BI

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Hi, I have a gateway. Not sure what you meant is there any set up that I need to do?

lbendlin
Super User
Super User

Are you getting a Formula.Firewall warning?  What's the error message?

Hi Im getting the following errors:

if in service:

krixtsup3r_0-1638745755190.png

 

if in desktop:

krixtsup3r_1-1638745776179.png

 

 

Set the privacy settings for the report to Ignore if that is acceptable.

It's already in ignore mode.

krixtsup3r_0-1638753763656.png

 

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors