Skip to main content

Find Redirect API

Written by Kadri - RichAPI Support Team

POST /find_redirect • Credits: 1 credit per call

Find Redirect follows a URL through every HTTP redirect and returns the final destination. Send a POST request with the link parameter. The response holds the final URL, the full redirect chain, the hop count, and the final HTTP status code. Each call costs 1 credit.

What does Find Redirect do?

A short link such as https://bit.ly/example hides its destination. A tracking link from an email tool or an ad platform hides the destination in the same way. Find Redirect sends the request itself, follows each Location header, and reports where the link ends. Find Redirect follows up to 20 hops and accepts the redirect status codes 301, 302, 303, 307, and 308. Find Redirect is a utility endpoint. It runs inside RichAPI and calls no external data provider. The only network traffic is the request to the target host and to every host in the redirect chain.

Which endpoint does Find Redirect use?

  • Method: POST

  • URL: https://api.richapi.ai/api/v1/find_redirect

  • Authentication: x-api-key header

  • Response: Synchronous JSON

  • Credits: 1 credit per call

How to send a Find Redirect request

  1. Copy your API key from the RichAPI dashboard.

  2. Set the link parameter to the short link or the tracking link.

  3. Send a POST request to https://api.richapi.ai/api/v1/find_redirect.

  4. Send the API key in the x-api-key header.

  5. Read the redirect_link field for the final destination.

  6. If resolved_successfully is false, treat the link as dead.

cURL

curl -X POST https://api.richapi.ai/api/v1/find_redirect   
-H "x-api-key: YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{
"link": "https://bit.ly/example"
}'

Python

import requests

response = requests.post(
"https://api.richapi.ai/api/v1/find_redirect",
headers={"x-api-key": "YOUR_API_KEY"},
json={"link": "https://bit.ly/example"},
timeout=60,
)
response.raise_for_status()
print(response.json())

Node.js

const response = await fetch("https://api.richapi.ai/api/v1/find_redirect", {
method: "POST",
headers: {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
link: "https://bit.ly/example",
}),
});

const data = await response.json();
console.log(data);

Which parameters does Find Redirect accept?

Parameter

Type

Required

Default

Description

link

string

Yes

None

The URL to follow. The maximum length is 2048 characters. A missing value or an empty value returns a 400 error.

RichAPI adds no default value to the request body. An empty link value returns a 400 error.

How does Find Redirect follow a redirect chain?

Rule

What Find Redirect does

Maximum hops

Follows 20 redirects.

Redirect status codes

Follows 301, 302, 303, 307, and 308.

Request method

Sends HEAD to each URL. After a 405 response or a connection failure, it retries the same URL with GET.

Timeout

Waits 10 seconds for each hop.

Missing scheme

Adds https:// to a value that holds a dot and no scheme. bit.ly/example becomes https://bit.ly/example.

Whitespace

Removes leading and trailing spaces before the request.

Allowed schemes

Accepts http and https only. Every other scheme returns a 400 error.

Maximum length

Rejects a link value over 2048 characters with a 400 error.

Relative Location

Joins a relative Location header to the current URL.

Missing Location

Stops at the current URL.

Private hosts

Blocks localhost, a private IP address, a reserved IP address, and a link-local IP address.

Redirect loop

Stops after 20 hops and returns the chain that it collected.

Find Redirect checks the host before the first request and again before every hop. If the first URL points at a private host, the response is a 400 error. If a later hop points at a private host, the response is a 200 response with resolved_successfully: false and final_status_code: 0.

What does Find Redirect return for real links?

The table below shows a real link value and the exact result for each field. Each row is one call.

link you send

redirect_count

redirect_link

final_status_code

resolved_successfully

https://bit.ly/example

2

https://vignettinglife.com/

200

true

bit.ly/example

2

https://vignettinglife.com/

200

true

https://youtu.be/dQw4w9WgXcQ

1

https://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtu.be

200

true

http://github.com

1

https://github.com/

200

true

http://en.wikipedia.org/wiki/API

1

https://en.wikipedia.org/wiki/API

200

true

https://example.com

0

https://example.com

200

true

https://www.microsoft.com?utm_source=news

0

https://www.microsoft.com?utm_source=news

200

true

https://bit.ly/3ThX1nJ (expired short link)

0

https://bit.ly/3ThX1nJ

404

false

A URL that sends no redirect returns redirect_count: 0 and is_redirected: false. In that case, redirect_link holds the same URL that you sent.

What does the Find Redirect response look like?

The block below is an example response for the request body {"link": "https://bit.ly/example"}. The short link passes through one HTTP hop before it reaches the final HTTPS page.

{
"original_link": "https://bit.ly/example",
"redirect_link": "https://vignettinglife.com/",
"redirect_chain": [
"https://bit.ly/example",
"http://vignettinglife.com/",
"https://vignettinglife.com/"
],
"redirect_count": 2,
"final_status_code": 200,
"is_redirected": true,
"resolved_successfully": true
}

Which fields does the Find Redirect response hold?

Field

Type

Description

original_link

string

The URL after normalization. Find Redirect trims the spaces and adds https:// to a value with no scheme.

redirect_link

string

The final destination URL. It is the last entry of redirect_chain.

redirect_chain

array of strings

Every URL in the chain, in order. The first entry is original_link. The last entry is redirect_link.

redirect_count

integer

The number of redirects that Find Redirect followed. It is the length of redirect_chain minus 1. The maximum value is 20.

final_status_code

integer

The HTTP status code of the last response. If the host did not answer, or if a hop failed the private-host check, the value is 0.

is_redirected

boolean

If redirect_chain holds more than one URL, the value is true.

resolved_successfully

boolean

If the last status code is under 400, the value is true. The value is false for a 404 page, a 500 page, or a host that did not answer.

How to resolve a tracking link before you store or scrape it

A list of scraped posts or emails holds short links and tracking links. Two different short links can point at the same page, so a count of unique links is wrong. Resolve each link first, then store the destination.

  1. Read the raw link from each record in your list.

  2. Send one Find Redirect request for each link.

  3. Read the resolved_successfully field from each response.

  4. Skip every record where resolved_successfully is false.

  5. Store the redirect_link value as the real destination.

  6. Send the redirect_link value to Web Scrape or to Clean Domain.

CAUTION: Do not send a short link to a scraping endpoint. The scraper reads the redirect page, and the call returns empty content and costs the full price.

How much does Find Redirect cost?

Find Redirect costs 1 credit per call. At $0.02 a credit, the rate on the 1,000 and 5,000 credit packs, one call costs $0.02. Larger packs cost less per credit. RichAPI charges the credit on a 200 response only. Every error response costs no credits.

Calls

Credits

Cost

1

1

$0.02

100

100

$2.00

1,000

1,000

$20.00

10,000

10,000

$200.00

CAUTION: A response with resolved_successfully: false is still a 200 response. RichAPI charges 1 credit for it.

Which errors can Find Redirect return?

Status

Meaning

What to do

400

The request body is missing, the JSON is not valid, or the link value failed validation. A value fails validation for an empty string, a length over 2048 characters, a scheme other than http or https, or a private host.

Send a JSON object that holds one public http or https URL in link.

401

The API key is missing, wrong or revoked.

Send a valid key in the x-api-key header.

402

The organization has no credits left, or the team reached its monthly spend limit.

Buy credits in the RichAPI dashboard.

403

This API key has no access to this endpoint (Endpoint not available on your plan).

Call GET /api/v1/my-endpoints to see the endpoints that this key can use. Contact support for access.

405

The request used a method other than POST.

Send the request again with the POST method.

429

The request rate is over the limit.

Wait, then send the request again.

500

The API failed.

Send the request again. If the failure repeats, contact support.

Every error response holds an error field with a plain-language message.

Frequently asked questions

How many redirects does Find Redirect follow?

Find Redirect follows 20 redirects. The redirect_count field reports the number of hops that Find Redirect followed, and its maximum value is 20. A chain longer than 20 hops stops at hop 20.

Does Find Redirect return the full chain or only the final URL?

Find Redirect returns both. The redirect_chain field holds every URL in order, and the first entry is the URL that you sent. The redirect_link field holds the final destination on its own.

What happens on a redirect loop?

Find Redirect stops after 20 hops. The response holds redirect_count: 20, a redirect_chain of 21 URLs, and the status code of the last redirect in final_status_code, for example 302. A redirect status code is under 400, so resolved_successfully stays true. To detect the cap, compare redirect_count to 20.

What is the Find Redirect timeout?

Find Redirect waits 10 seconds for each hop. The timeout applies to one hop, and not to the whole chain. A host that does not answer returns a 200 response with final_status_code: 0 and resolved_successfully: false.

Can Find Redirect follow a link to an internal address?

No. Find Redirect blocks localhost, private IP addresses, reserved IP addresses, and link-local IP addresses. Find Redirect runs this check on the first URL and on every hop. An open redirect on a public host therefore cannot reach an internal address.

Does a dead short link still cost a credit?

Yes. A dead short link returns HTTP 200 with resolved_successfully: false, and RichAPI charges 1 credit. RichAPI charges no credit for a 400 error, for example an empty link value.

Is Find Redirect synchronous?

Yes. Find Redirect returns the result in the same response. The endpoint needs no second call, no polling, and no webhook.

Related articles

Did this answer your question?