routes query
A merchant can reconfigure (rewrite) the URL to any product, category, or CMS page. When the rewrite goes into effect, any links that point to the previous URL are redirected to the new address.
The routes
query returns the canonical URL for a specified product, category, or CMS page. An external app can render a page by a URL without any prior knowledge about the landing page.
Syntax
{routes(url: String!): RoutableInterface}
Example usage
The following query returns information about the product with the URL key of joust-duffle-bag.html
. The response indicates the URL key has been permanently redirected to new-joust-duffle-bag.html
.
Request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
route(url: "joust-duffle-bag.html") {
__typename
relative_url
redirect_code
type
... on SimpleProduct {
sku
url_key
uid
url_rewrites {
url
parameters {
name
value
}
}
relative_url
redirect_code
type
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
"data": {
"route": {
"__typename": "SimpleProduct",
"relative_url": "new-joust-duffle-bag.html",
"redirect_code": 301,
"type": "PRODUCT",
"sku": "24-MB01",
"url_key": "new-joust-duffle-bag",
"uid": "MQ==",
"url_rewrites": [
{
"url": "new-joust-duffle-bag.html",
"parameters": [
{
"name": "id",
"value": "1"
}
]
},
{
"url": "gear/new-joust-duffle-bag.html",
"parameters": [
{
"name": "id",
"value": "1"
},
{
"name": "category",
"value": "3"
}
]
},
{
"url": "gear/bags/new-joust-duffle-bag.html",
"parameters": [
{
"name": "id",
"value": "1"
},
{
"name": "category",
"value": "4"
}
]
}
]
}
}
}
Input attributes
The routes
query requires the following attribute.
Attribute | Type | Description |
---|---|---|
url |
String! | The requested URL. To query for product and category pages, the url value must contain the URL key and suffix. For CMS page queries, the url value must contain the URL key only. |
Output attributes
The RoutableInterface
returns the following attributes.
Attribute | Data Type | Description |
---|---|---|
redirect_code |
Int! | Contains 0 when there is no redirect error. A value of 301 indicates the URL of the requested resource has been changed permanently, while a value of 302 indicates a temporary redirect |
relative_url |
String | The internal relative URL. If the specified URL is a redirect, the query returns the redirected URL, not the original |
type |
UrlRewriteEntityTypeEnum | One of PRODUCT, CATEGORY, or CMS_PAGE |