CircleCI-Archived / api-preview-docs

In-progress docs about the pre-release preview of CircleCI API v2
72 stars 39 forks source link

only 'master' branch is triggered using v2 API #46

Open Erilarn opened 4 years ago

Erilarn commented 4 years ago

I'm trying to trigger a build on specified branch using such v2 API call:

curl -u ${CIRCLECI_TOKEN}: -X POST "Content-Type: application/json" -d '{"branch": "some-branch"}' https://circleci.com/api/v2/project/${project_slug}/pipeline

EXPECTED RESULT: I expect the branch specified in branch parameter will be triggered.

ACTUAL RESULT: Instead of specified branch master always trigger.

peterbamsey commented 4 years ago

This seems to be working pretty consistently for us. @Erilarn Can I check, does ${project_slug} in your example expand to :vcs/:org/:project as per the documentation? For example: https://circleci.com/api/v2/project/github/mycompany/myrepo/pipeline ?

Erilarn commented 4 years ago

@peterbamsey As you can see from the actual result I'm able to trigger the build using my ${project_slug}. Doesn't it mean it's correct?

izikorgad commented 4 years ago

+1

ya-riel commented 4 years ago

Had the same problem, and found the issue. You have to add a header with content type application/json. The following should work for you: curl -u ${CIRCLECI_TOKEN}: -X POST "Content-Type: application/json" -H 'Content-Type: application/json' -d '{"branch": "some-branch"}' https://circleci.com/api/v2/project/${project_slug}/pipeline

Erilarn commented 4 years ago

@ya-riel I checked it out. You're right, thank you so much!

ya-riel commented 4 years ago

Glad to hear that I helped. Just for the record - the credit for pinpointing the issue goes to @izikorgad ;)