Back

Travis CI API Essential Guide

Aug 7, 20246 minute read

What type of API does Travis CI provide?

Based on the search results, Travis CI primarily uses a REST API. Here are the key points about Travis CI's API:

API Types

  • Travis CI uses a REST API

API Versions

  • API V3 is the most recent and recommended version
  • There are older versions like API V2.1 and API V2, but these are deprecated or being phased out

Key Features

  • The API V3 includes hypermedia features expected from a modern API
  • It allows automation of many Travis CI build processes like getting build info, restarting builds, canceling builds, etc.
  • Travis CI provides an API Explorer for V3 that updates automatically when new endpoints are added

Authentication

  • Authentication is done using API access tokens
  • Tokens can be obtained using GitHub authentication or from the Travis CI profile page

Making Requests

  • Requests to the API should include specific headers like User-Agent and Accept
  • The base URL for the API depends on whether you're using travis-ci.org, travis-ci.com, or Travis CI Enterprise

API Clients

  • There are official and third-party API clients available for various programming languages

Does the Travis CI API have webhooks?

Webhook Support

Yes, the official Travis CI API does support webhooks. Travis CI can send webhook notifications about build results.

Configuring Webhooks

Webhooks can be configured in the .travis.yml file of a repository. For example:

notifications: webhooks: http://your-domain.com/notifications

Multiple webhook URLs can be specified:

notifications: webhooks: - http://your-domain.com/notifications - http://another-domain.com/notifications

Webhook Events

You can subscribe to the following events for webhook notifications:

  • on_success: Sent when a build succeeds (default: always)
  • on_failure: Sent when a build fails (default: always)
  • on_start: Sent when a build starts (default: never)
  • on_cancel: Sent when a build is canceled (default: always)
  • on_error: Sent when a build errors (default: always)

Webhook Payload

The webhook payload is sent as JSON and includes information about the build status, repository, commit, etc. Some key fields include:

  • status/result: Indicates build status (0 for success, 1 for failure/incomplete)
  • type: Indicates the event type (push, pull_request, cron, api)
  • Repository information
  • Commit details

Verifying Webhooks

Travis CI provides a way to verify webhook requests using a signature header and public key for security.

API Triggered Builds

In addition to webhooks, Travis CI also allows triggering builds via its API. This can be done by sending a POST request to the /repo/{slug|id}/requests endpoint.

Rate Limits and other limitations

Based on the search results, there is no explicit information provided about the specific API rate limits for the Travis CI API. However, there are a few relevant points to consider regarding API rate limits:

GitHub API Rate Limits

  1. For unauthenticated requests to the GitHub API, the rate limit allows for up to 60 requests per hour ^2.

  2. For authenticated requests using Basic Authentication or OAuth to the GitHub API, you can make up to 5000 requests per hour ^2.

Travis CI API Usage

  1. Travis CI uses the GitHub API for various operations, and they have been experiencing issues with hitting GitHub's API rate limits ^5.

  2. In March 2020, Travis CI contacted GitHub to request increases to their API rate limits ^5.

  3. Travis CI has been working on improving how their code accesses the GitHub API to reduce unnecessary calls and stay under the limits ^5.

Best Practices

  1. For Travis CI users, it's recommended to use authenticated requests when possible to benefit from higher rate limits ^2.

  2. If you encounter rate limit issues, Travis CI support suggests retrying the action you were attempting to perform ^5.

  3. For open-source projects using Travis CI, migrating to the Travis CI GitHub Apps integration might help with API limit issues, although this wasn't explicitly mentioned in the support response ^5.

Key Takeaway

While the specific API rate limits for Travis CI's own API are not provided in the search results, it's clear that Travis CI's operations are significantly impacted by GitHub's API rate limits. Travis CI has been working with GitHub to increase these limits and improve their own API usage to minimize the impact on users.

For the most up-to-date and accurate information on Travis CI's API rate limits, it would be best to consult their official documentation or contact their support directly.

Latest API Version

The most recent version of the Travis CI API is V3. Here are the key points:

  1. API V3 is the current and most recent version of the Travis CI API [1].

  2. API V3 was released on April 6, 2017 [2].

  3. It is described as a "discoverable and self-documenting RESTful API" that includes "all the hypermedia features expected from a modern API" [2].

  4. API V3 can be used to automate many Travis CI build processes, including getting build info, restarting builds, canceling builds, triggering debug builds, and more [2].

  5. There is an API Explorer available for V3 that updates automatically when new endpoints are added [2].

  6. To use API V3, you should set the Accept header to application/vnd.travis-ci.3+json in your API requests [1].

  7. The previous versions, API V2 and V2.1, are considered deprecated. API V2 was slated for deprecation sometime in 2018 [1].

  8. Documentation for API V3 can be found at https://developer.travis-ci.org.

In summary, API V3 is the current and recommended version of the Travis CI API, offering modern RESTful capabilities and extensive functionality for automating Travis CI processes. When working with the Travis CI API, developers should use V3 and refer to the official documentation and API Explorer for the most up-to-date information on available endpoints and features.

How to get a Travis CI developer account and API Keys?

To get a developer account for Travis CI and create an API integration, you can follow these steps:

1. Sign up for Travis CI

  • Go to travis-ci.com and sign up using your GitHub account.
  • Authorize Travis CI to access your GitHub repositories.

2. Get an API token

  • Install the Travis CI command line client if you haven't already:
    gem install travis
    
  • Log in to Travis CI via the CLI:
    travis login --pro
    
  • Generate an API token:
    travis token
    
  • This will display your Travis CI API token.

3. Use the API token for authentication

  • Include the token in the Authorization header when making API requests:
curl -H "Travis-API-Version: 3" \
     -H "Authorization: token YOUR_API_TOKEN" \
     https://api.travis-ci.com/repos

4. Create an API integration

  • To integrate Travis CI with other services, you can use the API token to authenticate requests.
  • For example, to integrate with Postman:
    1. Open your API in Postman
    2. Go to the Integrations section
    3. Select Travis CI
    4. Enter a nickname for the integration
    5. Provide your Travis CI API token

What can you do with the Travis CI API?

Based on the search results provided, here is a list of data models that can be interacted with using the Travis CI API, along with what is possible for each:

Repositories

  • Retrieve repository information
  • Enable/disable repositories for Travis CI builds
  • Get build status and history for repositories

Builds

  • Retrieve build information
  • Restart builds
  • Cancel builds
  • Trigger new builds
  • Get build logs

Jobs

  • Retrieve job information
  • Restart jobs
  • Cancel jobs

Branches

  • Get branch build information

Requests

  • View build requests

Users

  • Get user profile information

Organizations

  • Retrieve organization information

Environment Variables

  • Add/edit/delete environment variables for repositories

Caches

  • View and delete repository caches

Cron Jobs

  • Create/edit/delete cron jobs for repositories

Hooks

  • Enable/disable service hooks for repositories

Settings

  • View and modify repository settings

Logs

  • Retrieve and view build logs

Config

  • Get Travis CI configuration details

Pagination

  • Handle paginated responses for large result sets

Key capabilities across these models include:

  • Retrieving information (GET requests)
  • Modifying settings and configurations (PUT/PATCH requests)
  • Triggering actions like builds (POST requests)
  • Deleting resources (DELETE requests)

The API allows programmatic access to most Travis CI functionality available in the web interface, enabling automation of CI/CD workflows and integration with other tools and services.