Examples
This documentation shows how to interact with the API using Python or PowerBI. The number of integration posibilities are high and it is possible to use the API in standard ETL tools as well.
Python example
This approach requires that you have installed Python.
import requests
# Configuration
API_URL = "http://your-server:port/graphql"
API_KEY = "your-api-key"
# Set up headers
headers = {
"BLIKSUND-X-API-KEY": API_KEY,
"Content-Type": "application/json"
}
# Define your GraphQL query
query = """
{
records {
created_at
deleted_at
id
en_GB
metadata_inserted_at
}
}
"""
# Create request payload
payload = {"query": query}
# Send request
response = requests.post(API_URL, json=payload, headers=headers)
# Check if request was successful
if response.status_code == 200:
data = response.json()
records = data['data']['records']
print(f"Retrieved {len(records)} records")
# Print first few records
for record in records[:5]:
print(f"ID: {record['id']}, Created: {record['created_at']}")
else:
print(f"Error: {response.status_code}")
print(response.text)
Power BI Example: CData GraphQL Connector
This approach requires that you have installed PowerBI. It is the easiest PowerBI approach, but requires downloading a GraphQL Connector with a paid subscription.
- Download the GraphQL Connector from the CData website and run through the installation progress. If you encounter the error “This setup could not copy important connector files”, follow the suggested solution in the installation guide.
- Setup the ODBC Driver and DSN
- On your machine, select Start > Search, and enter
ODBC Data Sources
in the search box. - Choose
CData PBI GraphQL Source
under User DSN. Press configure. - In the window, choose basic authentication and enter the log in information of your CData account. Enter the Analytics API URL.
- Choose advanced (under Connection Properties), find “Customer Headers” in the list and enter your authentication key in the following way:
BLIKSUND-X-API-KEY:<your-api-key>
. - Press ok twice to exit the ODBC Data Source Administrator.
- On your machine, select Start > Search, and enter
- Open PowerBI
- Go to Home > Get data > More and search for ODBC.
- In the ODBC window, choose CData PBI GraphQL Source as your DSN.
- During successful setup and connection, you should now be able to view and open your tables from the API.
Power BI Example: Power Query
This approach requires that you have installed PowerBI. It is a more advanced approach, but since Advanced Query in Power BI is used it comes with no additional cost.
- Open PowerBI
- Select Home > Get data > Blank Query. This will launch the Power Query Editor.
- In the Editor, click Advanced Editor (under File > Query menu). This will launce the Advanced Editor.
- The query below is an example of how to load the results of a GraphQL query. Remember to adjust the url, query and api-key to your needs.
let
url = "http://localhost:Port/url",
query = "{
records {
created_at
deleted_at
id
en_GB
metadata_inserted_at
}
}",
escapedQuery = Text.Replace(query, """", "\"""),
jsonBody = "{""query"": """ & escapedQuery & """}",
body = Text.ToBinary(jsonBody),
response = Web.Contents(url,
[
Headers = [
#"Content-Type" = "application/json",
#"BLIKSUND-X-API-KEY" = <your-api-key>
],
Content = body
]
),
json = Json.Document(response),
recordsList = json[data][records],
table = Table.Records(recordsList)
in
table
- Press Done to exit the Advanced editor, and Close & Apply to close the Power Query Editor.
- Your loaded data should appear in the data menu on the right side of the Power BI window.