Skip to content

Latest commit

 

History

History
947 lines (633 loc) · 24.6 KB

v3.rst

File metadata and controls

947 lines (633 loc) · 24.6 KB

API v3

The Read the Docs API uses :abbr:`REST (Representational State Transfer)`. JSON is returned by all API responses including errors and HTTP response status codes are to designate success and failure.

Authentication and authorization

Requests to the Read the Docs public API are for public and private information. All endpoints require authentication.

Token

The Authorization HTTP header can be specified with Token <your-access-token> to authenticate as a user and have the same permissions that the user itself.

Note

You will find your access Token under your profile settings.

Session

Warning

Authentication via session is not enabled yet.

Session authentication is allowed on very specific endpoints, to allow hitting the API when reading documentation.

When a user is trying to authenticate via session, :abbr:`CSRF (Cross-site request forgery)` check is performed.

Resources

This section shows all the resources that are currently available in APIv3. There are some URL attributes that applies to all of these resources:

?fields=:Specify which fields are going to be returned in the response.
?omit=:Specify which fields are going to be omitted from the response.
?expand=:Some resources allow to expand/add extra fields on their responses (see Project details for example).

Tip

You can browse the full API by accessing its root URL: https://readthedocs.org/api/v3/

Projects

Projects list

.. http:get:: /api/v3/projects/

    Retrieve a list of all the projects for the current logged in user.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/

    **Example response**:

    .. sourcecode:: json

        {
            "count": 25,
            "next": "/api/v3/projects/?limit=10&offset=10",
            "previous": null,
            "results": ["PROJECT"]
        }

    :query string language: language code as ``en``, ``es``, ``ru``, etc.
    :query string programming_language: programming language code as ``py``, ``js``, etc.


Project details

.. http:get:: /api/v3/projects/(string:project_slug)/

    Retrieve details of a single project.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/

    **Example response**:

    .. sourcecode:: json

        {
            "id": 12345,
            "name": "Pip",
            "slug": "pip",
            "created": "2010-10-23T18:12:31+00:00",
            "modified": "2018-12-11T07:21:11+00:00",
            "language": {
                "code": "en",
                "name": "English"
            },
            "programming_language": {
                "code": "py",
                "name": "Python"
            },
            "repository": {
                "url": "https://github.com/pypa/pip",
                "type": "git"
            },
            "default_version": "stable",
            "default_branch": "master",
            "subproject_of": null,
            "translation_of": null,
            "urls": {
                "documentation": "http://pip.pypa.io/en/stable/",
                "home": "https://pip.pypa.io/"
            },
            "tags": [
                "disutils",
                "easy_install",
                "egg",
                "setuptools",
                "virtualenv"
            ],
            "users": [
                {
                    "username": "dstufft"
                }
            ],
            "active_versions": {
                "stable": "{VERSION}",
                "latest": "{VERSION}",
                "19.0.2": "{VERSION}"
            },
            "_links": {
                "_self": "/api/v3/projects/pip/",
                "versions": "/api/v3/projects/pip/versions/",
                "builds": "/api/v3/projects/pip/builds/",
                "subprojects": "/api/v3/projects/pip/subprojects/",
                "superproject": "/api/v3/projects/pip/superproject/",
                "redirects": "/api/v3/projects/pip/redirects/",
                "translations": "/api/v3/projects/pip/translations/"
            }
        }

    :query string expand: allows to add/expand some extra fields in the response.
                          Allowed values are ``active_versions``, ``active_versions.last_build`` and
                          ``active_versions.last_build.config``. Multiple fields can be passed separated by commas.


Project create

.. http:post:: /api/v3/projects/

    Import a project under authenticated user.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X POST \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "name": "Test Project",
            "repository": {
                "url": "https://github.com/readthedocs/template",
                "type": "git"
            },
            "homepage": "http://template.readthedocs.io/",
            "programming_language": "py",
            "language": "es"
        }

    **Example response**:

    `See Project details <#project-details>`__

Project update

.. http:patch:: /api/v3/projects/(string:project_slug)/

    Update an existing project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X PATCH \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "name": "New name for the project",
            "repository": {
                "url": "https://github.com/readthedocs/readthedocs.org",
                "type": "git"
            },
            "language": "ja",
            "programming_language": "py",
            "homepage": "https://readthedocs.org/",
            "default_version": "v0.27.0",
            "default_branch": "develop",
            "analytics_code": "UA000000",
            "single_version": false,

        }

    :statuscode 204: Updated successfully


Versions

Versions are different versions of the same project documentation.

The versions for a given project can be viewed in a project's version page. For example, here is the Pip project's version page. See :doc:`/versions` for more information.

Versions listing

.. http:get:: /api/v3/projects/(string:project_slug)/versions/

    Retrieve a list of all versions for a project.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/versions/

    **Example response**:

    .. sourcecode:: json

        {
            "count": 25,
            "next": "/api/v3/projects/pip/versions/?limit=10&offset=10",
            "previous": null,
            "results": ["VERSION"]
        }

    :query boolean active: return only active versions
    :query boolean built: return only built versions


Version detail

.. http:get:: /api/v3/projects/(string:project_slug)/versions/(string:version_slug)/

    Retrieve details of a single version.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/versions/stable/

    **Example response**:

    .. sourcecode:: json

        {
            "id": 71652437,
            "slug": "stable",
            "verbose_name": "stable",
            "identifier": "3a6b3995c141c0888af6591a59240ba5db7d9914",
            "ref": "19.0.2",
            "built": true,
            "active": true,
            "type": "tag",
            "last_build": "{BUILD}",
            "downloads": {
                "pdf": "https://readthedocs.org/projects/pip/downloads/pdf/stable/",
                "htmlzip": "https://readthedocs.org/projects/pip/downloads/htmlzip/stable/",
                "epub": "https://readthedocs.org/projects/pip/downloads/epub/stable/"
            },
            "urls": {
                "documentation": "https://pip.pypa.io/en/stable/",
                "vcs": "https://github.com/pypa/pip/tree/19.0.2"
            },
            "_links": {
                "_self": "/api/v3/projects/pip/versions/stable/",
                "builds": "/api/v3/projects/pip/versions/stable/builds/",
                "project": "/api/v3/projects/pip/"
            }
        }

    :>json string ref: the version slug where the ``stable`` version points to.
                       ``null`` when it's not the stable version.
    :>json boolean built: the version has at least one successful build.

    :query string expand: allows to add/expand some extra fields in the response.
                          Allowed values are ``last_build`` and ``last_build.config``.
                          Multiple fields can be passed separated by commas.


Version update

.. http:patch:: /api/v3/projects/(string:project_slug)/version/(string:version_slug)/

    Update a version.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X PATCH \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/version/0.23/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "active": true,
        }

    :statuscode 204: Updated successfully


Builds

Builds are created by Read the Docs whenever a Project has its documentation built. Frequently this happens automatically via a web hook but can be triggered manually.

Builds can be viewed in the build page for a project. For example, here is Pip's build page. See :doc:`/builds` for more information.

Build details

.. http:get:: /api/v3/projects/(str:project_slug)/builds/(int:build_id)/

    Retrieve details of a single build for a project.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/builds/8592686/?expand=config

    **Example response**:

    .. sourcecode:: json

        {
            "id": 8592686,
            "version": "latest",
            "project": "pip",
            "created": "2018-06-19T15:15:59+00:00",
            "finished": "2018-06-19T15:16:58+00:00",
            "duration": 59,
            "state": {
                "code": "finished",
                "name": "Finished"
            },
            "success": true,
            "error": null,
            "commit": "6f808d743fd6f6907ad3e2e969c88a549e76db30",
            "config": {
                "version": "1",
                "formats": [
                    "htmlzip",
                    "epub",
                    "pdf"
                ],
                "python": {
                    "version": 3,
                    "install": [
                        {
                            "requirements": ".../stable/tools/docs-requirements.txt"
                        }
                    ],
                    "use_system_site_packages": false
                },
                "conda": null,
                "build": {
                    "image": "readthedocs/build:latest"
                },
                "doctype": "sphinx_htmldir",
                "sphinx": {
                    "builder": "sphinx_htmldir",
                    "configuration": ".../stable/docs/html/conf.py",
                    "fail_on_warning": false
                },
                "mkdocs": {
                    "configuration": null,
                    "fail_on_warning": false
                },
                "submodules": {
                    "include": "all",
                    "exclude": [],
                    "recursive": true
                }
            },
            "_links": {
                "_self": "/api/v3/projects/pip/builds/8592686/",
                "project": "/api/v3/projects/pip/",
                "version": "/api/v3/projects/pip/versions/latest/"
            }
        }

    :>json string created: The ISO-8601 datetime when the build was created.
    :>json string finished: The ISO-8601 datetime when the build has finished.
    :>json integer duration: The length of the build in seconds.
    :>json string state: The state of the build (one of ``triggered``, ``building``, ``installing``, ``cloning``, or ``finished``)
    :>json string error: An error message if the build was unsuccessful

    :query string expand: allows to add/expand some extra fields in the response.
                          Allowed value is ``config``.


Builds listing

.. http:get:: /api/v3/projects/(str:project_slug)/builds/

    Retrieve list of all the builds on this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/builds/

    **Example response**:

    .. sourcecode:: json

        {
            "count": 15,
            "next": "/api/v3/projects/pip/builds?limit=10&offset=10",
            "previous": null,
            "results": ["BUILD"]
        }

    :query string commit: commit hash to filter the builds returned by commit
    :query boolean running: filter the builds that are currently building/running


Build triggering

.. http:post:: /api/v3/projects/(string:project_slug)/versions/(string:version_slug)/builds/

    Trigger a new build for the ``version_slug`` version of this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X POST \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/versions/latest/builds/

    **Example response**:

    .. sourcecode:: json

        {
            "build": "{BUILD}",
            "project": "{PROJECT}",
            "version": "{VERSION}"
        }

    :statuscode 202: the build was triggered


Subprojects

Projects can be configured in a nested manner, by configuring a project as a subproject of another project. This allows for documentation projects to share a search index and a namespace or custom domain, but still be maintained independently. See :doc:`/subprojects` for more information.

Subproject details

.. http:get:: /api/v3/projects/(str:project_slug)/subprojects/(str:alias_slug)/

    Retrieve details of a subproject relationship.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/

    **Example response**:

    .. sourcecode:: json

        {
            "alias": "subproject-alias",
            "child": ["PROJECT"],
            "_links": {
                "parent": "/api/v3/projects/pip/"
            }
        }


Subprojects listing

.. http:get:: /api/v3/projects/(str:project_slug)/subprojects/

    Retrieve a list of all sub-projects for a project.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/subprojects/

    **Example response**:

    .. sourcecode:: json

        {
            "count": 25,
            "next": "/api/v3/projects/pip/subprojects/?limit=10&offset=10",
            "previous": null,
            "results": ["SUBPROJECT RELATIONSHIP"]
        }


Subproject create

.. http:post:: /api/v3/projects/(str:project_slug)/subprojects/

    Create a subproject relationship between two projects.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X POST \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/subprojects/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "child": "subproject-child-slug",
            "alias": "subproject-alias"
        }

    **Example response**:

    `See Subproject details <#subproject-details>`_

    :>json string child: slug of the child project in the relationship.
    :>json string alias: optional slug alias to be used in the URL (e.g ``/projects/<alias>/en/latest/``).
                         If not provided, child project's slug is used as alias.

    :statuscode 201: Subproject created sucessfully


Subproject delete

.. http:delete:: /api/v3/projects/(str:project_slug)/subprojects/(str:alias_slug)/

    Delete a subproject relationship.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X DELETE \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/

    :statuscode 204: Subproject deleted successfully


Translations

Translations are the same version of a Project in a different language. See :doc:`/localization` for more information.

Translations listing

.. http:get:: /api/v3/projects/(str:project_slug)/translations/

    Retrieve a list of all translations for a project.

    **Example request**:

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/translations/

    **Example response**:

    .. sourcecode:: json

        {
            "count": 25,
            "next": "/api/v3/projects/pip/translations/?limit=10&offset=10",
            "previous": null,
            "results": ["PROJECT"]
        }


Redirects

Redirects allow the author to redirect an old URL of the documentation to a new one. This is useful when pages are moved around in the structure of the documentation set. See :doc:`/user-defined-redirects` for more information.

Redirect details

.. http:get:: /api/v3/projects/(str:project_slug)/redirects/(int:redirect_id)/

    Retrieve details of a single redirect for a project.

    **Example request**

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/redirects/1/

    **Example response**

    .. sourcecode:: json

       {
           "pk": 1,
           "created": "2019-04-29T10:00:00Z",
           "modified": "2019-04-29T12:00:00Z",
           "project": "pip",
           "from_url": "/docs/",
           "to_url": "/documentation/",
           "type": "page",
           "_links": {
               "_self": "/api/v3/projects/pip/redirects/1/",
               "project": "/api/v3/projects/pip/"
           }
       }

Redirects listing

.. http:get:: /api/v3/projects/(str:project_slug)/redirects/

    Retrieve list of all the redirects for this project.

    **Example request**

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/redirects/

    **Example response**

    .. sourcecode:: json

        {
            "count": 25,
            "next": "/api/v3/projects/pip/redirects/?limit=10&offset=10",
            "previous": null,
            "results": ["REDIRECT"]
        }

Redirect create

.. http:post:: /api/v3/projects/pip/redirects/

    Create a redirect for this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X POST \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/redirects/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "from_url": "/docs/",
            "to_url": "/documentation/",
            "type": "page"
        }

    .. note::

       ``type`` can be one of ``prefix``, ``page``, ``exact``, ``sphinx_html`` and ``sphinx_htmldir``.

       Depending on the ``type`` of the redirect, some fields may not be needed:

       * ``prefix`` type does not require ``to_url``.
       * ``page`` and ``exact`` types require ``from_url`` and ``to_url``.
       * ``sphinx_html`` and ``sphinx_htmldir`` types do not require ``from_url`` and ``to_url``.

    **Example response**:

    `See Redirect details <#redirect-details>`_

    :statuscode 201: redirect created successfully


Redirect update

.. http:put:: /api/v3/projects/(str:project_slug)/redirects/(int:redirect_id)/

    Update a redirect for this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X PUT \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/redirects/1/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "from_url": "/docs/",
            "to_url": "/documentation.html",
            "type": "page"
        }

    **Example response**:

    `See Redirect details <#redirect-details>`_

Redirect delete

.. http:delete:: /api/v3/projects/(str:project_slug)/redirects/(int:redirect_id)/

    Delete a redirect for this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X DELETE \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/redirects/1/

    :statuscode 204: Redirect deleted successfully


Environment Variables

Environment Variables are variables that you can define for your project. These variables are used in the build process when building your documentation. They are useful to define secrets in a safe way that can be used by your documentation to build properly. See :doc:`/guides/environment-variables`

Environment Variable details

.. http:get:: /api/v3/projects/(str:project_slug)/environmentvariables/(int:environmentvariable_id)/

    Retrieve details of a single environment variable for a project.

    **Example request**

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/

    **Example response**

    .. sourcecode:: json

       {
           "_links": {
               "_self": "https://readthedocs.org/api/v3/projects/project/environmentvariables/1/",
               "project": "https://readthedocs.org/api/v3/projects/project/"
           },
       "created": "2019-04-29T10:00:00Z",
       "modified": "2019-04-29T12:00:00Z",
       "pk": 1,
       "project": "project",
       "name": "ENVVAR"
       }

Environment Variables listing

.. http:get:: /api/v3/projects/(str:project_slug)/environmentvariables/

    Retrieve list of all the environment variables for this project.

    **Example request**

    .. sourcecode:: bash

        $ curl -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/environmentvariables/

    **Example response**

    .. sourcecode:: json

        {
            "count": 15,
            "next": "/api/v3/projects/pip/environmentvariables/?limit=10&offset=10",
            "previous": null,
            "results": ["ENVIRONMENTVARIABLE"]
        }

Environment Variable create

.. http:post:: /api/v3/projects/pip/environmentvariables/

    Create an environment variable for this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X POST \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/environmentvariables/ \
          -H "Content-Type: application/json" \
          -d @body.json

    The content of ``body.json`` is like,

    .. sourcecode:: json

        {
            "name": "MYVAR",
            "value": "My secret value"
        }

    **Example response**:

    `See Environment Variable details <#environmentvariable-details>`_

    :statuscode 201: Environment variable created successfully


Environment Variable delete

.. http:delete:: /api/v3/projects/(str:project_slug)/environmentvariables/(int:environmentvariable_id)/

    Delete an environment variable for this project.

    **Example request**:

    .. sourcecode:: bash

        $ curl \
          -X DELETE \
          -H "Authorization: Token <token>" https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/

    :requestheader Authorization: token to authenticate.

    :statuscode 204: Environment variable deleted successfully