I had a similar problem - I want to construct a hyperlink that, when a user clicks on, it, runs a Circle pipeline with my pipeline parameters in the get query, as you want here.
Like your webhook request, a hyperlink is a GET request, not a POST request. However the documentation says the pipeline triggering API is a POST request.
AND I can’t just construct a URL that points to somewhere on circleci.com, although that would be awesome. It would actually fix having to worry about the CircleCI token because you have a cookie when you use the web UI. (That would have worked in my case, anyway).
So you need a translator. I wrote the following Google Cloud Function, although 2 lines of change would make it work under AWS Lambda or whatever. You can allow selected identities to run the function in IAM controls, or depend on security by obscurity.
Anyway, here’s 40 lines of sloppy Node.js code (half generated by Postman) using axios to make the request
const functions = require('@google-cloud/functions-framework');
var axios = require('axios');
functions.http('ciTrigger', (req, res) => {
var branch = req.query.branch || "main"
var orgRepo = req.query.orgRepo || "mygithuborb/my-default-repo";
if (req.query.branch) {
delete req.query.branch
}
if (req.query.orgRepo) {
delete req.query.orgRepo
}
var data = JSON.stringify({
"branch": branch,
"parameters": req.query
});
var config = {
method: 'post',
url: `https://circleci.com/api/v2/project/gh/${orgRepo}/pipeline`,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Circle-Token': process.env.CIRCLE_TOKEN
},
data: data
};
axios(config)
.then(function(response) {
var pipelineNum = response.data.number
res.send(`<html><body><a href="https://app.circleci.com/pipelines/github/${orgRepo}/${pipelineNum}">Open in Circle</a></body></html>`);
})
.catch(function(error) {
res.send(error);
});
});
Then the following link will work
https://BAZ-BAR-WHERE-THIS-FUNCTION-LIVES.a.run.app/?name=ryan
and calls your pipeline with a variable name whose value = “ryan”.
https://BAZ-BAR-WHERE-THIS-FUNCTION-LIVES.a.run.app/?name=ryan&orgRepo=boo%2Frepo triggers the build in boo org’s repo repo, running the pipeline with that name parameter.
It’ll even give you a link to the Circle UI, with my awesome HTML skillz.