Prompt
Answer
Paycor API Custom Connector
This documentation outlines the RESTful API endpoints structure and implementation for accessing the Paycor API using OAuth2 Authentication through a custom connector created using the latest Power Query SDK.
Version Information
[Version = "1.0.0"]
section Paycor_API;
Main Endpoint
The main function to access the Paycor API:
[DataSource.Kind="Paycor_API", Publish="Paycor_API.Publish"]
shared Paycor_API.Contents = (url as text) as binary =>
let
source = Web.Contents(url)
in
source;
Data Source Kind Description
Defines the authentication method and related configurations:
Paycor_API = [
Authentication = [
OAuth2 = [
StartLogin = StartLogin,
FinishLogin = FinishLogin,
Refresh = Refresh,
Logout = Logout,
AuthorizationEndpointUrl = "https://hcm-demo.paycor.com/AppActivation/Authorize",
TokenEndpointUrl = "https://apis.paycor.com/v1/authenticationsupport/retrieveAccessTokenWithRefreshToken",
ClientId = "ac2062e2c0e7486dba5c",
ClientSecret = "/2tomKaDLRSvauGVTo64xnsahzPEyoy4DPmIOvo0r5U", // Replace with actual secret (store securely)
RedirectUri = "https://hcm.paycor.com/appactivation/clientredirect",
Scope = "20d8da8c574def11991a0022488e10a9+offline_access"
]
]
];
UI Publishing Description
Defines the UI elements for publishing the data source in Power BI or other Power Query integrations:
Paycor_API.Publish = [
Beta = true,
Category = "Other",
ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
LearnMoreUrl = "https://powerbi.microsoft.com/",
SourceImage = Paycor_API.Icons,
SourceTypeImage = Paycor_API.Icons
];
Icons
Defines the icons used for the data source:
Paycor_API.Icons = [
Icon16 = { Extension.Contents("Paycor_API16.png"), Extension.Contents("Paycor_API20.png"), Extension.Contents("Paycor_API24.png"), Extension.Contents("Paycor_API32.png") },
Icon32 = { Extension.Contents("Paycor_API32.png"), Extension.Contents("Paycor_API40.png"), Extension.Contents("Paycor_API48.png"), Extension.Contents("Paycor_API64.png") }
];
OAuth2 Authentication Flows
Functions for handling OAuth2 login flows:
Start Login
Generates the authentication request:
StartLogin = (resourceUrl, state, display) =>
[
LoginUri = OAuth2.AuthorizationEndpointUrl & "?response_type=code&client_id=" & Uri.EscapeDataString(OAuth2.ClientId) & "&redirect_uri=" & Uri.EscapeDataString(OAuth2.RedirectUri) & "&state=" & state & "&scope=" & Uri.EscapeDataString(OAuth2.Scope) & "&prompt=login",
CallbackUri = OAuth2.RedirectUri,
WindowHeight = 720,
WindowWidth = 1024,
Context = null
];
Finish Login
Handles login completion and token retrieval:
FinishLogin = (context, callbackUri, state) =>
let
parts = Uri.Parts(callbackUri)[Query],
code = Record.Field(parts, "code"),
tokenResponse = OAuth2.SendTokenRequest(OAuth2.TokenUri, [code=code])
in
tokenResponse;
Refresh Token
Refreshes the OAuth2 token:
Refresh = (resourceUrl, refresh_token) =>
let
tokenResponse = OAuth2.SendTokenRequest(OAuth2.TokenUri, [refresh_token=refresh_token])
in
tokenResponse;
Logout
Logs out of the session:
Logout = (token) =>
let
logoutUri = Text.Format(OAuth2.LogoutUri, [token=token])
in
logoutUri;
To deepen your understanding of features like this, consider exploring the Enterprise DNA Platform for advanced courses on Power BI and Power Query development.
Description
This documentation details the implementation and structure of a custom connector for the Paycor API, utilizing OAuth2 authentication via the Power Query SDK, including the main endpoint, authentication flows, and UI publishing instructions.