---
name: azion-read-a-function-and-its-function-instances-with-the-api
description: >-
  Read the code, runtime, and default Args of a Function by its ID with the Azion API v4, and list the Function Instances of an Application.
---

# Read a Function and its Function Instances with the API

You can read a [Function](/en/documentation/platform/functions/) and its [Function Instances](/en/documentation/platform/applications/functions-instances/) in an [Application](/en/documentation/platform/applications/) with the [Azion API](/en/documentation/devtools/api/) v4.

---

## Prerequisites

- A personal token. To create one, refer to [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens/).
- `curl`, to call the API, and `jq`, to format the JSON responses.
- The ID of a Function, and the ID of an Application with a Function Instance of that Function. To create the three, refer to [Deploy a Function with the Azion API](/en/documentation/guides/application-development/automation/deploy-a-function-with-the-azion-api/).

---

## Read a Function by its ID

A `GET` request with the ID of a Function returns its code, its runtime, and its default Args in `data`.

To read the Function, send a `GET` request with its ID. Replace the two values with your own:

```bash
export AZION_API_TOKEN="[TOKEN VALUE]"
FUNCTION_ID=<your-function-id>
curl --silent "https://api.azion.com/v4/workspace/functions/$FUNCTION_ID" \
  --header "Authorization: Token $AZION_API_TOKEN" \
| jq
```

This excerpt of the response keeps the fields that this section describes:

```json
{
  "data": {
    "id": 111853,
    ...
    "active": true,
    "runtime": "azion_js",
    "execution_environment": "application",
    "default_args": {
      "greeting": "hello"
    },
    ...
    "reference_count": 2,
    ...
    "code": "export default {\n  async fetch(request, env, ctx) {\n    return Response.json({ greeting: ctx.args.greeting ?? 'none' })\n  }\n}",
    ...
  }
}
```

- `code` holds the source code of the Function as one JSON string.
- `runtime` is the runtime that executes the code: `azion_js`.
- `execution_environment` is `application` for a Function that runs in an Application, or `firewall` for one that runs in a [Firewall](/en/documentation/platform/firewall/).
- `default_args` holds the default [Args](/en/documentation/platform/applications/functions-instances/#args) of the Function. Args are the JSON arguments that a Function Instance passes into the execution of the Function. The API copies the default Args into a Function Instance created without `args`.
- `reference_count` counts the Function Instances that bind the Function, in all your Applications.

Environment variables are stored on the account, outside the Function, so they are not part of this response. To read them from the code, refer to [Environment variables](/en/documentation/platform/functions/environment-variables/).

To print only the code, as source text instead of a JSON string, replace `jq` with `jq -r .data.code`:

```bash
export AZION_API_TOKEN="[TOKEN VALUE]"
FUNCTION_ID=<your-function-id>
curl --silent "https://api.azion.com/v4/workspace/functions/$FUNCTION_ID" \
  --header "Authorization: Token $AZION_API_TOKEN" \
| jq -r .data.code
```

```javascript
export default {
  async fetch(request, env, ctx) {
    return Response.json({ greeting: ctx.args.greeting ?? 'none' })
  }
}
```

You have the runtime, the default Args, and the source code of the Function.

---

## List the Function Instances of an Application

A Function Instance is the entity that binds a Function to an Application or a Firewall. The API lists the Function Instances of an Application under the path of the Application.

To list them, send a `GET` request with the ID of the Application. The `fields` parameter limits each result to four fields. Replace the two values with your own:

```bash
export AZION_API_TOKEN="[TOKEN VALUE]"
APPLICATION_ID=<your-application-id>
curl --silent "https://api.azion.com/v4/workspace/applications/$APPLICATION_ID/functions?fields=id,name,function,args" \
  --header "Authorization: Token $AZION_API_TOKEN" \
| jq
```

```json
{
  "count": 2,
  "total_pages": 1,
  "page": 1,
  "page_size": 10,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 65425,
      "name": "greeting-default-args",
      "args": {
        "greeting": "hello"
      },
      "function": 111853
    },
    {
      "id": 65426,
      "name": "greeting-own-args",
      "args": {
        "greeting": "hi from instance"
      },
      "function": 111853
    }
  ]
}
```

In each result, `function` holds the ID of the Function that the Function Instance binds. Both results of this list bind the same Function.

`args` holds the Args that the Function Instance passes into the execution of the Function. The first Function Instance was created without `args`, so it holds a copy of the `default_args` of the Function.

Each Firewall holds its own Function Instances, which bind only Functions whose `execution_environment` is `firewall`. To list them, refer to [Function instances for Firewall](/en/documentation/platform/firewall/functions-instances/).

For each Function Instance in the list, you have its ID and the ID of the Function it binds.

---

## Read one Function Instance

The path of one Function Instance ends with its own `id`, not with the ID of the Function. With the ID of the Function in its place, the API answers `404` with code `10004`.

To read the Function Instance, send a `GET` request with its ID and the ID of its Application. Replace the three values with your own:

```bash
export AZION_API_TOKEN="[TOKEN VALUE]"
APPLICATION_ID=<your-application-id>
FUNCTION_INSTANCE_ID=<your-function-instance-id>
curl --silent "https://api.azion.com/v4/workspace/applications/$APPLICATION_ID/functions/$FUNCTION_INSTANCE_ID" \
  --header "Authorization: Token $AZION_API_TOKEN" \
| jq
```

```json
{
  "data": {
    "id": 65426,
    "name": "greeting-own-args",
    "args": {
      "greeting": "hi from instance"
    },
    "azion_form": {},
    "function": 111853,
    "active": true,
    ...
  }
}
```

The response carries the Args of the Function Instance and the ID of the Function it binds.

---

## Next steps

- [Function Instances](/en/documentation/platform/applications/functions-instances.md): Every field of a Function Instance, and how its Args replace the default Args.
- [Troubleshoot Azion API](/en/documentation/devtools/api/troubleshooting.md): Causes and fixes for the 400, 401, 404, and 405 responses of the API v4.
