Skip to content

Commit e359bf6

Browse files
committed
docs: add CircleCI API notes
1 parent 54cd19a commit e359bf6

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

docs/CircleCI-API.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# CircleCI API
2+
3+
* [CircleCI API Developer's Guide](https://circleci.com/docs/2.0/api-developers-guide/)
4+
5+
## Authentication
6+
7+
* generate [Personal API Token](https://app.circleci.com/settings/user/tokens) which is associated with a user
8+
* test the token works
9+
10+
```bash
11+
~> curl \
12+
-s \
13+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
14+
https://circleci.com/api/v2/me
15+
~>
16+
```
17+
18+
## Accept Header
19+
20+
* use an accept header to return compressed json
21+
22+
```bash
23+
~> curl \
24+
-s \
25+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
26+
--header 'Accept: application/json' \
27+
https://circleci.com/api/v2/me
28+
~>
29+
```
30+
31+
## URLs
32+
33+
* project slug = ```gh/simonsdave/cloudfeaster```
34+
* example URL ```https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/pipeline```
35+
36+
## Rate Limiting
37+
38+
* API implements rate limiting
39+
* HTTP status code of 429 when rate limiting tripped and [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After)
40+
header may be returned with the response and in the absense of such a header
41+
clients should use an exponential backoff approach to retry
42+
43+
## Get Project Details
44+
45+
```bash
46+
~> curl \
47+
-s \
48+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
49+
--header 'Accept: application/json' \
50+
https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster
51+
~>
52+
```
53+
54+
## Get All Pipelines For A Repo
55+
56+
```bash
57+
~> curl \
58+
-s \
59+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
60+
--header 'Accept: application/json' \
61+
https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/pipeline
62+
~>
63+
```
64+
65+
## Trigger a Pipeline
66+
67+
```bash
68+
~> curl \
69+
-s \
70+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
71+
-X POST \
72+
--header 'Content-Type: application/json' \
73+
--data '{"branch": "master"}' \
74+
--header 'Accept: application/json' \
75+
https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/pipeline
76+
~>
77+
```
78+
79+
## Scheduled Pipelines
80+
81+
* [Scheduled Pipelines](https://circleci.com/docs/2.0/scheduled-pipelines)
82+
* [7 Jan '22 - Getting started with scheduled pipelines](https://circleci.com/blog/using-scheduled-pipelines/)
83+
* can configure schedules under ```project settings / triggers``` (ex [https://app.circleci.com/settings/project/github/simonsdave/cloudfeaster/triggers](https://app.circleci.com/settings/project/github/simonsdave/cloudfeaster/triggers))
84+
85+
### Get All Schedules
86+
87+
```bash
88+
~> curl \
89+
-s \
90+
--verbose \
91+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
92+
--header 'Accept: application/json' \
93+
https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule
94+
```
95+
96+
### Create Schedule
97+
98+
* [https://circleci.com/docs/api/v2/#operation/createSchedule](https://circleci.com/docs/api/v2/#operation/createSchedule)
99+
* note = "hour of day" is in UTC; API docs don't make this clear but you can see from the UI
100+
101+
```bash
102+
~> curl \
103+
-s \
104+
--verbose \
105+
--header "Circle-Token: ${PERSONAL_API_TOKEN}" \
106+
-X POST \
107+
--header 'Content-Type: application/json' \
108+
--data-raw '{
109+
"name": "Run Integration Tests",
110+
"description": "Run intergration tests every day",
111+
"attribution-actor": "system",
112+
"parameters": {
113+
"branch": "master"
114+
},
115+
"timetable": {
116+
"per-hour": 1,
117+
"hours-of-day": [16],
118+
"days-of-week": ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
119+
}
120+
}' \
121+
--header 'Accept: application/json' \
122+
https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule
123+
```

0 commit comments

Comments
 (0)