Skip to main content

Data-serving APIs

This section provides all the information you need to query your data. It covers the different query APIs with examples of various data visualizations. It also covers upcoming SQL support.

You can test your GraphQL requests without writing a single line of code in our GraphQL Explorer.

SQL​

In Propel, you can use SQL to query your data. This way, you can easily take advantage of Propel's fast response times, high availability, and access controls with the convenience of familiar SQL syntax.

You can use the SQL API or the PostgreSQL-compatible SQL interface to build your data applications. Learn more about our SQL support.

query {
sqlV1(input: { query: "SELECT * FROM \"TacoSoft Demo Data\" LIMIT 3" }) {
columns {
columnName
}
rows
}
}

Query APIs​

Propel's query APIs are designed for powering various types of visualizations, as well as server-to-server use cases. Each API takes a different input and returns the data in a format optimized for its corresponding visualization.


Time Series​

The Time Series API returns values and labels for every time granule over the requested relative or absolute time range.

Read the docs

GraphQL Time Series example query

Query:
# What was the daily revenue for El Buen Sabor for the last 30 days?
query TimeSeriesExample1($input: TimeSeriesInput!) {
timeSeries(input: $input) {
labels
values
}
}

Variables:

{
"input": {
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
},
"granularity": "DAY",
"timeRange": {
"relative": "LAST_N_DAYS",
"n": 30
},
"filters": [
{
"column": "restaurant_name",
"operator": "EQUALS",
"value": "El Buen Sabor"
}
]
}
}

Counter​

The Counter API returns a single value for the requested relative or absolute time range.

Read the docs

Counter metric example cardCounter metric example card
GraphQL Counter example query

Query:
# Compare the revenue for the last 30 days to the previous 30 days before that
query CounterExample1(
$revenueLast30DaysInput: CounterInput!
$revenuePrevious30DaysInput: CounterInput!
) {
revenueLast30Days: counter(input: $revenueLast30DaysInput) {
value
}
revenuePrevious30Days: counter(input: $revenuePrevious30DaysInput) {
value
}
}

Variables:

{
"revenueLast30DaysInput": {
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
},
"timeRange": {
"relative": "THIS_MONTH",
"n": null
},
"filters": [
{
"column": "restaurant_name",
"operator": "EQUALS",
"value": "La Taqueria"
}
]
},
"revenuePrevious30DaysInput": {
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
},
"timeRange": {
"relative": "PREVIOUS_MONTH",
"n": null
},
"filters": [
{
"column": "restaurant_name",
"operator": "EQUALS",
"value": "La Taqueria"
}
]
}
}

Leaderboard​

The Leaderboard API returns an ordered list of aggregated values grouped by a given dimension.

Read the docs

GraphQL Leaderboard example query

Query:
# Find the top restaurants with the most revenue for the last 30 days.
query LeaderboardExample1($input: LeaderboardInput!) {
leaderboard(input: $input) {
headers
rows
}
}

Variables:

{
"input": {
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
},
"sort": "DESC",
"timeRange": {
"relative": "LAST_N_DAYS",
"n": 30
},
"rowLimit": 10,
"dimensions": [
{
"columnName": "restaurant_name"
}
],
"filters": []
}
}

Metric Report

The Metric Report API returns one or multiple metrics grouped by a common dimension.

Read the docs

Leaderboard metric example cardLeaderboard metric example card
GraphQL Metric Report example query

Query:
# Fetch a report showing the revenue and taco order
# count for the top performing restaurant-taco pairs.
query MetricReportExample($input: MetricReportInput!) {
metricReport(input: $input) {
headers
rows
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
}
}

Variables:

{
"input": {
"timeRange": {
"relative": "LAST_N_DAYS",
"n": 30
},
"dimensions": [
{
"columnName": "restaurant_name"
},
{
"columnName": "taco_name"
}
],
"metrics": [
{
"metric": {
"sum": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"measure": {
"columnName": "taco_total_price"
}
}
}
},
{
"metric": {
"countDistinct": {
"dataPool": {
"name": "TacoSoft Demo Data"
},
"dimension": {
"columnName": "order_id"
}
}
}
}
],
"orderByColumn": 1,
"first": 10
}
}

How to test your GraphQL query​

Once you have a GraphQL query for your data that you want to test, there are a few ways to go about it.

1. GraphQL Explorer​

You can check out our GraphQL Explorer, log in to your Propel account, and test your query there.

2. cURL or a similar tool​

If you'd like to test your query with curl or a similar tool, you can first create an access token like so:

curl -X POST https://auth.us-east-2.propeldata.com/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"

You can find your client ID and secret on Propel Console in the Applications page.

Once you have your access token, you can use it to test your query like this:

curl -X POST https://api.us-east-2.propeldata.com/graphql \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "Content-Type: application/json" \
-d '{
"query": "query LeaderboardExample1($input: LeaderboardInput!) { leaderboard(input: $input) { headers rows }}",
"variables": {
"input": {
"metricName": "Revenue",
"sort": "DESC",
"timeRange": {
"relative": "LAST_N_DAYS",
"n": 30
},
"rowLimit": 10,
"dimensions": [
{
"columnName": "restaurant_name"
}
],
"filters": []
}
}
}'

3. JavaScript​

Here's an example of how you can run a GraphQL query using fetch in vanilla JavaScript.

const query = `
query LeaderboardExample1($input: LeaderboardInput!) {
leaderboard(input: $input) {
headers
rows
}
}
`

const variables = {
input: {
metricName: 'Revenue',
sort: 'DESC',
timeRange: {
relative: 'LAST_N_DAYS',
n: 30
},
rowLimit: 10,
dimensions: [{ columnName: 'restaurant_name' }],
filters: []
}
}

// Fetch access token
fetch('https://auth.us-east-2.propeldata.com/oauth2/token', {
method: 'post',
body: `grant_type=client_credentials&client_id=${process.env.CLIENT_ID}&client_secret=${process.env.SECRET}`
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.then((response) => response.json())
.then((jsonData) => jsonData.access_token)

// Post the GraphQL query
.then((access_token) => {
return fetch('https://api.us-east-2.propeldata.com/graphql', {
method: 'POST',
headers: {
Authorization: `Bearer ${access_token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query, variables })
})
})
.then((response) => response.json())
.then((data) => console.log(data))
tip

In production code, make sure not to expose your client ID and secret on the frontend.

For a more comprehensive example that shows you the whole flow from creating an OAuth 2.0 client, obtaining an access token, and running and processing a GraphQL query, you can check Propel Next.js Starter App.

Additional guides​