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 you can 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:

Redirect Properties

id
{ "id" : 304339089 }
The unique numeric identifier for the redirect.
path
{ "path" : "/products.php" }
The "before" path to be redirected. When the user this path, s/he will be redirected to the path specified by target.
target
{ "target" : "/products" }
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.
LimitAmount of results
(default: 50) (maximum: 250)
pagePage to show
(default: 1)
since_idRestrict results to after the specified ID
pathShow Redirects with given path
targetShow Redirects with given target
fieldscomma-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

Response:

HTTP/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

Response:

HTTP/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.
pathCount Redirects with given path
targetCount 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

Response:

HTTP/1.1 200 OK
{
  "count": 3
}

GET/web/redirects/668809255.json

Get a single redirect.
fieldscomma-separated list of fields to include in the response

Get a single redirect by its ID.

GET /web/redirects/#{id}.json

Response:

HTTP/1.1 200 OK
{
  "redirect": {
    "id": 668809255,
    "path": "\/leopard",
    "target": "\/pages\/macosx"
  }
}

POST/web/redirects.json

Create a new redirect.
POST /web/redirects.json
{
  "redirect": {
    "path": "\/ipod",
    "target": "\/pages\/itunes"
  }
}


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"
  }
}

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

POST /web/redirects.json
{
  "redirect": {
    "body": "foobar"
  }
}

Response:

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:

PUT /web/redirects/#{id}.json
{
  "redirect": {
    "id": 668809255,
    "path": "\/tiger"
  }
}

Response:

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"
  }
}

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

Response:

HTTP/1.1 200 OK
{}