Create Achievement

Achievements help with the gamification of your loyalty program. See the sample example of how this can be configured. Links to more detailed instructions can be found at the end of the article.

How this example works

The achievements module enables members to engage in challenges over an extended period. Think of achievements as a tracking tool, whereas campaigns offer one-time rewards to users. When integrated with campaigns, completed achievements can activate a campaign that rewards users with points or coupons.

In this example, we will create an achievement that monitors a member's login streak over the past 7 days. The member will be able to complete the achievement once.


Try yourself

  • Input the previous saved token and storeCode in the request header

  • Create an achievement Endpoint: POST /api/{storeCode}/achievement

    {
        "achievement": {
            "active": true,
            "translations": {
                "en": {
                    "name": "Maintain a 7-day login streak",
                    "description": "Challenge members to achieve milestones within a custom event. This is a non-transactional achievement that engages customers through gamification elements."
                }
            },
            "limit": {
                "value": 1
            },
            "activity": {
                "data": null,
                "operator": ""
            },
            "rules": [
                {
                    "aggregation": {
                        "type": "quantity"
                    },
                    "completeRule": {
                        "period": {
                            "type": "last_day",
                            "value": 7
                        },
                        "periodGoal": 1
                    },
                    "conditions": [],
                    "event": "app_login",
                    "limit": {
                        "interval": {
                            "type": "calendarDays",
                            "value": 1
                        },
                        "value": 1
                    },
                    "trigger": "custom_event",
                    "type": "direct",
                    "translations": {
                        "en": {
                            "name": "7-day login streak",
                            "description": ""
                        }
                    }
                }
            ]
        }
    }

Endpoints used

Create a new achievement

post
Authorizations
AuthorizationstringRequired

Open Loyalty has the JWT authorization. To learn what a JSON Web Token is and how it works, check out Introduction to JSON Web Tokens https://jwt.io/introduction/

Obtain an access token

Send a request with the parameters username and password

Definition

POST /api/admin/login_check Go to definition
POST /api/{storeCode}/member/login_check Go to definition

Example

curl {HOST}/api/admin/login_check
    -H 'Content-Type: application/json;charset=UTF-8'
    -H 'Accept: application/json, text/plain, */*'
    --data-binary '{"username":"admin","password":"password"}'

Example Response

{
    "token":"eyJhbGciOiJSUzI1NiIsInR5cCI6...",
    "refresh_token":"0558f8bb29948c4e54c443f..."
}

Using JSON Web Token

Add authorization header to each request
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6...
You can now access any API method you want under the /api prefix.

Example

curl {HOST}/api/{storeCode}/analytics/members
    -H 'Accept: application/json'
    -H 'Content-type: application/x-www-form-urlencoded'
    -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6...'

Refresh JSON Web Token

You can refresh token using refresh_token that was given during login.
There are two endpoints
To refresh admin token POST /api/token/refresh Go to definition
To refresh member token POST /api/{storeCode}/token/refresh Go to definition

Path parameters
storeCodestringRequired

Store code

Body
achievementall ofOptional
and
Responses
200

Return created achievement ID.

application/json
post
/api/{storeCode}/achievement
POST /api/{storeCode}/achievement HTTP/1.1
Host: openloyalty.localhost
Authorization: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 430

{
  "achievement": {
    "translations": {
      "en": {},
      "pl": {}
    },
    "activity": {
      "operator": "is_after"
    },
    "active": true,
    "rules": [
      {
        "completeRule": {
          "period": {
            "type": {},
            "consecutive": 1
          }
        },
        "aggregation": {
          "rule": "text",
          "type": "text"
        },
        "conditions": [
          {
            "attribute": "text",
            "operator": "expression"
          }
        ],
        "translations": {
          "en": {
            "name": "text",
            "description": "text"
          }
        },
        "event": "text",
        "uniqueReferee": true
      }
    ],
    "limit": {
      "value": 1,
      "interval": {
        "type": "calendarHours",
        "value": 1
      }
    }
  }
}
{
  "achievementId": "00000000-0000-0000-0000-000000000000"
}

More resources

For a detailed overview and description of the campaign creation and management, please refer to these series of articles:

AchievementsIn this section, you will learn how Achievements work in Open Loyalty, as well as how to configure them according to your preferences; how to create new Achievements, and assign them to your Campaign.

Last updated

Was this helpful?