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:
Code | Description |
---|---|
301 | Moved Permanently - This and all future requests should be directed to the given URI |
302 | Found - Tells the client to look at (browse to) another URI |
303 | See Other - Redirect to another page which does not represent the requested resource |
307 | Temporary Redirect - Like 302, but the method and body must not change in the redirected request |
308 | Permanent 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
Parameter | Type | Details |
---|---|---|
limit | Integer or Empty | A limit on the number of entities to be returned. Maximum amount set to 5k. |
cursor | String or Empty | A valid cursor for use in pagination. Can be retrieved from the response |
with | String with comma separated of the models to include | For this case the one available is parent . It’s important to have it included to be able to see the redirect’s parent data. |
filters | Array with the filters to be applied | Available filters are
|
sort | String or Empty | Column to be used for sort, by default it’s created_at |
sortDir | String or Empty | Direction 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.