I would first make sure you're using the latest version of the API, which is v4. The endpoint to use to trigger a pipeline is:
POST /projects/:id/trigger/pipeline
Next up, you will want to ensure you have the correct project ID in the API URL. You can get this by going to your project's page on GitLab and looking at the URL. It should look something like:
https://gitlab.com/username/project-name
The project ID is that number that pops up when you hover over the project name.
You will want to make sure you have the correct trigger token. You can create a new trigger token by going to your project's Settings > CI/CD > Pipeline Triggers. Be sure to remember to keep that token safe and not share it with the world.
When you're ready to make the API call, make sure you're sending the correct parameters (token
and ref
) as form data. Here's a simple example in cURL:
curl --request POST \
--form token=YOUR_TRIGGER_TOKEN \
--form ref=main \
https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/trigger/pipeline
Remember to replace YOUR_TRIGGER_TOKEN with your actual trigger token and YOUR_PROJECT_ID with your project ID.
I saw this problem the other day. The last thing to mention is to double-check that you're using the trigger token and not mixing it with a personal access token. The trigger token is specifically designed for triggering pipelines, while a personal access token is used for authentication when working with the GitLab API.
If you've double-checked all of the above and you're still seeing a 404 error, it could be due to a few reasons:
- The project ID might be incorrect, or the project doesn't exist.
- The trigger token might be invalid or has been revoked.
- You might not have the right permissions to trigger a pipeline for the specified project.
If you still have problems and you have access to the gitlab server logs, I would look there.