Unable to send branch name to circleci API v2 to trigger a pipeline

Previously, I was able to trigger a pipeline on a particular branch using the Circleci V1.1 API.

curl -s -u ${token}: https://circleci.com/api/v1.1/project/github/org/job-name/tree/$branch

which was successfully able to Trigger a pipeline.

I want to upgrade to circleci 2.1and so the above will no longer work.

I am trying:

curl -f -u ${token}: -X POST --header “Content-Type: application/json” -d ‘{“parameters”: {“branch”: “$branch”}}’ https://circleci.com/api/v2/project/gh/org/job-name/pipeline

However, this is always triggered on the master branch, rather than the branch that I specify in the param.

Any advice?

In v2 you pass branch as a top level key rather than inside parameters

@ndintenfass Could you provide an example?

Thank you!

To use your example, it would look something like:

curl -f -u ${token}: -X POST --header "Content-Type: application/json" -d '{"branch": "$branch"}' https://circleci.com/api/v2/project/gh/org/job-name/pipeline