Traceable provides GraphQL public APIs that you can use to access Traceable using your existing automation setup. You can use Traceable's public API for configuration and accessing operational data.
What will you learn in this topic?
By the end of this topic, you will be able to understand:
The steps to generate and copy the platform API token.
The concept of the Altair GraphQL client.
The examples related to Traceable’s public APIs.
To use Traceable's GraphQL public API, complete the following two steps:
Step 1 — Generate and Copy the Platform API token
Complete the following steps to access the Platform API token:
Log in to Traceable Platform.
Navigate to Your Account → My Preferences as shown below.
On the My Preferences page, click API Tokens → Generate API Token.
Copy the token value and then click Okay.
Note
Once you copy the token, you cannot view or access it again. Make sure that you copy and save it. If you lose the token, you must generate a new one.
When you delete the API token from Traceable, your access from the GraphQL client is blocked.
You can only edit or delete the token. When you edit the token, you can only change the name of the token and not its value.
The following interactive demo walks you through the steps to navigate and generate an API token on the Traceable platform.
Step 2 — Access the Public API
You can use any GraphQL client to access Traceable's public API. In the below steps, we are using Altair GraphQL client. Complete the following steps in Altair GraphQL client:
Launch the Altair GraphQL client and click on the Set Headers icon as shown below.
Click on Add header in the Headers window to add the
Authorization
header. Add the Platform API Token that you copied in Step 1 and click Save.Add the
https://api.traceable.ai/graphql
URL and click on Reload Docs icon as shown below.Click on Queries or Mutations to start exploring the documentation. You can also type your query in the search field.
Example Queries
Total number of learned APIs
Query
query {
entities(
scope: "API"
between: {
startTime: "2021-10-27T22:52:55.026Z"
endTime: "2021-10-27T23:52:55.026Z"
}
filterBy: [
{
keyExpression: { key: "isLearnt" }
operator: EQUALS
value: true
type: ATTRIBUTE
}
{
keyExpression: { key: "apiDiscoveryState" }
operator: IN
value: ["DISCOVERED", "UNDER_DISCOVERY"]
type: ATTRIBUTE
}
]
includeInactive: true
) {
total
}
}
Result
{
"data": {
"entities": {
"total": 658
}
}
}
Total number of learning API endpoints
Query
query {
entities(
scope: "API"
between: {
startTime: "2021-10-27T22:52:55.026Z"
endTime: "2021-10-27T23:52:55.026Z"
}
filterBy: [
{
keyExpression: { key: "isLearnt" }
operator: EQUALS
value: false
type: ATTRIBUTE
}
{
keyExpression: { key: "apiDiscoveryState" }
operator: IN
value: ["DISCOVERED", "UNDER_DISCOVERY"]
type: ATTRIBUTE
}
]
includeInactive: true
) {
total
}
}
Result
{
"data": {
"entities": {
"total": 33657
}
}
}
Total number of services
Query
{
entities(
scope: "SERVICE"
limit: 1
between: {startTime: "2021-10-27T22:52:55.026Z", endTime: "2021-10-27T23:52:55.026Z"}
includeInactive: true
) {
total
}
}
Result
{
"data": {
"entities": {
"total": 572
}
}
}
Top 10 APIs
The following query fetches top 10 API endpoints by call volume:
Query
{
explore(
scope: "API"
limit: 10
between: {
startTime: "2022-01-01T22:52:55.026Z"
endTime: "2022-01-10T23:52:55.026Z"
}
filterBy: [
{
keyExpression: { key: "apiDiscoveryState" }
operator: IN
value: ["DISCOVERED", "UNDER_DISCOVERY"]
type: ATTRIBUTE
}
]
groupBy: {
expressions: [{ key: "id" }, { key: "name" }]
groupLimit: 10000
}
orderBy: [
{ keyExpression: { key: "name" }, aggregation: COUNT, direction: DESC }
]
) {
results {
id: selection(expression: { key: "id" }) {
value
}
name: selection(expression: { key: "name" }) {
value
}
count_name: selection(expression: { key: "name" }, aggregation: COUNT) {
value
}
}
}
}
Result
{
"data": {
"explore": {
"results": [
{
"id": {
"value": "7ccf74e7-8b28-360a-a5b9-e701ddf6b828"
},
"name": {
"value": "hipstershop.ProductCatalogService.GetProduct"
},
"count_name": {
"value": 2784148
}
},
{
"id": {
"value": "457b9ecc-91be-30c2-b814-e11ba0f5b396"
},
"name": {
"value": "GET /product/{product-id}"
},
"count_name": {
"value": 1286569
}
},
{
"id": {
"value": "6806a4b7-ad8a-32b4-83ca-a46653f87cbc"
},
"name": {
"value": "POST /partner/{partner-id}"
},
"count_name": {
"value": 649034
}
},
{
"id": {
"value": "906589e9-2064-3f1c-991f-a71d78d8cce3"
},
"name": {
"value": "GET /loginservice/check"
},
"count_name": {
"value": 492144
}
},
{
"id": {
"value": "ccbd507b-60db-330e-aafa-facc559f0228"
},
"name": {
"value": "hipstershop.CurrencyService.Convert"
},
"count_name": {
"value": 470178
}
},
{
"id": {
"value": "fd271283-9c38-3767-9fb4-5a4a3cc7aec4"
},
"name": {
"value": "hipstershop.ProductCatalogService.ListProducts"
},
"count_name": {
"value": 396176
}
},
{
"id": {
"value": "09b1f28b-9075-3e62-8313-e5640041c143"
},
"name": {
"value": "hipstershop.ProductCatalogService.GetProductsSlice"
},
"count_name": {
"value": 265645
}
},
{
"id": {
"value": "8e4dbf89-ce90-3f3d-8461-0a227b961085"
},
"name": {
"value": "hipstershop.CartService.GetCart"
},
"count_name": {
"value": 211799
}
},
{
"id": {
"value": "1a4dddc6-6bd6-3f31-916b-e8beb514dbf2"
},
"name": {
"value": "hipstershop.RecommendationService.ListRecommendations"
},
"count_name": {
"value": 203979
}
},
{
"id": {
"value": "98a5be1d-ed4b-370c-a953-5ce58441178d"
},
"name": {
"value": "GET /product"
},
"count_name": {
"value": 179195
}
}
]
}
}
}