Calling Manta from a backend
Use the GraphQL and SPARQL APIs directly, without React.
Everything the React SDK does goes through two HTTP APIs that you can call from any language: GraphQL for operations such as rules and action plans, and SPARQL for reading the knowledge graph.
Authenticate
Requests carry a Keycloak access token as a bearer token. A backend gets one of two ways, both through a custom app:
-
Machine access. The app’s server mints its own token with the client ID and secret. It acts for the organization that owns the app, with a member’s access to its datastores.
import { cachedToken, mintWithClientCredentials } from "@manta-eu/auth/web"; const getAccessToken = cachedToken(() => mintWithClientCredentials({ clientId, clientSecret })); -
A person’s token. The server signs a person in and stores their refresh token, then calls Manta as them. See Backend for frontend.
manta-codegen and manta-upload sign in with their own CLI client, for generating types and in CI. Do not build a
customer-facing backend on that login: create a custom app instead.
GraphQL
Send operations to /graphql on your Manta deployment (by default https://app.hiremanta.com). Name the datastore
in the x-manta-datastore header:
curl https://app.hiremanta.com/graphql \
-H "Authorization: Bearer $MANTA_TOKEN" \
-H "x-manta-datastore: your-datastore" \
-H "Content-Type: application/json" \
-d '{"query": "query { rules(limit: 5) { count rules { ruleIri committedRule } } }"}'
The rules and actions pages show the payloads for each operation.
SPARQL
Read the graph with a SPARQL query posted to /sparql with the x-manta-datastore header, or to the datastore’s own
path, /d/<datastore>/sparql; both work the same. The endpoint accepts read queries only and answers anything else,
such as INSERT DATA, with a 403. Write to the graph by
connecting a source or uploading files, or through the GraphQL operations
above.
curl https://app.hiremanta.com/d/your-datastore/sparql \
-H "Authorization: Bearer $MANTA_TOKEN" \
-H "Content-Type: application/sparql-query" \
-H "Accept: application/sparql-results+json" \
--data 'SELECT ?s WHERE { ?s a ?type } LIMIT 10'
Treat IRIs as opaque in your queries too. Match on schema:identifier instead of filtering on the shape of an IRI.