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

Get a list of all URL redirects for your shop 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"
    }
  ]
}

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 /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"
    }
  ]
}
GET/admin/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 /admin/redirects/count.json
View Response
HTTP/1.1 200 OK
{
  "count": 3
}
GET/admin/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 /admin/redirects/#{id}.json
View Response
HTTP/1.1 200 OK
{
  "redirect": {
    "id": 668809255,
    "path": "\/leopard",
    "target": "\/pages\/macosx"
  }
}
POST/admin/redirects.json

Create a new redirect.

Trying to create a redirect without a path and target will return 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"
    ]
  }
}

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 /admin/redirects.json
{
  "redirect": {
    "path": "http:\/\/www.apple.com\/forums",
    "target": "http:\/\/forums.apple.com"
  }
}
View Response
HTTP/1.1 201 Created
{
  "redirect": {
    "id": 979034146,
    "path": "\/forums",
    "target": "http:\/\/forums.apple.com\/"
  }
}

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 /admin/redirects.json
{
  "redirect": {
    "path": "\/ipod",
    "target": "\/pages\/itunes"
  }
}
View Response
HTTP/1.1 201 Created
{
  "redirect": {
    "id": 979034147,
    "path": "\/ipod",
    "target": "\/pages\/itunes"
  }
}
PUT/admin/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 /admin/redirects/#{id}.json
{
  "redirect": {
    "id": 668809255,
    "path": "\/tiger"
  }
}
View 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 /admin/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/admin/redirects/668809255.json

Delete a redirect

Remove an existing redirect from a shop

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