This page shows how to read the data of an event (gathering in the schema, selected with gatheringId). You get an API user from Certain. Then you sign in with the login mutation, and you send a query with the token.
Get an API user
An API user holds the credentials that your system uses to sign in. Certain creates API users. Ask your Certain contact for an API user, and tell them:
- The name of the API user, for example the name of your system.
- The kind of API user that you need: organization-wide, for the organization and all its events, or restricted to specific events.
- For a restricted API user, the events that it can reach.
Your Certain contact gives you the Client Id and the Client Token of the API user. Keep both values secret. Your system sends them to the login mutation.
To see the API users of your organization, open your organization in the CMS. In the menu of the organization page, under Administration, select API Users. Only organization managers can open this screen.
Find the id of an event
Most queries need the id of an event. The address of an event page in the CMS contains the id of the app and the id of the event.
/apps/<app id>/gatherings/<event id>
An organization-wide API user can also list the events of an app with the gatherings query. A restricted API user cannot use this query.
Sign in
The login mutation takes the client id and the client token. It returns a token.
mutation Login($clientId: String!, $clientToken: String!) {
login(clientId: $clientId, clientToken: $clientToken) {
token
}
}
This command sends the mutation with curl.
curl https://api.certaintouchpoint.com/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "mutation Login($clientId: String!, $clientToken: String!) { login(clientId: $clientId, clientToken: $clientToken) { token } }",
"variables": { "clientId": "YOUR_CLIENT_ID", "clientToken": "YOUR_CLIENT_TOKEN" }
}'
The response holds the token.
{
"data": {
"login": {
"token": "eyJhbGciOi..."
}
}
}
If the client id or the client token is wrong, the response has the error Invalid client id or token.
The token is valid for one day. There is no refresh call. When the token expires, call login again. Send that request without an Authorization header. A request that carries the expired token gets HTTP 401.
Send a query
Send the token in the Authorization header. Write the word Bearer, a space, and the token.
Authorization: Bearer <token>
This query reads the first five attendees of an event.
query FirstAttendees($gatheringId: ID!) {
attendeesConnection(gatheringId: $gatheringId, first: 5) {
totalCount
edges {
node {
id
firstName
lastName
email
}
}
}
}
This command sends the query with curl.
curl https://api.certaintouchpoint.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"query": "query FirstAttendees($gatheringId: ID!) { attendeesConnection(gatheringId: $gatheringId, first: 5) { totalCount edges { node { id firstName lastName email } } } }",
"variables": { "gatheringId": "123" }
}'
The response lists the attendees.
{
"data": {
"attendeesConnection": {
"totalCount": 2,
"edges": [
{
"node": {
"id": "9001",
"firstName": "Morgan",
"lastName": "Hayes",
"email": "morgan@example.com"
}
},
{
"node": {
"id": "9002",
"firstName": "Jordan",
"lastName": "Patel",
"email": "jordan@example.com"
}
}
]
}
}
}
To read a long list, see Pagination.
Check the connection
The pulse query needs no token. It returns the text Ok! when the API is reachable.
query {
pulse
}
{
"data": {
"pulse": "Ok!"
}
}
Next steps
- Pagination shows how to read all attendees of a large event.
- Errors lists the errors that a request can return.
- The reference lists every query, mutation, and type.
This article is a copy of Getting started in the Touchpoint API documentation.
Comments
0 comments
Please sign in to leave a comment.