Generate regid for a Shopper

generate the ID used by the shopper, by store merchants.

Introduction

To ensure data security and protect sensitive information, the Store Admin API requires proper authentication for access. This authentication process involves using a username (pid) and a password (API Key), which are generated from the Swym Dashboard or Swym Admin. The authentication type used is Basic Auth, which is a widely recognized and straightforward method to secure API access.

By incorporating the Store Admin API authentication during these instances, you can provide a seamless and secure experience for both guest and registered users for using the Lists API, allowing them to manage their wishlists effectively while maintaining data privacy and protection.

generate-regid

The generate-regid REST API creates a unique SWYM regid and a session id, using either the useremail or uuid parameter. The API returns a regid that is distinct for each uuid or email.

๐Ÿ“˜

The regid is unique to the uuid or email and remains unchanged unless the uuid or email is modified. This consistency enables the wishlist to be persisted.

Endpointrequest typeAPI type
/storeadmin/v3/user/generate-regidpostStore Admin

Returns

When provided with the correct parameters, this API returns a new regid associated with either a uuid or an email address.

Request headers

Parameter / fieldDescriptioncontent-typerequired
uuidunique token assigned to the guest user conforming to RFC4122 UUID v4application/x-www-form-urlencodedYes, for guest users
useremailemail address of the user.application/x-www-form-urlencodedYes, for logged in users.
useragenttypea string to identify user agent that is requesting the regid generationapplication/x-www-form-urlencodedYes

๐Ÿšง

You can either provide the uuid or the email

For logged in users please use email and for guest users please provide an uuid to generate the unique token.

Use Cases

When implementing the Store Admin API, there are two crucial instances when the authentication process should be executed:

  1. When a user first visits the page: To assign a 'regid' to a new visitor, the Store Admin API should be integrated as soon as they access the website. This initial authentication allows the API to generate a unique 'regid' token for the visitor, enabling them to add items to their wishlist even if they have not registered or logged in.
  2. When a guest user becomes a logged-in user: When a visitor decides to register or log in to their account, the Store Admin API should be executed again to update their authentication status. This ensures that the 'regid' assigned during their guest session is properly linked to their newly created or logged-in account, preserving their wishlist data across sessions.

๐Ÿ‘

This API caters to both guest and logged-in shoppers, providing seamless functionality for all users

Sample Curl

curl --location --request POST '{{Swym API Endpoint}}/storeadmin/v3/user/generate-regid'
-H 'Authorization: Basic {{BASE64-ENCODING-OF-"pid:apikey"}}'
--header 'Content-Type: application/x-www-form-urlencoded'
--data-urlencode 'useragenttype=mobileApp'
--data-urlencode '[email protected]'
--data-urlencode 'uuid=c0deab58-8510-4aa2-9a1a-328812c8e0a1'
--compressed
var axios = require('axios');
var qs = require('qs');
// required
var data = qs.stringify({
  'useragenttype': 'mobileApp',
  'uuid': 'e80c9d38-bdc9-40e8-ac8a-528d33360e1c' 
});
var config = {
  method: 'post',
  url: '{{Swym API Endpoint}}/storeadmin/v3/user/generate-regid',
  headers: { 
    'Authorization': 'Basic {{BASE64-ENCODING-OF-"pid:apikey"}}', 
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

Success Response

{
    "message": "A regid was successfully generated using the uuid.",
    "regid": "e5uAew4m_i67HiY81C8AEpC8ES-tHyzA_mIYxKXvISg60QvNxBkvb9FzluBr4y-h66NHv8e1oREoGsfas3_aLxX7gC--oMgQ-AIa2LjpsDQQq9vtJXdY2Zz8a09GNX5oORRGhzmu1XUmd86hfcrvIn0hMEhI-SxOx3Dn3VNFiEUzQjxMkTFR-SZf0V2NECCJ",
    "sessionid": "8be20a56-098c-48a8-8bd9-bc50f8176311-API"
}

Error Response

if there are no parameters or there are invalid parameters, endpoint does not generate a regid.


{
    "error": true,
    "type": "invalid-uuid",
    "msg": "A UUID v4 that complies with the RFC4122 Standard should be given to create a regid."
}

Sample flow Diagram

Error Status Codes:

If the request is unsuccessful, the API will return a JSON response with an error message and an HTTP status code indicating the type of error that occurred.

Status CodeTypeDescription
400Bad RequestYour request is invalid, change your request params and query and try again.
401UnauthorisedYou are performing an action on a resource that is not granted to the current logged-in user. Additionally, for REST APIs, this could mean your API key is wrong.
403ForbiddenYou are not allowed to request this data.
404Not FoundThe specified requested data could not be found.
429Too Many RequestsYou're raising too many requests! Slow down!
500Internal Server ErrorWe had a problem with our server. Try again later.
503Service UnavailableWe're temporarily offline for maintenance. Please try again later.