# 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 %}
