Forum Discussion

5AMsan's avatar
5AMsan
Frequent Visitor
3 years ago

Manage function (or table) parameters in Navigation Table

Hello,

I'm trying to add parameters to API calls. OAuth is working and I can generate a list of available datasets in a dynamic navigation table:

 

Here is the auth screen with no optional parameters, the one I want to appear in the screenshot above (in the right pane):

 

Now I can't figure out how to allow date and dimension parameters and show on right pane (the one showing error, since dates and dimensions are null).

 

I read the whole TripPin walkthrough several times to end up at this point, but I'm getting lost about parameters and navigation table...

 

Here is some relevant code:

 

 

[DataSource.Kind="PQ_SearchConsole", Publish="PQ_SearchConsole.Publish"]
shared PQ_SearchConsole.Contents = Value.ReplaceType(CreateNavTable, contentsType);
contentsType = type function (
    optional start as (type text meta [
        Documentation.FieldCaption = "Début",
        Documentation.FieldDescription = "Date de début de l'extraction (les mots clés sont autorisés : `today`, `yesterday`, `60daysAgo`).",
        Documentation.SampleValues = {"2022-01-01"}
    ]),
    optional end as (type text meta [
        Documentation.FieldCaption = "Fin",
        Documentation.FieldDescription = "Date de fin de l'extraction (les mots clés sont autorisés : `today`, `yesterday`, `60daysAgo`).",
        Documentation.SampleValues = {"yesterday"}
    ]),
    optional params  as (type nullable text meta [
        Documentation.FieldCaption = "Dimensions",
        Documentation.FieldDescription = "Saisir les dimensions souhaitées",
        Documentation.SampleValues = {"query,page,device,country"}
    ])

) as table [...]
CreateNavTable = (
    optional start as text, 
    optional end as text, 
    optional params as nullable text
) as table => 
    let
        sites = GetSitesList(),
        navBody = List.Accumulate( sites[siteUrl], {}, (state, current)=> state &
            {{current, current, PQ_SearchConsole.GetContents(current,start,end,params), "Function", "Function", true}}
        ),

        navHeader = {"Name","Key","Data","ItemKind", "ItemName", "IsLeaf"}, 
        objects = #table(navHeader, navBody),
        NavTable = Table.ToNavigationTable(objects, {"Key"}, "Name", "Data", "ItemKind", "ItemName", "IsLeaf")
    in
        NavTable
GetSitesList = () as table => 
    let
        source = Json.Document( Web.Contents ( api_base_uri ) ),
        sites = Table.FromRecords( source[siteEntry], type table[siteUrl = Text.Type /*, permissionLevel = Text.Type*/] )
    in
        sites;
PQ_SearchConsole.GetContents = (
    website as text,
    start as text, 
    end as text, 
    params as nullable text
)  =>
    let 
        now =  DateTime.FixedLocalNow(), 

        reqStartDate = Date.From(dateFunc(start)), // #date( Date.Year(now), Date.Month(now) - 1 , Date.Day(now) ),
        reqEndDate = Date.From(dateFunc(end)), //  #date( Date.Year(now), Date.Month(now), Date.Day(now) ),
        reqDimensions = if params="" or params = null then {} else Text.Split(params,","),
        source = Web.Contents( api_base_uri, [
            RelativePath = Text.Combine({Uri.EscapeDataString(website), "/searchAnalytics/query"}), 
            Headers = [#"Content-Type"="application/json"],
            Content = Json.FromValue([startDate = reqStartDate, endDate = reqEndDate, dimension = reqDimensions]) 
        ]),
        report = Json.Document(source)
    in
        report

 

 

 

3 Replies

    • 5AMsan's avatar
      5AMsan
      Frequent Visitor

      Hello v-chenwuz-msft 

       

      Not at all ^^ 
      I enjoyed a long week-end and then now I can dive in again!

  • 5AMsan's avatar
    5AMsan
    Frequent Visitor

    I must admit I'm quite puzzled there's no documentation about having parameters for functions or tables exposed as navigation in Power BI. I'm sure some connectors use this, but no way to find anything about this 😕