You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jekyll/_cci2/api-developers-guide.md
+29-29Lines changed: 29 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ To add an API token, perform the steps listed below.
59
59
60
60
**Note:** All API calls are made in the same way, by making standard HTTP calls, using JSON, a content-type, and your API token. Please note that the JSON examples shown in this document are not comprehensive and may contain additional JSON response fields not shown in the example, based on user input and fields.
61
61
62
-
# Getting Started with the API
62
+
## Getting Started with the API
63
63
64
64
The CircleCI API shares similarities with previous API versions in that it identifies your projects using repository name. For instance, if you want to pull information from CircleCI about the GitHub repository https://github.com/CircleCI-Public/circleci-cli you can refer to that in the CircleCI API as `gh/CircleCI-Public/circleci-cli`, which is a “triplet” of the project type (VCS provider), the name of your “organization” (or your username), and the name of the repository.
65
65
@@ -75,23 +75,23 @@ The `project_slug` is included in the payload when pulling information about a p
When you make an API request to the server, an HTTP status code is returned along with the JSON body response. The CircleCI API v2 adheres to standard HTTP response codes, which include the following status code definitions:
81
81
82
82
* 200 - Success
83
83
* 400 - Client error
84
84
* 500 - Server error
85
85
86
-
## 200 Status Codes
86
+
### 200 Status Codes
87
87
88
88
If you receive a 200 HTTP status code, your API request is successful and the requested resource will be returned. The following 200 HTTP status codes could potentially be returned with your request:
89
89
90
90
* 200 - OK
91
91
* 201 - Created
92
92
* 202 - Accepted
93
93
94
-
## 400 Status Codes
94
+
### 400 Status Codes
95
95
96
96
If you receive a 400 HTTP status code, there is a problem with the request and the server is unable to successfully process the request. The following status codes may be returned with your request:
97
97
@@ -100,13 +100,13 @@ If you receive a 400 HTTP status code, there is a problem with the request and t
100
100
* 404 - Not Found
101
101
* 429 - Too Many Requests (see [rate limits](#rate-limits)).
102
102
103
-
## 500 Status Code
103
+
### 500 Status Code
104
104
105
105
If you receive a 500 HTTP status code, there is a problem with the server and the request cannot be processed. If you encounter a 500 response, the error will be logged and CircleCI will work to resolve the error. The following 500 HTTP status codes could potentially be returned with your request:
106
106
107
107
* 500 - Internal Server Error
108
108
109
-
# Rate Limits
109
+
## Rate Limits
110
110
111
111
The CircleCI API is protected by a number of rate limiting measures to ensure the stability of the system. We reserve the right to throttle the requests made by an individual user, or the requests made to individual resources in order to ensure a fair level of service to all of our users.
112
112
@@ -116,22 +116,22 @@ There are different protections and limits in place for different parts of the A
116
116
For HTTP APIs, when a request is throttled, you will receive [HTTP status code 429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429). If your integration requires that a throttled request is completed, then you should retry these requests after a delay, using an exponential backoff.
117
117
In most cases, the HTTP 429 response code will be accompanied by the [Retry-After HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After). When this header is present, your integration should waitfor the period of time specified by the header value before retrying a request.
118
118
119
-
# REST API Tutorial
119
+
## REST API Tutorial
120
120
121
121
For more detailed information about HTTP status codes, refer to the [rest api tutorial](http://www.restapitutorial.com/httpstatuscodes.html).
122
122
123
-
# Example End-to-End API Request
123
+
## Example End-to-End API Request
124
124
125
125
The following section details the steps you would need, from start to finish, to make an API call. This section includes creating a "demo repository" called "hello-world", however, you can use a pre-existing repository to follow along if you choose.
126
126
127
127
**NOTE:** Many of the API calls make use of the `{project-slug}` triplet, described [above](#getting-started-with-the-api).
128
128
129
-
## Prerequisites
129
+
### Prerequisites
130
130
131
131
* A GitHub or BitBucket account with a repository to setup with CircleCI.
132
132
* Completion of the CircleCI onboarding.
133
133
134
-
## Steps
134
+
### Steps
135
135
136
136
1. On your VCS provider, create a repository. The repo for this example will be called `hello-world`.
137
137
@@ -262,7 +262,7 @@ The following section details the steps you would need, from start to finish, to
262
262
263
263
This concludes the end-to-end example of using the V2 API. For more detailed information about other endpoints you may wish to call, please refer to the [CircleCI API v2 Documentation]({{site.baseurl}}/api/v2/#circleci-api) for an overview of all endpoints currently available.
264
264
265
-
# Additional API Use Cases
265
+
## Additional API Use Cases
266
266
267
267
Now that you have a general understanding of how the CircleCI API v2 service works through an end-to-end API example request and walkthrough, let's look at a few common tasks and operations you may perform on a regular basis when using the API. Whether you wish to return information about a job or project, or retrieve more detailed information about a project by reviewing its artifacts, the examples shown below should assist you in gaining a better understanding of how to make some API requests to the server so you can perform a deep dive into the specifics of your work.
268
268
@@ -281,7 +281,7 @@ This section provides detailed information on how you can perform the following
281
281
* [Download artifacts](#download-artifacts)
282
282
* [Gather Insights](#gather-insights)
283
283
284
-
## Get Project Details
284
+
### Get Project Details
285
285
286
286
You may often find that it would be helpful to retrieve information about a specific project, including the name of the organization the project belongs to, the version control system (vcs) that hosts the project, and other details. The CircleCI API enables you to return this and other information by making a single GET request to the `project/{project-slug}` endpoint by passing the `project-slug` parameter.
287
287
@@ -295,7 +295,7 @@ The `project_slug` is included in the payload when you pull information about a
295
295
296
296
**Note** If you would like more detailed information about a project, or simply need a refresher on the specifics of a project, please refer to the CircleCI [Projects](https://circleci.com/docs/2.0/projects/) page.
297
297
298
-
### Steps
298
+
#### Steps
299
299
300
300
Of the several project-related API endpoints available with CircleCI API v2, making a GET request to the `/project/{project-slug}` endpoint enables you to return detailed information about a specific project by passing the `project_slug` parameter with your request.
301
301
@@ -329,13 +329,13 @@ To return project details, perform the following steps:
329
329
330
330
Notice in the example above that you will receive very specific information about your project, including the name of the project, the name of the organization that the project belongs to, and information about the VCS that hosts the project. For a more detailed breakdown of each value returned in this request, please refer to the [Get Project Details](https://circleci.com/docs/api/v2/#get-a-project) section of the *CircleCI API v2 Reference Guide*.
331
331
332
-
## Get Job Details
332
+
### Get Job Details
333
333
334
334
Much like the Get Project Details API request described in the previous example, the Get Job Details API request enables you to return specific job information from the CircleCI API by making a single API request. Retrieving job information can be very useful when you want information about how your job performed, what resources were used (e.g. pipeline, executor type, etc.), and the time it took for the job to finish.
335
335
336
336
Please remember, jobs are collections of steps. Each job must declare an executor that is either `docker`, `machine`, `windows` or `macos`. `machine` includes a default image if not specified, for `docker` you must specify an image to use for the primary container, for `macos` you must specify an Xcode version, and for `windows` you must use the Windows orb.
337
337
338
-
### Steps
338
+
#### Steps
339
339
340
340
Of the several Jobs-related API endpoints available with CircleCI API v2, there is a specific endpoint you may wish to call to receive detailed information about your job. This API call to the `GET /project/{project_slug}/job/{job-number}`endpoint enables you to return detailed information about a specific job by passing the `project-slug` and `job-number` parameters with your request.
341
341
@@ -404,11 +404,11 @@ Notice in the example above that you will receive very specific information abou
404
404
405
405
For a more detailed breakdown of each value returned in this request, please refer to the [Get Job Details](https://circleci.com/docs/api/v2/#get-job-details) section of the *CircleCI API v2 Reference Guide*.
406
406
407
-
## Download Artifacts
407
+
### Download Artifacts
408
408
409
409
The following section details the steps you need to follow to download artifacts that are generated when a job is run, first, returning a list of artifacts for a job, and then downloading the full set of artifacts. If you are looking for instructions for downloading the _latest_ artifacts for a pipeline, without needing to specify a job number, see our [API v1.1 guide](https://circleci.com/docs/2.0/artifacts/#downloading-all-artifacts-for-a-build-on-circleci) – keep checking back here as this functionality will be added to API v2 in the future.
410
410
411
-
### Steps
411
+
#### Steps
412
412
413
413
1. First, we will ensure your API token is set as an environment variable. You maybe have already done this during authentication, but if not, run the following command in your terminal, substituting your personal API token:
414
414
@@ -462,11 +462,11 @@ The following section details the steps you need to follow to download artifacts
462
462
463
463
**Note:**`grep` is used to locate all the URLs for downloading the job artifacts, while`wget` is used to perform the download.
464
464
465
-
## Gather Insights
465
+
### Gather Insights
466
466
467
467
The CircleCI API v2 also includes several endpoints that enable you to retrieve detailed insights into your workflows and individual jobs. By making API calls to these endpoints, you can better understand how to optimize your workflows and jobs so you can increase workflow performance while minimizing credit usage and consumption. The example below describes how you can return information about a single workflow containg information about metrics and credit usage.
468
468
469
-
### Returning Workflow Metrics
469
+
#### Returning Workflow Metrics
470
470
471
471
To return aggregated data for an individual workflow, perform the steps listed below.
472
472
@@ -566,7 +566,7 @@ Notice that in this JSON response, you will receive detailed metrics for the set
566
566
567
567
**Note** The above example only shows just a few builds. When you run this command, you may receive up to 250 individual builds that you can review in much more detail.
568
568
569
-
### Reviewing Individual Job Metrics
569
+
#### Reviewing Individual Job Metrics
570
570
571
571
Now that you have retrieved aggregated data for up to 250 different jobs, you will most likely want to review specific information about a single job, or smaller number of jobs, to ensure that your jobs are running efficiently. To review an individual job, follow the steps below.
572
572
@@ -643,23 +643,23 @@ When reviewing each individual review job, please note that the following inform
643
643
- `stopped_at` - The time the job ended.
644
644
- `credits_used` - The number of credits used during the job.
645
645
646
-
# Reference
646
+
## Reference
647
647
648
-
## API Endpoints
648
+
### API Endpoints
649
649
650
650
The CircleCI v2 API, and its associated endpoints allow you to make HTTP calls to designated endpoints developed in the underlying CircleCI API architecture. These endpoints provide programmatic access to CircleCI services, including pipelines, workflows, and jobs.
651
651
652
652
Before working with the API and making calls, you should first have an understanding of the various API requests you can make to API v2 endpoints. The sections below describe these API requests.
| GET /user/{id} | This endpoint enables you to return information about a specific user by making a GET request and passing the `id` parameter in the request |
659
659
| GET /me/collaborations | This endoint enables you to return a list of organizations that the user is a member of, or is a collaborator by making a GET request and passing the `collaborations` parameter in the request. |
0 commit comments