Skip to content

Commit

Permalink
Adding trigger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
htahir1 committed Jun 26, 2024
1 parent 471d1a3 commit e1b1380
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ The above set of REST calls means that you can only trigger a pipeline that has

## A worked example

{% hint style="info" %}
Learn how to get a bearer token for the curl commands [here](../../reference/api-reference.md#using-a-bearer-token-to-access-the-api-programatically).
{% endhint %}

Here is an example. Let's say would we like to re-run a pipeline called `training`. We first query the `/pipelines` endpoint:

```shell
curl -X 'GET' \
'<YOUR_ZENML_SERVER_URL>/api/v1/pipelines?hydrate=false&name=training&version=45' \
-H 'accept: application/json'
-H 'accept: application/json' \
-H 'Authorization: Bearer <YOUR_TOKEN>'
```

<figure><img src="../../.gitbook/assets/rest_api_step_1.png" alt=""><figcaption><p>Identifying the pipeline ID</p></figcaption></figure>
Expand All @@ -41,7 +46,8 @@ After this, we take the pipeline ID and call the `/pipeline_builds?pipeline_id=<
```shell
curl -X 'GET' \
'<YOUR_ZENML_SERVER_URL>/api/v1/pipeline_builds?hydrate=false&logical_operator=and&page=1&size=20&pipeline_id=b826b714-a9b3-461c-9a6e-1bde3df3241d' \
-H 'accept: application/json'
-H 'accept: application/json' \
-H 'Authorization: Bearer <YOUR_TOKEN>'
```

We can now take the <BUILD_ID> from this response. Here it is `b826b714-a9b3-461c-9a6e-1bde3df3241d`.
Expand All @@ -55,6 +61,7 @@ curl -X 'POST' \
'<YOUR_ZENML_SERVER_URL>/api/v1/pipeline_builds/b826b714-a9b3-461c-9a6e-1bde3df3241d/runs' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <YOUR_TOKEN>' \
-d '{
"steps": {"model_trainer": {"parameters": {"model_type": "rf"}}}
}'
Expand Down
46 changes: 46 additions & 0 deletions docs/book/reference/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,50 @@ In the local case (i.e. using `zenml up`, the docs are available on `http://127.

![ZenML API Redoc](../.gitbook/assets/zenml_api_redoc.png)

## Using a bearer token to access the API programatically

If you are using the ZenML server API using the above pages, it is enough to be logged in to your ZenML
account in the same browser session. However, in order to do this programatically, the following steps
need to be followed:

1. Create a [service account](../how-to/connecting-to-zenml/connect-with-a-service-account.md):

```shell
zenml service-account create myserviceaccount
```

This will print out the `<ZENML_API_KEY>`, you can use in the next command.

2. Get an access token by using the `/api/v1/login` endpoint:

```shell

curl -X 'POST' \
'<YOUR_ZENML_SERVER_URL>/api/v1/login' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=zenml-api-key&username=&password=<ZENML_API_KEY>'\''&client_id=&device_code='
```

This will return a response like this:

```json
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI3MGJjZTg5NC1hN2VjLTRkOTYtYjE1Ny1kOTZkYWY5ZWM2M2IiLCJpc3MiOiJmMGQ5NjI1Ni04YmQyLTQxZDctOWVjZi0xMmYwM2JmYTVlMTYiLCJhdWQiOiJmMGQ5NjI1Ni04YmQyLTQxZDctOWVjZi0xMmYwM2JmYTVlMTYiLCJleHAiOjE3MTk0MDk0NjAsImFwaV9rZXlfaWQiOiIzNDkyM2U0NS0zMGFlLTRkMjctODZiZS0wZGRhNTdkMjA5MDcifQ.ByB1ngCPtBenGE6UugsWC6Blga3qPqkAiPJUSFDR-u4",
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": null,
"scope": null
}
```

3. Use the access token to make subsequent curl commands:

```shell
curl -X 'GET' \
'<YOUR_ZENML_SERVER_URL>/api/v1/pipelines?hydrate=false&name=training&version=45' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <ACCESS_TOKEN>'
```

<figure><img src="https://static.scarf.sh/a.png?x-pxid=f0b4f458-0a54-4fcd-aa95-d5ee424815bc" alt="ZenML Scarf"><figcaption></figcaption></figure>

0 comments on commit e1b1380

Please sign in to comment.