# Code

## Execute Function

<mark style="color:green;">`POST`</mark> `https://api.codemash.io/:version/serverless/functions/:id/execute`

Executes a function during a request.

#### Path Parameters

| Name    | Type   | Description                                             |
| ------- | ------ | ------------------------------------------------------- |
| version | string | The version of the API endpoint. Current latest **v1**. |
| id      | string | The ID of function to be executed.                      |

#### Headers

| Name           | Type   | Description                                            |
| -------------- | ------ | ------------------------------------------------------ |
| Authorization  | string | Your project's secret key.                             |
| x-cm-projectid | string | Your project's ID. Can be passed as a query parameter. |

#### Request Body

| Name      | Type   | Description                                         |
| --------- | ------ | --------------------------------------------------- |
| Template  | string | Parameter of JSON format to pass into the function. |
| Qualifier | string | Version or alias of a function to execute.          |

{% tabs %}
{% tab title="200 Returns a response received from a function as string." %}

```javascript
{
    Result: ""
}
```

{% endtab %}

{% tab title="401 Returns if the user does not have a valid permission to call this method." %}

```
```

{% endtab %}

{% tab title="500 " %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var codeService = new CodeMashCodeService(client);

var response = await codeService.ExecuteFunctionAsync(new ExecuteFunctionRequest
{
    Id = Guid.Parse("{FUNCTION_ID}"),
});
```

{% endtab %}

{% tab title="Node" %}

```
```

{% endtab %}

{% tab title="PHP" %}

```php
use Codemash\CodemashClient;
use Codemash\CodemashCode;

class CodemashService
{
    protected CodemashCode $codemashCode;

    public function __construct()
    {
        $secretKey = '{YOUR_SECRET_KEY}';
        $projectId = '{YOUR_PROJECT_ID}';

        $client = new CodemashClient($secretKey, $projectId);
        $this->codemashCode = new CodemashAuth($client);
    }

    public function executeFunction()
    {
        $responseData = $this->codemashCode->executeFunction([
            'id' => '{YOUR_FUNCTION_ID}',
        ]);
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
In order to execute the function method, you can use **GET** method instead of **POST**.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.codemash.io/api/code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
