Price2Spy API – Power BI Connection (HMAC authorization)

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:

REQUIRED STEPS

Here are the steps on how to use Power BI with HMAC and Power Query (M language).

In Power BI:

Find the detailed step-by-step connection guide here:

Price2Spy API – Power BI Connection (HMAC authorization)

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.

"{""active"":""true"", ""brandName"":""Nike"", ""categoryName"": ""Shoes"", ""customField5″":""Red color"", ""searchMode"":""LIKE""}"

All JSON properties should have double quotes around every attribute.

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