# 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 <strong>target</strong>. 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.

## Resource Properties

### Redirect

* id: The ID for the redirect.
  * Type: x-string
  * Example: 304339089
* path:           The old path to be redirected. When the user visits this path, they will be redirected to the target. (maximum: 1024 characters)

  * Type: x-string
  * Example: "/products.php"
* target: The target location where the user will be redirected. When the user visits the old path specified by the <code>path</code> 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)
  * Type: x-string
  * Example: "/products"
## Retrieves a list of URL redirects

Retrieves a list of URL redirects. <strong>Note:</strong> This endpoint implements pagination by using links that are provided in the response header. To learn more, refer to <a href='/api/usage/pagination-rest'>Make paginated requests to the REST Admin API</a>.

### Endpoint
/admin/api/#{api_version}/redirects.json?since_id=668809255 (GET)

### Parameters
* api_version (required): 
* fields: Show only certain fields, specified by a comma-separated list of field names.
* limit: The maximum number of results to show.
* path: Show redirects with a given path.
* since_id: Restrict results to after the specified ID.
* target: Show redirects with a given target.

### Responses
#### 200
Retrieves a list of URL redirects

Examples:
##### Retrieve a list of URL redirects after a specified ID
Request:
```
GET /admin/api/unstable/redirects.json
```

Response:
```
HTTP/1.1 200 OK
{"redirects":[{"id":950115854,"path":"/ibook","target":"/products/macbook"}]}
```
##### Retrieve a list of all redirects
Request:
```
GET /admin/api/unstable/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"}]}
```
## Retrieves a count of URL redirects

Retrieves a count of URL redirects

### Endpoint
/admin/api/#{api_version}/redirects/count.json (GET)

### Parameters
* api_version (required): 
* path: Count redirects with given path.
* target: Count redirects with given target.

### Responses
#### 200
Retrieves a count of URL redirects

Examples:
##### Count all redirects
Request:
```
GET /admin/api/unstable/redirects/count.json
```

Response:
```
HTTP/1.1 200 OK
{"count":3}
```
## Retrieves a single redirect

Retrieves a single redirect

### Endpoint
/admin/api/#{api_version}/redirects/{redirect_id}.json (GET)

### Parameters
* api_version (required): 
* redirect_id (required): 
* fields: Show only certain fields, specified by a comma-separated list of field names.

### Responses
#### 200
Retrieves a single redirect

Examples:
##### Retrieve a single redirect by its ID
Request:
```
GET /admin/api/unstable/redirects/668809255.json
```

Response:
```
HTTP/1.1 200 OK
{"redirect":{"id":668809255,"path":"/leopard","target":"/pages/macosx"}}
```
## Updates an existing redirect

Updates an existing [redirect](https://shopify.dev/api/admin-rest/latest/resources/redirect)

### Endpoint
/admin/api/#{api_version}/redirects/{redirect_id}.json (PUT)

### Parameters
* api_version (required): 
* redirect_id (required): 

### Responses
#### 200
Updates an existing redirect

Examples:
##### Update both the source (path) and target URIs of a redirect
Request:
```
PUT /admin/api/unstable/redirects/950115854.json
{"redirect":{"id":950115854,"path":"/powermac","target":"/pages/macpro"}}
```

Response:
```
HTTP/1.1 200 OK
{"redirect":{"path":"/powermac","target":"/pages/macpro","id":950115854}}
```
##### Update the source (path) URI of a redirect
Request:
```
PUT /admin/api/unstable/redirects/668809255.json
{"redirect":{"id":668809255,"path":"/tiger"}}
```

Response:
```
HTTP/1.1 200 OK
{"redirect":{"path":"/tiger","target":"/pages/macosx","id":668809255}}
```
##### Update the target URI of a redirect
Request:
```
PUT /admin/api/unstable/redirects/668809255.json
{"redirect":{"id":668809255,"target":"/pages/macpro"}}
```

Response:
```
HTTP/1.1 200 OK
{"redirect":{"target":"/pages/macpro","path":"/leopard","id":668809255}}
```
## Deletes a redirect

Deletes a redirect

### Endpoint
/admin/api/#{api_version}/redirects/{redirect_id}.json (DELETE)

### Parameters
* api_version (required): 
* redirect_id (required): 

### Responses
#### 200
Deletes a redirect

Examples:
##### Delete an existing redirect
Request:
```
DELETE /admin/api/unstable/redirects/668809255.json
```

Response:
```
HTTP/1.1 200 OK
{}
```
## Creates a redirect

Creates a redirect. When you provide a full URL as the value of the <code>path</code> property, it will be saved as an absolute path without the domain.
          For example, <code>"path": "http://www.example.com/springwear"</code> will be saved as <code>"path": "springwear"</code>.

### Endpoint
/admin/api/#{api_version}/redirects.json (POST)

### Parameters
* api_version (required): 

### Responses
#### 201
Creates a redirect

Examples:
##### Create a redirect
Request:
```
POST /admin/api/unstable/redirects.json
{"redirect":{"path":"/ipod","target":"/pages/itunes"}}
```

Response:
```
HTTP/1.1 201 Created
{"redirect":{"id":984542200,"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
Request:
```
POST /admin/api/unstable/redirects.json
{"redirect":{"path":"http://www.apple.com/forums","target":"http://forums.apple.com"}}
```

Response:
```
HTTP/1.1 201 Created
{"redirect":{"id":984542199,"path":"/forums","target":"http://forums.apple.com/"}}
```
#### 422
Creates a redirect

Examples:
##### Creating a redirect without a path or target fails and returns an error
Request:
```
POST /admin/api/unstable/redirects.json
{"redirect":{"body":"foobar"}}
```

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