Error HTTP 508 when redeploying a project

Hello everyone,
Hope you’re all well.
I’m new to the community.

I’m here because I face a problem when I trigger a redeployment using Vercel Rest API.
Here’s the function I use :

# Trigger a redeployment in Vercel
def redeploy_vercel_project():
    """Triggers a redeployment by selecting the latest successful deployment."""
    url = f"{VERCEL_API_BASE_URL}/v6/deployments?projectId={VERCEL_PROJECT_ID}"
    if VERCEL_TEAM_ID:
        url += f"&teamId={VERCEL_TEAM_ID}"

    headers = {"Authorization": f"Bearer {VERCEL_API_TOKEN}"}
    deployments_response = requests.get(url, headers=headers)

    if deployments_response.status_code != 200:
        print(f"❌ Failed to fetch latest deployments: HTTP {deployments_response.status_code}")
        return

    deployments = deployments_response.json().get("deployments", [])

    # Filter out invalid deployments
    valid_deployments = [
        d for d in deployments
        if d["state"] == "READY"
        and d.get("target") == "production"  # Ensure it's a production deployment
        and d.get("source") != "redeploy"  # Avoid re-redeploying already redeployed deployments
        and d.get("readySubstate") != "STAGED"  # Ignore staged deployments
    ]

    if not valid_deployments:
        print("❌ No valid previous deployments found.")
        return

    # Select the most recent successful production deployment
    latest_deployment_id = valid_deployments[0]["uid"]
    print(f"🔹 Using latest deployment ID: {latest_deployment_id} for redeployment.")

    # Redeploy using the latest deployment ID
    redeploy_url = f"{VERCEL_API_BASE_URL}/v13/deployments/{latest_deployment_id}/rebuild"
    if VERCEL_TEAM_ID:
        redeploy_url += f"?teamId={VERCEL_TEAM_ID}"

    redeploy_response = requests.post(redeploy_url, headers=headers)

    if redeploy_response.status_code == 200:
        print("🚀 Successfully triggered a redeployment!")
    elif redeploy_response.status_code == 429:
        print("❌ Too many requests. Vercel is rate-limiting redeployments. Try again later.")
    elif redeploy_response.status_code == 508:
        print("⚠️ Vercel is stuck in a deployment loop. Please check manually.")
    else:
        print(f"❌ Failed to trigger redeployment: HTTP {redeploy_response.status_code}")

All other functions (Update Vercel ENV keys …) are working and I can’t find what is this 508 error.

Thank you in advance.
Paul,

Hello,

Can you try using this payload instead: https://vercel.com/docs/rest-api/endpoints#tag/deployments/create-a-new-deployment ?

if you want to trigger a deployment from a specific branch, you may use something like this:

{
  "name": "YourProjectNameOnVercel", 
  "gitSource": {
    "ref": "yourBranchName",
    "repoId": "gitRepositoryId",
    "sha": "COMMITSHA",
    "type": "github"
  },
  "target": "production"
}

You also should consider using the following forceNew=1 query paremeter - this forces a new deployment (re-deployment) even if there is a previous similar deployment

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.