Skip to main content

How to use our API

Sending GraphQL Query to Fabriq API

GraphQL Query with Variables:

query GetMonthlyPageViews($period_month: Int!, $period_year: Int!) {
wral_articles_monthly(where: {period_month: {_eq: $period_month}, period_year: {_eq: $period_year}}) {
article_id
page_views
new_users
users
}
}

Using curl

You can use curl to send a GraphQL query to the Fabriq API. Below is the curl command:

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Key api-key" \
-d '{
"query": "query GetMonthlyPageViews($period_month: Int!, $period_year: Int!) {\n wral_articles_monthly(where: {period_month: {_eq: $period_month}, period_year: {_eq: $period_year}}) {\n article_id\n page_views\n new_users\n users\n }\n}\n",
"variables": {
"period_month": 1,
"period_year": 2024
}
}' \
https://app.getfabriq.com/wral/api/metrics

Updated JavaScript code:

const axios = require('axios');

async function fetchData(period_month, period_year) {
const query = {
query: `query GetMonthlyPageViews($period_month: Int!, $period_year: Int!) {
wral_articles_monthly(where: {period_month: {_eq: $period_month}, period_year: {_eq: $period_year}}) {
article_id
page_views
new_users
users
}
}`,
variables: { period_month, period_year }
};

try {
const response = await axios.post('https://app.getfabriq.com/wral/api/metrics', query, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Key api-key'
}
});
const data = response.data;
console.log(data);
} catch (error) {
console.error('Error:', error);
}
}

// Call the function with desired period_month and period_year values
fetchData(1, 2024);

This JavaScript code sends a POST request to the Fabriq API using the axios library. Ensure you have installed axiox using npm install axios before running this code.