Redirect

A redirect causes a visitor on a specific path on the shop's site to be automatically sent to a different location, called the target. The target can be a new path on the shop's site or a full URL. The new URL can even be on a completely different domain. Redirect paths are unique, so a shop can't have more than one redirect with the same path.

What you can do with Redirect

The Shopify 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 ID for the redirect.

path
"path": "/products.php"

The old path to be redirected. When the user visits this path, they will be redirected to the target. (maximum: 1024 characters)

target
"target": "/products"

The target location where the user will be redirected. When the user visits the old path specified by the path property, they will be redirected to this location. This property can be set to any path on the shop's site, or to an external URL. (maximum: 255 characters)

Endpoints

GET /admin/redirects.json
Retrieves a list of URL redirects
limit

The maximum number of results to show.

(default: 50) (maximum: 250)
page

The page of results to show.

(default: 1)
since_id

Restrict results to after the specified ID.

path

Show redirects with a given path.

target

Show redirects with a given target.

fields

Show only certain fields, specified by a comma-separated list of field names.

Retrieve a list of all redirects

GET /admin/redirects.json
View 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"
    }
  ]
}

Retrieve a list of URL redirects after a specified ID

GET /admin/redirects.json?since_id=668809255
View Response
HTTP/1.1 200 OK
{
  "redirects": [
    {
      "id": 950115854,
      "path": "/ibook",
      "target": "/products/macbook"
    }
  ]
}
GET /admin/redirects/count.json
Retrieves a count of URL redirects
path

Count redirects with given path.

target

Count redirects with given target.

Count all redirects

GET /admin/redirects/count.json
View Response
HTTP/1.1 200 OK
{
  "count": 3
}
GET /admin/redirects/668809255.json
Retrieves a single redirect
fields

Show only certain fields, specified by a comma-separated list of field names.

Retrieve a single redirect by its ID

GET /admin/redirects/#{redirect_id}.json
View Response
HTTP/1.1 200 OK
{
  "redirect": {
    "id": 668809255,
    "path": "/leopard",
    "target": "/pages/macosx"
  }
}
POST /admin/redirects.json
Creates a redirect. When you provide a full URL as the value of the path property, it will be saved as an absolute path without the domain. For example, "path": "http://www.johns-apparel.com/springwear" will be saved as "path": "springwear".

Create a redirect

POST /admin/redirects.json
{
  "redirect": {
    "path": "/ipod",
    "target": "/pages/itunes"
  }
}
View Response
HTTP/1.1 201 Created
{
  "redirect": {
    "id": 979034144,
    "path": "/ipod",
    "target": "/pages/itunes"
  }
}

Create a redirect using a full URL for the path, which will be saved as an absolute path without a domain

POST /admin/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/"
  }
}

Creating a redirect without a path or target fails and returns an error

POST /admin/redirects.json
{
  "redirect": {
    "body": "foobar"
  }
}
View Response
HTTP/1.1 422 Unprocessable Entity
{
  "errors": {
    "path": [
      "can't be blank"
    ],
    "target": [
      "can't be blank",
      "can't be the same as path"
    ]
  }
}
PUT /admin/redirects/668809255.json
Updates an existing redirect

Update the path URI of a redirect

PUT /admin/redirects/#{redirect_id}.json
{
  "redirect": {
    "id": 668809255,
    "path": "/tiger"
  }
}
View Response
HTTP/1.1 200 OK
{
  "redirect": {
    "id": 668809255,
    "path": "/tiger",
    "target": "/pages/macosx"
  }
}

Update both the path and target URIs of a redirect

PUT /admin/redirects/#{redirect_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 /admin/redirects/668809255.json
Deletes a redirect

Delete an existing redirect

DELETE /admin/redirects/#{redirect_id}.json
View Response
HTTP/1.1 200 OK
{
}