Developer Guide
Introduction
Authentication
const fetch = require('node-fetch')
const crypto = require('crypto')
const url = 'https://platform.stagetokensoft.com/graphql'
// access and secret keys obtained from your admin dashboard
const accessKey = 'your access key'
const secretKey = 'your secret key'
// create a signature for the request body
const createSignature = (body, timestamp, secretKey) => {
const text = timestamp + body
const hmac = crypto.createHmac('sha256', secretKey)
hmac.update(text)
return hmac.digest('hex')
}
const getServerTime = async () => {
const request = {
query: '{ time }'
}
const body = JSON.stringify(request)
const options = {
headers: {
'Content-Type': 'application/json',
},
method: 'post',
body
}
const res = await fetch(url, options)
const { data } = await res.json()
return data.time
}
const run = async () => {
const timestamp = await getServerTime()
const body = JSON.stringify({ query: '{ currentUser { id email } }' })
const signature = createSignature(body, String(timestamp), secretKey)
const options = {
// include signature and timestamp to request headers
headers: {
'access-key': accessKey,
'access-sign': signature,
'access-timestamp': timestamp,
'Content-Type': 'application/json',
},
method: 'post',
body
}
try {
const res = await fetch(url, options)
console.log('res', res)
const { data } = await res.json()
console.log('data', data)
} catch (e) {
console.log('e', e)
}
}
run()SDK
Sandbox Environment
Platform
Last updated
Was this helpful?