docs
  1. SCAYLE Resource Center
  2. Developer Guides
  3. Shops
  4. URL Redirects

URL Redirects

General

SCAYLE offers you the capability to manage your Storefront URLs in a efficient & documented way.
The redirects are managed either via Admin API or within the SCAYLE Panel.

Learn how to use the Admin API to manage redirects below, and refer to the User Guide for instructions on setting up redirects in the SCAYLE Panel.

Understand Redirect Status Codes

The following HTTP status codes are supported:

CodeDescription
301Moved Permanently - This and all future requests should be directed to the given URI
302Found - Tells the client to look at (browse to) another URI
303See Other - Redirect to another page which does not represent the requested resource
307Temporary Redirect - Like 302, but the method and body must not change in the redirected request
308Permanent Redirect - Like 301, but the method and body must not change in the redirected request

Redirect inheritance logic

Below are some considerations for how redirects operate at the global and shop-country levels:

  • Redirects created on the global shop level are inherited to all country-level shops.
  • Inherited redirects can be edited on the country level. Edited country redirect values will overwrite the global values.
  • Redirects can be created on the country level separately. Redirects created at the country level can't be overwritten and are only valid for the respective shop-country.

Admin API

Use Admin API to create, update and delete redirects (also possible as a bulk action) for a shop.

Parameters

ParameterTypeDetails
limitInteger or EmptyA limit on the number of entities to be returned. Maximum amount set to 5k.
cursorString or EmptyA valid cursor for use in pagination. Can be retrieved from the response
withString with comma separated of the models to includeFor this case the one available is parent . It’s important to have it included to be able to see the redirect’s parent data.
filtersArray with the filters to be applied

Available filters are id and search. Each filter needs to be sent separately.
filtersid- Integer - To get a single redirect
filterssearch- String . This will return all the redirects where the source or target contains the filtered value. (As we search in the SCAYLE Panel as of now)


Since we have regex in the source we expect to have special characters in the filter. Please make sure to have all these URL encoded to avoid conflicts and to receive the expected result.

sortString or EmptyColumn to be used for sort, by default it’s created_at
sortDirString or EmptyDirection of the sort. Possible values are asc and desc, by default it's desc

Create a new redirect

Create a new redirect for a shop.

let newRedirect = {
   "source": "https://google.com",
   "target": "https://google2.com",
   "statusCode": 302,
   "parent": {
      "id": 2,
   },
   "isRegex": false,
   "priority": 1
};
  
let response = await client.apis.Redirects.createRedirect({}, {requestBody: newRedirect});// Some code

Update an existing redirect

let updateRedirect = {
    "source": "https://google.com",
    "target": "https://google2.com",
    "statusCode": 302,
    "parent": {
      "id": 2,
    },
    "isRegex": false,
    "priority": 1
};
  
 let response = await client.apis.Redirects.update({redirectIdentifier: 1}, {requestBody: newRedirect});
 let updatedRedirect = response.body;

List redirects

You can list all redirects in a particular shop

let response = await client.apis.Redirects.getRedirects({
    shopKey: 'ms',
    with: 'parent',
    "filters[id]": "10,11,12"
});

let redirects = response.body.entities;

redirects.forEach(
    redirect => console.log(redirect.id)
);

Bulk create redirects

 const redirects = [
    {
      "source": "https://source.com",
      "target": "https://target.com",
      "status": 301,
      "isRegex": false,
      "priority": 1
    },
    {
      "parent": {
        "id": 1
      },
      "target": "https://target2.com",
      "status": 302,
      "isRegex": false,
      "priority": 2
    }
  ];

  const response = await client.apis.Redirects.createOrUpdateRedirects({
      shopKey: 'ms'
  }, {
    requestBody: redirects,
  });
  
  const failedRedirects = response.body.entities;

Endpoint is limited to 1000 entries per call

Bulk update redirects

const redirects = [
    {
     "redirectId": 122,
      "source": "https://source.com",
      "target": "https://target.com",
      "status": 301,
      "isRegex": false,
      "priority": 1
    },
    {
      "redirectId": 123,
      "parent": {
        "id": 1
      },
      "target": "https://target2.com",
      "status": 302,
      "isRegex": false,
      "priority": 2
    }
  ];

  const response = await client.apis.Redirects.createOrUpdateRedirects({
      shopKey: 'ms'
  }, {
    requestBody: redirects,
  });
  
  const failedRedirects = response.body.entities;

Endpoint is limited to 1000 entries per call

Delete an existing redirect

client.apis.Redirects.deleteRedirect({redirectId: 1});

Bulk delete redirects

  const redirects = [
    {
      "id": 1
    },
    {
      "id": 2
    },
    {
      "id": 3
    }
  ];

  await client.apis.Redirects.deleteRedirects({
      shopKey: 'ms'
  }, {
    requestBody: redirects,
  });

Check the Admin API Reference for more details.

Storefront API

Handle URL redirects in your Storefront

Use Storefront API to find matching redirects for a URL.

Refer to the User Guide for instructions on setting up redirects in the SCAYLE Panel and further explanations.

Get the matching URL redirect

Let's imagine we have set up a new shop website with a new URL structure. Now we want all customers which enter an address of our previous shop to be forwarded to our new shop's equivalent.

To achieve this in our new shop, we will establish a handler function that responds to any request not aligning with our new URL structure. This function will capture the current URL and forward it to SCAYLE to retrieve a corresponding redirect.

const redirect = await client.redirects.post(url);
console.log(redirect);

Get all URL redirects

To receive a list of all configured redirects of the SCAYLE Panel we can use the get method.

const redirects = await client.redirects.get();
console.log(redirects.entities);

Check the Storefront API Reference for more details.