LGTM API specification
The REST API for LGTM provides data so that you can customize how you integrate LGTM analysis into your workflow. It includes the following resources:
/()—get version information or download the specification in OpenAPI format./projects()—list projects, get a summary of the current status for a project, or add new projects./analyses()—get a summary of results, download all the alerts, or trigger analysis for a specific commit./codereviews()—trigger code review for a patch, and view the results./operations()—get information about long-running tasks, for example, analyses or code reviews that you've requested./snapshots()—download and upload databases representing a snapshot of a codebase./queryjobs()—submit queries to evaluate against existing projects, and download their results./system()—get information on the health or usage of the system.
For an overview and getting started topics, see .
- Homepage
- https://api.apis.guru/v2/specs/lgtm.com/v1.0.json
- Provider
- lgtm.com
- OpenAPI version
- 3.0.1
- Spec (JSON)
- https://api.apis.guru/v2/specs/lgtm.com/v1.0/openapi.json
- Spec (YAML)
- https://api.apis.guru/v2/specs/lgtm.com/v1.0/openapi.yaml
Tools (31)
Extracted live via the executor SDK.
-
analyses.getAlertsDownload all the alerts found by an analysis. Use the
Accept:request header to specify the output media type as either CSV or :-
application/sarif+json: Alerts in SARIF format. If no version is specified the latest supported SARIF version is used. -
application/json: Alerts in SARIF format (deprecated). If no version is specified, is used for backwards compatibility. -
text/csv: Alerts in CSV format. Thetext/csvmedia type has two optional parameters:charset: determines the character encoding of the text, by default UTF-8.header: determines whether a header row with column names ispresentorabsent. The default value for this parameter ispresent. For example, an Accept header with valuetext/csv; header=absentwould result in CSV output without a header row.
To find the analysis identifier for a commit, use the
/analyses/{project-id}/commits/{commit-id}endpoint. For more information, see . -
-
analyses.getAnalysisGet a summary of the analysis results for a specific analysis identifier.
To find the analysis identifier for a commit, use the
/analyses/{project-id}/commits/{commit-id}endpoint. For more information, see .This endpoint reports the commit analyzed and a summary of the results for each language. Alternatively, you can use this identifier to download full details of all the alerts found by the analysis. For more information, see .
-
analyses.getAnalysisForCommitGet a summary of the analysis results for a specific commit, or the latest commit, to a project. (For projects configured for sparse or upload analysis, only
latestis supported.)This endpoint reports a summary of results for each language, and also the analysis identifier. You can use the analysis identifier to download full details of all the alerts found by the analysis. For more information, see .
-
analyses.requestAnalysisTrigger the analysis of a specific commit to a project. If a previous attempt to analyze that commit failed, this triggers a fresh analysis. This is supported for all LGTM projects, regardless of repository type or host. The commit must be available in the main repository, but can be on a branch that isn't tracked by LGTM. For both LGTM.com and LGTM Enterprise, you must include an access token with the
analyses:writescope.When you request the analysis of a commit, the API returns:
operation-id: used to track the status of the task using the/operationsendpoint. For more information, see .status: initially pending.task-result: containing information about the progress and results of the analysis.
-
apiRoot.getSpecGet the specification of this API in format. This endpoint does not require an access token. This makes it easier for you to use the specification with third-party tools.
-
apiRoot.getVersionGet the version information of this API.
-
codeReviews.getCodeReviewGet the results of a code review using the review identifier for the task.
When you request a code review, the response includes a task result URL of the form:
/codereviews/{review-id}.This endpoint reports the results of a complete code review, or the status of a review that's still in progress.
-
codeReviews.requestReviewTrigger the code review of a patch. This is available for projects with Git repositories.
Your request must include:
- Identifier for the base commit
- Patch generated using
git diff --binary(see ) - Header
Content-Type: application/octet-stream - For both LGTM.com and LGTM Enterprise, an access token with the
codereviews:writescope
Note that if you make a request using Curl, you'll also need to add
--data-binaryto the request to ensure that the patch you supply in the body is sent with newlines unchanged. You can track the progress of the review using the task result URL returned on creation of the task, or by calling the/operationsendpoint with the operations identifier returned by the request. For more information, see . Alternatively, if you supply a callback URL you'll get a post-back automatically on completion of the review.When the review is complete, you can access the results using the task result URL.
-
issues.getIssueFetch the alert information for an issue in format.
-
operations.getOperationTrack progress of a long-running operation using the operations identifier returned when you created the operation. For example, by triggering the analysis of a commit, or the code review of a patch. For both LGTM.com and LGTM Enterprise, you must include an access token with the
operations:readscope. -
projects.addProjectLGTM administrators can add a new project to LGTM by providing a repository URL. By default, LGTM tries to build and analyze the project in the same way as for projects added through the user interface. If at least one language is successfully analyzed, and the repository doesn't already exist on LGTM, a new project is created. If the project already exists but your API call triggers a successful analysis of additional languages, LGTM adds those languages to the project.
You can configure how LGTM processes the project using query parameters to:
- Specify the languages to analyze.
- Create a new project in .
- Create a new project in to analyze externally-generated databases. Each database represents a snapshot of the codebase. Use this option when you want to upload databases that were generated by the CodeQL CLI (or the QL command-line tools). The version of the command line used to generate the database must be the same version as LGTM Enterprise.
With any of these options, you can also include an
lgtm.ymlin the body of the request to . -
projects.deleteProjectDelete a project with a particular numeric project identifier. In addition to access to the project, administrative access to LGTM or the LGTM Enterprise instance is required to delete projects.
-
projects.getProjectGet the latest summary for a specific project using the numeric project identifier.
To find the LGTM identifier for a project, list all projects using the
/projectsendpoint and look up the project by name. Alternatively, use the/projects/{provider}/{org}/{name}endpoint. If you have administration access, the project identifier is also displayed in the administration page for the project. -
projects.getProjectByUrlIdentifierGet the latest summary for a specific project using the project's URL identifier
{provider}/{org}/{name}.To find the URL identifier for a project, view the project overview page in LGTM. The URL identifier follows after
/projects. For example, for a project with the URLhttps://lgtm.example.com/projects/g/apache/commons-iothe URL identifier isg/apache/commons-io. In the example,grepresents theprovider(repository host),apacheis theorganizationandcommons-iois thenameof the repository. -
projects.getProjectConfigGet the latest configuration for a specific project using the numeric project identifier.
-
projects.getProjectsList all the projects the current user has authorization to view.
A maximum of 100 projects are returned in each response. When further results are available, the response includes the URL you need to request the next page of results.
Use the optional parameter,
limit, to change the number of results reported in each response (range of 1—100). If you supply an invalid value for this parameter, the default value of 100 is used.When more than one page of results is available, each response includes a
nextPageUrlresponse parameter. You can use this URL to request the next page of results. ThenextPageUrlincludes an automatically generatedstartparameter, which specifies the projects to return in the next page of results. -
projects.setProjectConfigSet the administrator configuration for a specific project using the numeric project identifier.
-
queryJobs.createQueryJobSubmit a query to run on one or more projects on LGTM. The query is included in the body of the request.
-
queryJobs.getQueryJobGet the status of a query job using the query job identifier for the task.
When you create a query job, the response includes a task result URL of the form:
/queryjobs/{queryjob-id}. -
queryJobs.getQueryJobResultsForProjectFetch the results for a specific project. The endpoint succeeds only if the query was successful, and returns a
404error otherwise. By default, the endpoint provides only results that are within the source tree. To obtain all results, specify thenofilterparameter. -
queryJobs.getQueryJobResultsOverviewThis endpoint provides a summary of the results generated by completed query runs for each project specified in the the POST /queryjobs endpoint. For completed query jobs, the summary includes:
- The number of results for successful query runs.
- Error information for failed query runs.
No information is included in the response for any project for which the query run is still in progress.
-
snapshots.abortUploadAborts the specified upload session and deletes any uploaded parts. After the session is aborted it cannot be restarted. If any part uploads are in progress when the session is aborted, their data may not be deleted. To ensure that uploaded parts are deleted correctly, you should only abort an upload session after all part uploads have completed.
-
snapshots.completeUploadCompletes the database upload by closing the upload session, upgrading the database if appropriate, and scheduling analysis of that snapshot of the codebase.
You can view the analysis progress and access the results using the
task-result-url. -
snapshots.getSnapshotDownload a CodeQL database from LGTM, representing a snapshot of the codebase, to run queries in your IDE.
This endpoint works for projects that have been successfully analyzed for the language specified in the request. A successful request redirects you to a URL for downloading a database that represents the code snapshot, as specified in the
Location:header in the response. Therefore, your HTTP client should be configured to follow redirects. For example, if you are usingcurl, you can add the-Lflag to the command.The database is downloaded as a zip file that can be imported into an IDE equipped with a CodeQL extension. The extension must be up to date to analyze databases downloaded from LGTM. For more information on running queries locally in your IDE, see .
-
snapshots.initSnapshotUploadStart a session to upload an externally-built database (which represents a snapshot of a codebase) to a project on LGTM.
This endpoint works for projects that are already on LGTM, and the selected language of the database must already be configured. The project must be configured with 'upload' analysis mode. You can upload a "bundled" CodeQL database or a database exported by the QL command-line tools (
odasa).If your database was generated using a version of the command line that is older than LGTM, LGTM will try to upgrade and analyze it when the upload is complete. You can include cached predicates in the upload, but they are ignored as the cache is repopulated after the database has been upgraded and analyzed. However, if you want to include results with your database, make sure the database is compatible before you start the upload session. Incompatible databases with results won't be upgraded and therefore cannot be uploaded. For further information on externally-built databases, see .
When the upload session has been successfully started, upload the database to the upload URL returned in the response. The database can be uploaded to the upload URL in parts using the endpoint. After uploading all the parts you must call the endpoint to complete the upload session.
-
snapshots.uploadPartUpload a database representing a snapshot of a codebase. The database is sent in one or more parts. Each part is sent in the request body. Use the endpoint to start an upload session before uploading a database part. Database parts must have been generated and prepared for upload using the CodeQL CLI or the QL command-line tools. For further information on exporting externally-built databases, see .
Split large databases into multiple parts. Upload the parts by making a separate request for each part. Don't upload the next part until you've successfully uploaded the previous part.
If the upload fails you should retry it with the same data.
-
system.getHealthReturn an indication of whether the application is working as expected (up) or needs attention (down). > The
descriptionanddetailsfields are reported only if the request includes an access token for a user account that has administration rights for this LGTM server. -
system.getMetricLGTM administrators can download usage data using this endpoint. The response includes up to 1000 values for the specified metric and reports the date-time that each value was calculated. There is normally one value per day.
-
system.getMetricsLGTM administrators can use this endpoint to list the usage metrics that are available to download.
-
openapi.previewSpecPreview an OpenAPI document before adding it as a source
-
openapi.addSourceAdd an OpenAPI source and register its operations as tools