An introduction to operations

Basics

Operations are the interface where developers can interact with the SimpleLoyalty system. Retrieving and manipulating data can be done using http post request. The header of the request must contain a SimpleLoyalty admin assigned token as well as a form body with an operation name and its required arguments.

Release of V2 APIs

Version 2 of the SimpleLoyalty Third Party APIs has been released. These APIs require the use of OAuth 2.0 for authentication. Currently, the following APIs are under this category:

  • Zero Error Point Crediting
  • Void Collection V2
  • Redeem Voucher
  • Void Redemption V2

Other APIs will continue to function as usual, but will be shifted over to OAuth 2.0 authentication at a later date, which will be announced.

Endpoint

All requests for v2 APIs should be made to the url below.

https://simpleloyalty.com/third_party/v2

All other requests should be made to the url below.

https://simpleloyalty.com/third_party

Generic Request

Below is an example of using the V2 api via curl.

Text beginning with $ are values to be replaced.

curl \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OAUTH_TOKEN" \
-d '{"operation_name": $OPERATION_NAME}' \
https://simpleloyalty.com/third_party/v2

Below is an example of using the V1 api via curl.

Text beginning with $ are values to be replaced.

curl \
-X POST \
-H "Content-Type: application/json" \
-H "Token: $TOKEN" \
-d '{"operation_name": $OPERATION_NAME}' \
https://simpleloyalty.com/third_party

Types of Operations

Operations can be divided into two distict types.

Index of operations can be found here.

  • Queries
    • Read operation used to retrieve data
    • No side-effect
  • Mutations
    • Write operation used to manipulate existing data
    • Causes side-effect

Errors

Mutation operations contains an inner errors field.

This is to alert users when a failure to perform intended side effect occurs.

Query Response

Below is a structural example of a response from a query operation

{
    "data": {
        $RESOURCE_NODE: {
            $MULTIPLE_RESOURCE: [
                {
                    $FIELD
                    $NESTED_RESOURCE {
                      $NESTED_FIELD
                    }
                }
            ],
            $SINGLE_RESOURCE {
                $FIELD
            }
        }
    },
    "errors": [
      {
        "message": $RUNTIME_ERROR
      }
    ]
}

Mutation Response

While a structural example of a mutation operation would like below

{
    "data": {
        $RESOURCE_NODE: {
            $MULTIPLE_RESOURCE: [
                {
                    $FIELD
                    $NESTED_RESOURCE {
                      $NESTED_FIELD
                    }
                }
            ],
            $SINGLE_RESOURCE {
                $FIELD
            },
            "errors": [
                {
                  "message": $OPERATION_ERROR
                }
            ]
        }
    },
    "errors": [
      {
        "message": $RUNTIME_ERROR
      }
    ]
}