Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code-snippets generator for M language (microsoft power query) #754

Open
AmauryVanEspen opened this issue Jul 16, 2024 · 0 comments
Open

Comments

@AmauryVanEspen
Copy link

AmauryVanEspen commented Jul 16, 2024

Is your feature request related to a problem? Please describe.
Postman offers a generate-code-snippets feature for various supported language, currently, there is no snippet for M language to query with Power Platform using web API.

Describe the solution you'd like
Provide a M Code to request web API in M

Additional context
Please find below an example of M Code for Quonto web API with API-KEY authentication.
using some header parameters the request GET results and combine pages into one database as a structured table (in one column) according to fields label.

`let
// Auteur : Alexandre STEVENS - https://www.formationpowerbi.fr

// Paramètres de l'API
api_url = "https://thirdparty.qonto.com/v2/transactions",
api_key = "ID:APIKEY",
iban = "IBAN",
slug = "ID",
nb_pages = 10,

// Fonction pour récupérer les transactions d'une page donnée
get_transactions = (pageNumber) =>
    let
        // Paramètres de la requête
        params = [
            #"slug"= slug,
            #"iban"= iban,
            #"current_page"= Text.From(pageNumber)
        ],

        // En-têtes de la requête
        headers = [Authorization=api_key],

        // Appel de l'API
        Source = Json.Document(Web.Contents(api_url, [Query=params, Headers=headers])),

        // Extraction des transactions
        transactions = Source[transactions],

        // Conversion en table
        table = Table.FromList(transactions, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
    in
        table,

// Nombre total de pages à requêter
total_pages = nb_pages,

// Liste pour stocker les résultats de chaque page
all_pages = List.Generate(() => 1, each _ <= total_pages, each _ + 1, each get_transactions(_)),

// Fusion de toutes les pages en une seule table
df_all = Table.Combine(all_pages),

// Expansion des colonnes
database = Table.ExpandRecordColumn(df_all, "Column1", {"transaction_id", "amount", "amount_cents", "settled_balance", "settled_balance_cents", "attachment_ids", "local_amount", "local_amount_cents", "side", "operation_type", "currency", "local_currency", "label", "settled_at", "emitted_at", "updated_at", "status", "note", "reference", "vat_amount", "vat_amount_cents", "vat_rate", "initiator_id", "label_ids", "attachment_lost", "attachment_required", "card_last_digits", "category", "id", "subject_type", "income", "transfer", "direct_debit"}, {"transaction_id", "amount", "amount_cents", "settled_balance", "settled_balance_cents", "attachment_ids", "local_amount", "local_amount_cents", "side", "operation_type", "currency", "local_currency", "label", "settled_at", "emitted_at", "updated_at", "status", "note", "reference", "vat_amount", "vat_amount_cents", "vat_rate", "initiator_id", "label_ids", "attachment_lost", "attachment_required", "card_last_digits", "category", "id", "subject_type", "income", "transfer", "direct_debit"})

in
database
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant