Integrate the Cloud Agent Admin API
Integrate your application with the Cloud Agent admin API
Integrate server-side application using API Key
async function callWithApiKey(gql: string) {
const adminApiUrl: string = '' // Set the URL to your Cloud Agent instance's admin API.
const adminApiKey: string = '' // Set your admin API key.
const response = await fetch(adminApiUrl, {
method: 'POST',
body: gql,
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'x-api-key': adminApiKey,
}
})
if (response.status !== 200) {
throw `HTTP response status ${response.status}`
}
const json = JSON.parse(await response.text())
if (json.errors) {
throw `GraphQL error when resolving ${json.errors[0].path}: ${json.errors[0].message}`
}
return json.data
}
// The following example GraphQL query fetches recent basic messages for a connection.
const exampleGqlQuery: string = `{
connection(
connectionId: "001fe530-3562-41d6-a631-3df9c7ae1f38"
) {
id
alias
basicMessages(
page: {}
) {
items {
id
content
timestamp
direction
}
nextToken
}
}
}`
const queryResponse = await callWithApiKey(exampleGqlQuery)
const connectionAlias: string = queryResponse.connection.alias
const messages: BasicMessage[] = queryResponse.connection.basicMessages.items
// The following example GraphQL mutation sends a basic message to a connection.
const exampleGqlMutation: string = `mutation {
sendBasicMessage(
connectionId: "001fe530-3562-41d6-a631-3df9c7ae1f38"
content: "Hello Bob"
) {
id
content
timestamp
direction
}
}`
const mutationResponse = await callWithApiKey(exampleGqlMutation)
const sentMessageId = mutationResponse.sendBasicMessage.idIntegrate client-side application using Bearer Token
Last updated