# CircleCI API follow a new project

**URL:** <https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410>\
**Category:** API\
**Tags:** 2.0\
**Created:** [December 23, 2022, 12:55pm UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410 "2022-12-23T12:55:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![meraj-kashi](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/meraj-kashi/32/29214_2.png) [@meraj-kashi](https://discuss.circleci.com/u/meraj-kashi)\
**Post date:** [December 23, 2022, 12:55pm UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/1 "2022-12-23T12:55:22Z")

</div>

Hi!  
According to the V1 API documentation ([CircleCI API Reference](https://circleci.com/docs/api/v1/index.html#follow-a-new-project-on-circleci)), following a new project API will be deprecated soon and I can’t see the equal API in V2.  
Any plan to add this API endpoint V2?

Br,  
Meraj

---

<div class="post-metadata">

**Author:** ![jkzilla](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jkzilla/32/19750_2.png) [@jkzilla](https://discuss.circleci.com/u/jkzilla)\
**Post date:** [December 28, 2022, 8:52pm UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/2 "2022-12-28T20:52:31Z")

</div>

Please vote and subscribe to the CircleCI feature request on this issue which will be updated with the relevant information when available: [Add follow project endpoint to v2 API | API | CircleCI Ideas](https://ideas.circleci.com/api-feature-requests/p/add-follow-project-endpoint-to-v2-api)

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [January 26, 2023, 12:02am UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/3 "2023-01-26T00:02:51Z")

</div>

I love Circle, but the whole way “following” projects works seems (to me) very suboptimal. As someone who does infra work (and the recent security incidents are a good example), I often need to do bulk operations on lots of repos. With the current setup:

- A project won’t build unless it has at least one follower (projects can stop building unexpectedly)
- The `get_projects` API endpoint _only_ returns projects that you follow
- If you’ve _ever_ pushed to a branch in a project you follow, you can’t stop getting notifications about it unless you disable notifications of failed builds for _all_ projects and _all_ branches (also, the notifications settings page where you can do this doesn’t seem to work at _all_ on mobile).

I started working on a simple tool (using [GitHub - alpinweis/pycircleci: Python client for CircleCI API](https://github.com/alpinweis/pycircleci)) to autofollow projects, both for my own account and for a bot / machine account. But, then found out:

- If you run `follow_project` on a project not setup for Circle, it will implicitly start building it (oops)

Ok, so we can get a list of all our github repos, then run `get_project` for each (non-archived) repo name, but now:

- If you’d accidentally first done the above for all your projects, but then run “stop building” and remove webhooks / deploy keys, then the `get_project` API endpoint stops working properly (i.e., it will return data even though the project is no longer setup). I’ve contacted support to delete projects to try and fix this, but that hasn’t worked so far either, even after they confirmed deletion.

High level, IMO, Circle should stop coupling “repos I can see / manage from the API” with “repos I ‘follow’”

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [January 26, 2023, 12:20am UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/4 "2023-01-26T00:20:28Z")

</div>

> **[API to list all enabled projects ( not just followed ) | API | CircleCI Ideas](https://ideas.circleci.com/api-feature-requests/p/api-to-list-all-enabled-projects-not-just-followed)**

> **[/Projects API endpoint - Gather ALL projects from given org | API | CircleCI...](https://ideas.circleci.com/api-feature-requests/p/projects-api-endpoint-gather-all-projects-from-given-org)**

Two more ideas to vote for

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [January 26, 2023, 6:26am UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/5 "2023-01-26T06:26:18Z")

</div>

Actually, found out from support this won’t work either… even if the project has never been built, going to it once will create a db record for it…

i.e, if you go to [https://app.circleci.com/pipelines/github/someord/repo](https://app.circleci.com/pipelines/github/someord/repo) for a project that’s not setup, reload it at least once, it’ll now be setup, and `get_project` will now have a record.

they did point me to  
[https://circleci.com/api/v1.1/user/repos/github?page=1&per-page=100](https://circleci.com/api/v1.1/user/repos/github?page=1&per-page=100)  
which should show all the repos you have the ability to see, at which point you can use `"has_followers" : false` to infer whether a repo is setup or not.

---

<div class="post-metadata">

**Author:** ![yannCI](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/yannci/32/24866_2.png) [@yannCI](https://discuss.circleci.com/u/yannCI)\
**Post date:** [January 27, 2023, 4:27pm UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/6 "2023-01-27T16:27:23Z")

</div>

Hi @wyardley,

Using the `"has_followers" : false` as an identifier of actual projects is indeed a good idea.

However, it has two caveats:

- A project could be set up but find itself with no followers at some point (for example, if all followers leave the org)
- A project that has stopped building remains in CircleCI (unless you explicitly request deletion), even if you delete the related repository in the VCS. And unless you manually removed them, secrets and other configuration settings will still be present.

I found that one way to identify repositories that correspond to actual CircleCI projects (current or past) is to check if CircleCI has knowledge of any branch in the repository.

This info can be found by querying the `https://circleci.com/api/v1.1/project/<project_slug>/settings` endpoint, and checking the length of the `branches` object in the JSON response.

```auto
curl "https://circleci.com/api/v1.1/project/<project_slug>/settings" \
-H "Circle-Token: <api_token> | jq '.branches|length'

```

If the above command returns a non-zero result, then the repository corresponds to a current or past CircleCI project.

Let me know what you think. Would really appreciate your feedback on this.

_N.B: The endpoint `https://circleci.com/api/v1.1/user/repos/github?page=1&per-page=100` will the first page of repos (up to `100`) so if the number of repos is indeed number you’ll need to fetch the following page until the page contains less than `100` repos._

---

<div class="post-metadata">

**Author:** ![wyardley](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/wyardley/32/19231_2.png) [@wyardley](https://discuss.circleci.com/u/wyardley)\
**Post date:** [February 1, 2023, 6:15pm UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/7 "2023-02-01T18:15:07Z")

</div>

@yannCI thanks

Yes, aware of the “not following will stop building” issue - actually, the reason I’m writing this tool is exactly that - to follow repos that we’re “building” under a predictable bot user. So, assuming my script works, as long as it’s run periodically, should not run into that condition.

> A project that has stopped building remains in CircleCI

Yeah, that’s what I discovered, and also, even if you’ve never built it, `get_repo` will show it once someone’s hit it once via a specific page in the Circle UI 😞

> _so if the number of repos is indeed number you’ll need to fetch the following page until the page contains less than `100` repos_

I PRed support for this endpoint upstream to the library I’m using, so should be good on pagination.

> <https://github.com/alpinweis/pycircleci/pull/27>
>
> This endpoint provides some summary info about all the repos a user has the abil…ity to see.
> 
> This is useful because \`get\_projects\` only shows projects a user is following, and \`get\_project\` can show a project as existing even if it isn't currently setup. By checking \`has\_followers\` and filtering by org name, this lets one more easily get a list of repos which exist in an org, but which one is not following
> 
> Some more context:
> https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/3
> 
> I didn't want to put a big enough test fixture to test pagination, but I’ve locally tested paginated endpoints with the new changes.

High level, I guess I wish Circle would rework how you all think about returning and “building” repos based on API requests; kind of summarized my thoughts in the first “ideas” link above.

Thanks for the other suggestion - I’ll see if it’s trivial to add that as an extra check / guard, though I think using the endpoint above should work for my purposes for now.

---

<div class="post-metadata">

**Author:** ![skfarhat](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/skfarhat/32/29238_2.png) [@skfarhat](https://discuss.circleci.com/u/skfarhat)\
**Post date:** [April 7, 2023, 7:42am UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/8 "2023-04-07T07:42:50Z")

</div>

I’d like to double down on @wyardley’s comments above.  
The need to follow a project for CircleCI to start building it coupled with the absence of a “follow a project” API endpoint in v2 is bewildering to me.

How are CircleCI users expected to built automation on top of their CI (e.g. automate creation) in the absence of such APIs?

Also, I had the same issues around a year ago and was coming back now hoping something had been developed in that aread. Alas 😕

---

<div class="post-metadata">

**Author:** ![olafmol](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/olafmol/32/32599_2.png) [@olafmol](https://discuss.circleci.com/u/olafmol)\
**Post date:** [December 8, 2023, 1:23pm UTC](https://discuss.circleci.com/t/circleci-api-follow-a-new-project/46410/9 "2023-12-08T13:23:52Z")

</div>

Hi all, we have released new API v2 endpoints to create/follow and configure projects programmatically through our API. Let me know what you think!

> [@Create/Follow Project v2 API endpoint now in open preview](https://discuss.circleci.com/t/create-follow-project-v2-api-endpoint-now-in-open-preview/49953):
>
> In our ongoing effort to support valuable automation and integration use cases, and improve our public API, we’ve recently released the Create/Follow Project API v2 endpoint. This v2 API endpoint allows you to create a new CircleCI project, and returns a list of the default advanced settings. It can also be used to follow a new project. CircleCI will then monitor the project for automatic building of commits. This endpoint is especially useful for those wanting to incorporate the creation of C…

> [@Project Settings API v2 endpoints now in open preview](https://discuss.circleci.com/t/project-settings-api-v2-endpoints-now-in-open-preview/49999):
>
> We’re keeping the momentum going on improving our public API v2 endpoints, and have recently released new Project Settings API v2 endpoints. These endpoints allow you to programmatically read and update the advanced Project settings. This will be especially useful for those wanting to incorporate the configuration of CircleCI projects into your automated processes. Combined with the new Create/Follow Project endpoint, these endpoints provide powerful automation and integration possibilities. N…
