API

If you’re looking to jump right in to the ActiveState API go to our reference resource_

Using GraphQL queries, ActiveState Platform users can define and compose steps for building complex open source software for different operating systems and languages without worrying about sourcing, maintaining, and updating their own infrastructure. This is done through the GraphQL console.

The following will guide you through using the ActiveState API

Authentication

Interacting with the API

Example query


Authentication Process

Both methods will require the State Tool CLI to be installed and your account to be authenticated with the state auth command.

If you have not authenticated using state auth your browser will open prompting you to Authorize your State Tool. If the prompt does not appear, paste the link in the state auth output into your browser and click Authorize.

After authenticating with the StateTool CLI, authentication with the GraphQL console is done using either

  • JSON Web Tokens (JWTs), or
  • API keys that allow you to interact with the API.

While JWTs are temporarily issued and will expire, your API key will not, be sure to protect the security of your account by never sharing or publicly displaying your API key.

To generate a JWT open your command terminal and run the following command

state export jwt 

To generate an API key enter

state export new-api-key <orgname/projectname>

In the “Header” area of your GraphQL console, enter either of the above tokens (JWT or API key) as shown below

{
  "Authorization": "Bearer <APIkey or JWT token generated above>"
}

You are now ready to start interacting with GraphQL directly.


Interacting with the API

Begin by creating a query using the Graphql console to see what information is available. Results are returned as JSON data that matches your query.

Go to https://platform.activestate.com/sv/buildplanner/graphql. Queries are crafted on the left, with the result displayed on the right after clicking the triangular “play” button between the two panels.

In the API reference page see the item labeled Queries > project in the vertical site index.

We will create an example project query by copying the contents of the “QUERY” and pasting it into the query field of the GraphQL console as shown below. Note the arguments listed on the reference page (“organization” and “project”) and enter them in the Variables section as shown below using the information from your organization and project.

alt_text

The json format for the variables is shown below

{
  "organization": "<orgname>",
  "project": "<projectname>"
}

Example query

Query to return a project build expression

query commit {
  commit(commitId: "49a44671-6434-4821-8131-ec6ea7acd029") {
    ... on Commit {
      expr
    }
    ... on NotFound {
      message
      type
    }
  }
}

Open in GraphQL

Response

{
  "data": {
    "commit": {
      "expr": {
        "let": {
          "sources": {
            "solve": {
              "at_time": "2023-11-06T19:15:03.030000Z",
              "platforms": [
                "46a5b48f-226a-4696-9746-ba4d50d661c2",
                "78977bc8-0f32-519d-80f3-9043f059398c",
                "7c998ec2-7491-4e75-be4d-8885800ef5f2"
              ],
              "requirements": [
                {
                  "name": "python",
                  "namespace": "language",
                  "version_requirements": [
                    {
                      "comparator": "eq",
                      "version": "3.10.13"
                    }
                  ]
                },
                {
                  "name": "appdirs",
                  "namespace": "language/python"
                },
                {
                  "name": "flask",
                  "namespace": "language/python"
                },
                {
                  "name": "scipy",
                  "namespace": "language/python"
                }
              ],
              "solver_version": null
            }
          },
          "runtime": {
            "state_tool_artifacts_v1": {
              "src": "$sources",
              "build_flags": []
            }
          },
          "in": "$runtime"
        }
      }
    }
  }
}