Skip to main content

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:

NameDescription
MANAGE_AGREEMENTSManage agreements
MANAGE_APPSManage apps
MANAGE_CHECKOUTSManage checkouts
MANAGE_COLLECTIONSManage collections
MANAGE_DISCOUNTSManage sales and vouchers
MANAGE_DOCUMENTSManage documents
MANAGE_DRAFT_AND_QUOTE_ORDERSManage draft and quote orders
MANAGE_EMAILSManage emails
MANAGE_FULFILLMENTSManage fulfillments
MANAGE_INVENTORYManage inventory
MANAGE_MARKETPLACEManage the marketplace
MANAGE_MARKETPLACE_CONFIGURATIONManage marketplace configuration
MANAGE_MENUSManage navigation
MANAGE_ORDERSManage orders
MANAGE_PAYMENTSManage payments
MANAGE_PAYOUTSManage payouts
MANAGE_PLUGINSManage plugins
MANAGE_PRODUCTSManage products
MANAGE_PRODUCT_TYPES_AND_ATTRIBUTESManage product templates and attributes
MANAGE_REFUNDSManage refunds
MANAGE_SETTINGSManage settings
MANAGE_SHIPPINGManage shipping
MANAGE_STAFFManage staff
MANAGE_STOREFRONTSManage storefronts
MANAGE_USERSManage 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 to true.
  • 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.

note

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": []
}
}
]
}
}
}
Show more ↓

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 the App, 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.

note

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 the App, 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
}
}
}
Show more ↓

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
}
}
}

Was this page helpful?