Add a routing rule
POST
https://api.vercel.com/v1/projects/{projectId}/routesAdd a single routing rule to a project at a specified position. Defaults to the end of the list if no position is provided. The route is enabled by default. Stages a new version with the added route.
https://api.vercel.com/v1/projects/{projectId}/routes
const response = await fetch('https://api.vercel.com/v1/projects/projectId/routes?teamId=string&slug=string', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Content-Type': 'application/json', }, body: JSON.stringify({ "route": { "name": "Example Name", "description": "string", "enabled": "true", "srcSyntax": "equals", "route": { "src": "string", "dest": "string", "headers": "value", "caseSensitive": "true", "status": "123", "has": [ { "type": "host", "key": "string", "value": "string" } ], "missing": [ { "type": "host", "key": "string", "value": "string" } ], "transforms": [ { "type": "request.headers", "op": "append", "target": "value", "args": "value", "env": [] } ], "respectOriginCacheControl": "true" } }, "position": { "placement": "start", "referenceId": "example_id" } }),});
const data = await response.json();console.log(data);Response
{ "route": { "description": "string", "enabled": "false", "id": "icfg_1234567890", "name": "Example Name", "rawDest": "string", "rawSrc": "string", "route": { "caseSensitive": "false", "check": "false", "continue": "false", "dest": "string", "destination": "string", "env": [], "has": [ { "type": "host", "value": "string" } ], "headers": "value", "important": "false", "locale": { "cookie": "string", "redirect": "value" }, "methods": [], "middleware": "123", "middlewarePath": "example_id", "middlewareRawSrc": [], "missing": [ { "type": "host", "value": "string" } ], "mitigate": { "action": "challenge" }, "override": "false", "respectOriginCacheControl": "false", "source": "string", "src": "string", "status": "123", "statusCode": "123", "transforms": [ { "args": "string", "env": [], "op": "append", "target": { "key": "string" }, "type": "request.headers" } ] }, "routeType": "redirect", "srcSyntax": "equals", "staged": "false" }, "version": { "alias": "string", "createdBy": "string", "id": "icfg_1234567890", "isLive": "false", "isStaging": "false", "lastModified": "123", "ruleCount": "123", "s3Key": "string" }}AuthorizationbearerToken
Default authentication mechanism
400One of the provided values in the request body is invalid.
One of the provided values in the request query is invalid.
401The request is not authorized.
403You do not have permission to access this resource.
404Error
409Error
410Error
500Error