Skip to content

improvement provided - not able to make a pull request - this is a generic function for all APIs #7

Description

@thej4ck

hi, this is an improvement. i make a function from your code.


//Assumption to use this function
// create two parameters in powerquery named APIKEY and pipedrive_url, the first with the api key and the second with the dns name of the pipedrive tenant
// then call this function with the correct API name (see documentation) ,es: deals, leads, organizations, products ecc...

// https://developers.pipedrive.com/docs/api/v1

let
    Origine = (entity as any, optional fields as any) => let 
    fields_statement = "",
    
    
    Source = Json.Document(Web.Contents("https://" & pipedrive_url & "/v1/" & entity & ":(id)?api_token=" & APIKEY,[Query=[api_token=APIKEY, limit="1", start="0", get_summary="1"]])), 
    #"Converted to Table Record" = Record.ToTable(Source),
    Value = #"Converted to Table Record"{2}[Value],
    summary = Value[summary],
    total_records = summary[total_count],
    
    //This second part, tries to resolve the maximum limit value of 500 that pipedrive have
    //Starts 0, 500, 1000, 1500 until the total records
    
    Starts = List.Generate(()=>0, each _ < total_records, each _ + 500), 
    #"Converted to Table" = Table.FromList(Starts, Splitter.SplitByNothing(), null, null, ExtraValues.Error), 
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}), 
    #"if_test" = if fields = null then fields_statement = "" else fields_statement = ":("&fields&")",
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Json.Document(Web.Contents("https://"&pipedrive_url&"/v1/"& entity & fields_statement & "?api_token="&APIKEY,[Query=[api_token=APIKEY, limit="500", start=[Column1]]]))),
    
    //then is just branding and expanding
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"data"}, {"Custom.data"}),
    #"Expanded Custom.data" = Table.ExpandListColumn(#"Expanded Custom", "Custom.data")

    in
    #"Expanded Custom.data"
in
    Origine

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions