Price2Spy API - Power BI Connection (HMAC authorization)
This guide explains how to connect to Price2spy API from Power BI Desktop using HMAC authentication.
PREREQUIREMENTS
Before starting, make sure you have:
- Power BI Desktop installed (latest version recommended)
- API base URL
- API Key (public key or client ID). - Client ID from your account. (Must have an API access)
- Documentation for the API endpoint
- Before any action, please check how Price2spy API works with HMAC authorization here.
REQUIRED STEPS
Here are the steps on how to use Power BI with HMAC and Power Query (M language).
In Power BI:
- Open Power BI Desktop.
- Go to Home → Get Data → Blank Query.
- Open Advanced Editor and paste the following example script:
- Choose and paste the code snippet that matches the type of request you want to send — either GET or POST.
Find the detailed step-by-step connection guide here:

Microsoft Power BI
Follow the steps to connect Microsoft Power BI with Price2Spy via our API.
EXAMPLES
The following section contains two examples of Power M queries — one for a GET endpoint and one for a POST endpoint. Before that, let’s go over the variables used in these examples.
- METHOD – [GET, POST], depending on which HTTP method you intend to use in the query.
- API_BASE_URL – Base URL of Price2spy API (https://api.price2spy.com)
- RESOURCE – Desired API endpoint without the base API URL (e.g., /price2spy-api/rest/v1/get-brands )
- API_BODY (PAYLOAD) – for GET request is should be an empty string, for POST it should be a body of request as JSON text. See example bellow:
"{""active"":""true"", ""brandName"":""Nike"", ""categoryName"": ""Shoes"", ""customField5″":""Red color"", ""searchMode"":""LIKE""}" All JSON properties should have double quotes around every attribute.
- SIGNATURE_AUTHORIZATION_HEADER – Authorization header for signature service (contact support for more information)
Example of GET request (get-brands) with HMAC authorization:
let
METHOD = "GET", // Desired endpoint method
API_BASE_URL = "https://api.price2spy.com",
RESOURCE = "/rest/v1/get-brands", // Desired endpoint in P2S API
CLIENT_ID = "", // Set your clientId here,
API_BODY = "", // Must be an empty string in GET request
SIGNATURE_AUTHORIZATION_HEADER = "", // Contact support to get this information
// Body needed for HMAC Signature
signaturePayload = [
method = METHOD,
resource = RESOURCE,
clientId = CLIENT_ID,
payload = API_BODY
],
// ==== Make the Web Request to Signature API ====
signature = Web.Contents(
"https://signature.price2spy.com/api/v1/signature/generate",
[
Headers = [
#"Authorization" = SIGNATURE_AUTHORIZATION_HEADER,
#"Content-Type" = "application/json"
],
ManualStatusHandling = {400, 401, 403, 404, 500},
Content = Json.FromValue(signaturePayload)
]
),
signatureResponse = Json.Document(signature),
// converting timestamp to text
timestamp = Text.From(signatureResponse[timestamp]),
headers = [
#"Authorization" = signatureResponse[signature],
#"X-P2S-Date" = timestamp,
#"Content-Type" = "application/json"
],
// Request to API
response = Web.Contents(API_BASE_URL, [
RelativePath = RESOURCE,
Headers = headers,
ManualStatusHandling = {400, 401, 403, 404, 500}
]),
// Parse response
result = Json.Document(response)
in
result
Example of POST request (get-products) with HMAC authorization:
let
METHOD = "POST", // Desired endpoint method
API_BASE_URL = "https://api.price2spy.com",
RESOURCE = "/rest/v1/get-products", // Desired endpoint in P2S API
CLIENT_ID = "", // Set your clientId here,
API_BODY = "{""active"":""true"", ""brandName"":""Brand"", ""searchMode"":""LIKE""}",
SIGNATURE_AUTHORIZATION_HEADER = "", // Contact support to get this information
// Body needed for HMAC Signature
signaturePayload = [
method = METHOD,
resource = RESOURCE,
clientId = CLIENT_ID,
payload = API_BODY
],
// ==== Make the Web Request to Signature API ====
signature = Web.Contents(
"https://signature.price2spy.com",
[
RelativePath = "api/v1/signature/generate",
Headers = [
#"Authorization" = SIGNATURE_AUTHORIZATION_HEADER,
#"Content-Type" = "application/json"
],
ManualStatusHandling = {400, 401, 403, 404, 500},
Content = Json.FromValue(signaturePayload)
]
),
signatureResponse = Json.Document(signature),
// converting timestamp to text
timestamp = Text.From(signatureResponse[timestamp]),
// ==== Setup HTTP Headers for API call ====
headers = [
#"Authorization" = signatureResponse[signature],
#"X-P2S-Date" = timestamp,
#"Content-Type" = "application/json"
],
// Request to API
response = Web.Contents(API_BASE_URL, [
RelativePath = RESOURCE,
Headers = headers,
ManualStatusHandling = {400, 401, 403, 404, 500},
Content = Text.ToBinary(API_BODY)
]),
// ==== Parse JSON Response ====
result = Json.Document(response)
in
result