Redirect
A redirect causes a visitor on a specific path on the shop's site to be automatically sent to a target (different location). The target can be a new location on the shop's site, or a full URL, even one on a completely different domain. Redirect paths are unique; a shop cannot have more than one redirect with the same path.
What can you do with Redirect?
The haravan API lets you do the following with the Redirect resource. More detailed versions of these general actions may be available:
- GET /web/redirects.json Receive a list of all Redirects
- GET /web/redirects/count.json Receive a count of all Redirects
- GET /web/redirects/#{id}.json Receive a single Redirect
- POST /web/redirects.json Create a new Redirect
- PUT /web/redirects/#{id}.json Modify an existing Redirect
- DELETE /web/redirects/#{id}.json Remove a Redirect from the database
Redirect Properties
id |
The unique numeric identifier for the redirect. |
path |
The "before" path to be redirected. When the user this path, s/he will be redirected to the path specified by target. |
target |
The "after" path or URL to be redirected to. When the user visits the path specified by path, s/he will be redirected to this path or URL. This property can be set to any path on the shop's site, or any URL, even one on a completely different domain. |
Endpoints
GET/web/redirects.json
Get a list of all URL redirects for your shop.
limit | Amount of results (default: 50) (maximum: 250) |
page | Page to show (default: 1) |
since_id | Restrict results to after the specified ID |
path | Show Redirects with given path |
target | Show Redirects with given target |
fields | comma-separated list of fields to include in the response |
A redirect's "path" attribute is the path which activates this redirect when visited, and a shop cannot have more than one redirect with the same path. The "target" attribute is the URL which the visitor is redirected to when they try to access the associated path. The target could either be a path or a full URL, possibly even for a different domain.
GET /web/redirects.json
View ResponseHTTP/1.1 200 OK { "redirects": [ { "id": 304339089, "path": "\/products.php", "target": "\/products" }, { "id": 668809255, "path": "\/leopard", "target": "\/pages\/macosx" }, { "id": 950115854, "path": "\/ibook", "target": "\/products\/macbook" } ] }
Get a list of all URL redirects for your shop after a specified ID
GET /web/redirects.json?since_id=668809255
View ResponseHTTP/1.1 200 OK { "redirects": [ { "id": 950115854, "path": "\/ibook", "target": "\/products\/macbook" } ] }
GET/web/redirects/count.json
Get a count of all URL redirects for your shop.
path | Count Redirects with given path |
target | Count Redirects with given target |
A redirect’s “path” attribute is the path which activates this redirect when visited, and a shop cannot have more than one redirect with the same path. The “target” attribute is the URL which the visitor is redirected to when they try to access the associated path. The target could either be a path or a full URL, possibly even for a different domain.
GET /web/redirects/count.json
View ResponseHTTP/1.1 200 OK { "count": 3 }
GET/web/redirects/668809255.json
Get a single redirect.
fields | comma-separated list of fields to include in the response |
Get a single redirect by its ID.
GET /web/redirects/#{id}.json
View ResponseHTTP/1.1 200 OK { "redirect": { "id": 668809255, "path": "\/leopard", "target": "\/pages\/macosx" } }
POST/web/redirects.json
Create a new redirect.
We expect users might try going to /ipod in order to find about one of our popular products, but we want to redirect them to /itunes because that's where we have the information they're looking for.
POST /web/redirects.json
{ "redirect": { "path": "\/ipod", "target": "\/pages\/itunes" } }View Response
HTTP/1.1 201 Created { "redirect": { "id": 979034144, "path": "\/ipod", "target": "\/pages\/itunes" } }
We have a separate forums site that is on a different subdomain. The "path" is always converted to an absolute path without a domain, but the "target" can be a full URL.
POST /web/redirects.json
{ "redirect": { "path": "http:\/\/www.apple.com\/forums", "target": "http:\/\/forums.apple.com" } }View Response
HTTP/1.1 201 Created { "redirect": { "id": 979034145, "path": "\/forums", "target": "http:\/\/forums.apple.com" } }
Trying to create a redirect without a path and target will return an error
HTTP/1.1 422 Unprocessable Entity { "errors": { "path": [ "can't be blank" ], "target": [ "can't be blank", "URI is invalid" ] } }
PUT/web/redirects/668809255.json
Update a redirect's path and/or target URIs.
Change a redirect so that it activates for a different request path:
HTTP/1.1 200 OK { "redirect": { "id": 668809255, "path": "\/tiger", "target": "\/pages\/macosx" } }
Change both the path and target URIs for an existing redirect
PUT /web/redirects/#{id}.json
{ "redirect": { "id": 950115854, "path": "\/powermac", "target": "\/pages\/macpro" } }View Response
HTTP/1.1 200 OK { "redirect": { "id": 950115854, "path": "\/powermac", "target": "\/pages\/macpro" } }
DELETE/web/redirects/668809255.json
Delete a redirect
Remove an existing redirect from a shop
DELETE /web/redirects/#{id}.json
View ResponseHTTP/1.1 200 OK {}