Apps
Key concepts
Architecture
Apps are separate applications that use GraphQL to talk to a Traide server and that can receive webhooks with event notifications from Traide.
Authentication
Unlike regular users, apps use a bearer token. The token is returned when the app is created and needs to be stored in a secure manner.
The authorization header for apps has the following format:
Authorization: Bearer <app-token>
Permissions
When you create a custom app you must assign its permissions:
| Name | Description |
|---|---|
MANAGE_AGREEMENTS | Manage agreements |
MANAGE_APPS | Manage apps |
MANAGE_CHECKOUTS | Manage checkouts |
MANAGE_COLLECTIONS | Manage collections |
MANAGE_DISCOUNTS | Manage sales and vouchers |
MANAGE_DOCUMENTS | Manage documents |
MANAGE_DRAFT_AND_QUOTE_ORDERS | Manage draft and quote orders |
MANAGE_EMAILS | Manage emails |
MANAGE_FULFILLMENTS | Manage fulfillments |
MANAGE_INVENTORY | Manage inventory |
MANAGE_MARKETPLACE | Manage the marketplace |
MANAGE_MARKETPLACE_CONFIGURATION | Manage marketplace configuration |
MANAGE_MENUS | Manage navigation |
MANAGE_ORDERS | Manage orders |
MANAGE_PAYMENTS | Manage payments |
MANAGE_PAYOUTS | Manage payouts |
MANAGE_PLUGINS | Manage plugins |
MANAGE_PRODUCTS | Manage products |
MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES | Manage product templates and attributes |
MANAGE_REFUNDS | Manage refunds |
MANAGE_SETTINGS | Manage settings |
MANAGE_SHIPPING | Manage shipping |
MANAGE_STAFF | Manage staff |
MANAGE_STOREFRONTS | Manage storefronts |
MANAGE_USERS | Manage customers |
Webhooks
Webhooks can be used to receive data from Traide when particular events happen. For more information, see Webhooks.
Add an app using the API
Creating an app
To create a new app, use the appCreate mutation. This mutation is only available to staff users with the MANAGE_APPS permission. Staff user can't grant app more permissions than he has for his own. The mutation takes the following input fields:
name: the name of the app.isActive: whether to activate the app, defaults totrue.permissions: list of permissions the app should be granted.
Let's assume that we want to create an order processing service that can fetch and manage orders in Traide. To do so, we create a new app with the MANAGE_ORDERS permission:
mutation {
appCreate(
input: { name: "Order processing service", permissions: [MANAGE_ORDERS] }
) {
authToken
app {
id
name
}
appErrors {
field
code
}
}
}
If there are no errors in the response, a new app is created:
{
"data": {
"appCreate": {
"authToken": "Es1O0oB2O3PTeG9A4IVYUcaMoru3Ls",
"app": {
"id": "QXBwOjk=",
"name": "Order processing service"
},
"appErrors": []
}
}
}
The response contains the authToken field - this is the token that the app needs to include in requests to Traide API to authorize itself and have access to queries or mutations that it needs.
The authToken field is only available in the mutation response and cannot be fetched later, except for the last four digits.
Creating authorization keys
Creating an app with appCreate mutation creates the default authorization token (authToken). You can create more authorization keys with the appTokenCreate. The mutation takes the following fields:
app: ID of the app.name: (optional) name of the key.
mutation {
appTokenCreate(input: { app: "QXBwOjk=" }) {
authToken
appErrors {
field
code
}
appToken {
id
}
}
}
Revoking authorization keys
To revoke an authorization key, pass the key's id (the appToken.id returned by appTokenCreate, not the app's ID) to appTokenDelete:
mutation {
appTokenDelete(id: "QXBwVG9rZW46Mjc=") {
appErrors {
field
code
}
}
}
Retrieving all apps
To fetch list of all apps, use apps query. This query is only available to staff users with the MANAGE_APPS permission.
{
apps(first: 5){
edges{
node{
id
permissions{
code
}
name
isActive
webhooks{
name
}
}
}
}
}
The query returns a similar response:
{
"data": {
"apps": {
"edges": [
{
"node": {
"id": "QXBwOjE=",
"permissions": [
{
"code": "MANAGE_ORDERS"
}
],
"name": "Order App",
"isActive": true,
"webhooks": []
}
}
]
}
}
}
Activating an app
To activate an app, use the appActivate mutation. This mutation is only available to staff users with the MANAGE_APPS permission.
Staff user can't activate app which has more permissions than he has for his own.
The mutation takes the following fields:
id: the id of theApp, required.
mutation {
appActivate(id:"QXBwOjE="){
app{
id
isActive
}
appErrors{
field
message
code
}
}
}
The query returns a similar response:
{
"data": {
"appActivate": {
"app": {
"id": "QXBwOjE=",
"isActive": true
},
"appErrors": []
}
}
}
Deactivating an app
To deactivate an app, use the appDeactivate mutation. This mutation is only available to staff users with the MANAGE_APPS permission.
Staff user can't deactivate an app which has more permissions than they have for their own.
Deactivating an app will disable all auth-tokens generated for an app. The app won't receive a webhook payload.
The mutation takes the following fields:
id: the id of theApp, required.
mutation {
appDeactivate(id:"QXBwOjE="){
app{
id
isActive
}
appErrors{
field
message
code
}
}
}
The query returns a similar response:
{
"data": {
"appDeactivate": {
"app": {
"id": "QXBwOjE=",
"isActive": false
},
"appErrors": []
}
}
}
Subscribing to a webhook
To subscribe to a webhook, we need to first create an app with proper permissions. Let's assume that we want to extend the order processing app that we've created in the example above. The app should receive notifications whenever new orders are created in Traide. To do so, we'll create a new webhook using the webhookCreate mutation. The mutation takes the following input:
name: name of the webhook.targetUrl: URL of a service that will receive webhooks requests.events: list of the events to subscribe to.app: ID of the app to which the webhook belongs.isActive: whether to activate the webhook.
mutation {
webhookCreate(
input: {
name: "New orders notification"
targetUrl: "https://order-processing-service.example.com"
events: [ORDER_CREATED]
app: "QXBwOjk="
isActive: true
secretKey: "secret-key"
}
) {
webhook {
id
}
webhookErrors {
field
code
}
}
}
If there are no errors in the response, the webhook is successfully created. From now on, whenever a new order is placed, payload with order data will be sent to your targetUrl.
Updating a webhook
To update a webhook (e.g. to deactivate it or change the permissions), use the webhookUpdate mutation. The mutation takes similar input fields as the webhookCreate mutation. The example below shows how to deactivate a webhook:
mutation {
webhookUpdate(id: "V2ViaG9vazox", input: { isActive: false }) {
webhook {
isActive
}
webhookErrors {
field
code
}
}
}
Removing a webhook
To fully remove a webhook, use the webhookDelete mutation:
mutation {
webhookDelete(id: "V2ViaG9vazox") {
webhookErrors {
field
code
}
}
}