How to create vercel alias using Vercel REST API
To enhance my workflow, I’m transitioning from using the Vercel CLI command vercel alias
to generate aliases, to leveraging the Vercel REST API. The API documentation specifies using the deploymentID parameter to assign an alias (https://vercel.com/docs/rest-api/endpoints/aliases#assign-an-alias).
Here’s a snippet of my current workflow:
- name: Build and deploy
id: build-and-deploy
run: |
vercel build --debug --token=${{ secrets.VERCEL_TOKEN }} --scope=***
DEPLOYMENT_URL=$(vercel deploy --prebuilt --yes --token=${{ secrets.VERCEL_TOKEN }} --scope=***)
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> "$GITHUB_OUTPUT"
- name: Assign aliases
run: |
SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
vercel alias ${{ steps.build-and-deploy.outputs.DEPLOYMENT_URL }} ${SHORT_SHA}.example.com --token=${{ secrets.VERCEL_TOKEN }} --scope=*** | awk '{print $3}')" >> "$GITHUB_OUTPUT"
How can I obtain the deployment ID and integrate it into the Vercel REST API call for alias assignment? Any insights or suggestions would be greatly appreciated.