Skip to main content

Endpoint

POST /add-redirect

Function signature

export const addRedirect = async (data: AddRedirectProps): Promise<AxiosResponse>

Request body

fromDomain
string
required
The domain from which the redirect originates
toDomain
string
required
The domain to which the redirect points
redirectType
RedirectType
required
The type of redirect. Must be either permanent or temporary
pathForwarding
boolean
required
Indicates whether the path should be forwarded
queryForwarding
boolean
required
Indicates whether the query parameters should be forwarded
samplingRate
number
required
The sampling rate for analytics. Must be a value between 0 and 1

Type definitions

type AddRedirectProps = {
  fromDomain: string;
  toDomain: string;
  redirectType: RedirectType;
  pathForwarding: boolean;
  queryForwarding: boolean;
  samplingRate: number;
};

enum RedirectType {
  Permanent = 'permanent',
  Temporary = 'temporary',
}

Response

status
number
HTTP status code
data
object
The created redirect object

Code example

import { addRedirect } from '@/lib/api';
import { RedirectType } from '@/lib/constants';

const createRedirect = async () => {
  const response = await addRedirect({
    fromDomain: 'example.com',
    toDomain: 'newsite.com',
    redirectType: RedirectType.Permanent,
    pathForwarding: true,
    queryForwarding: true,
    samplingRate: 1.0
  });
  
  return response.data;
};
The samplingRate parameter controls what percentage of traffic is tracked for analytics. A value of 1.0 means 100% of requests are tracked, while 0.5 means 50% are sampled.

Error responses