Code
CodeMash Code service allows you to add your own custom functions or CodeMash provided functions which can later be used in various triggers, scheduled tasks, or called through API.
To start using Code API you first need to enable code service in your CodeMash dashboard.
Features included in code service:
  1. 1.
    Providers - the ability to add your own functions from external providers.
  2. 2.
    Functions - executing your own custom pieces of code.
  3. 3.
    CodeMash functions - using CodeMash implemented functions.

Using SDK

If you decide to use one of our provided SDK, the following code shows how to initialize code service.
.NET
Node
PHP
1
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
2
var apiKey = "{YOUR_SECRET_KEY}";
3
4
var client = new CodeMashClient(apiKey, projectId);
5
var codeService = new CodeMashCodeService(client);
Copied!
1
Copied!
1
use Codemash\CodemashClient;
2
use Codemash\CodemashCode;
3
4
class CodemashService
5
{
6
protected CodemashCode $codemashCode;
7
8
public function __construct()
9
{
10
$secretKey = '{YOUR_SECRET_KEY}';
11
$projectId = '{YOUR_PROJECT_ID}';
12
13
$client = new CodemashClient($secretKey, $projectId);
14
$this->codemashCode = new CodemashAuth($client);
15
}
16
17
}
Copied!

Example

The following are examples of code SDK using different languages and frameworks.
.NET
Node
PHP
1
using System;
2
using CodeMash.Client;
3
using CodeMash.Code.Services;
4
using Isidos.CodeMash.ServiceContracts;
5
6
namespace ConsoleApplication
7
{
8
class Program
9
{
10
static void Main(string[] args)
11
{
12
// 1. Get your Project ID and Secret Key
13
var projectId = Guid.Parse("{YOUR_PROJECT_ID}");
14
var apiKey = "{YOUR_SECRET_KEY}";
15
16
// 2. Create a general client for API calls
17
var client = new CodeMashClient(apiKey, projectId);
18
19
// 3. Create a service object
20
var codeService = new CodeMashCodeService(client);
21
22
// 4. Call an API method
23
codeService.ExecuteFunction(new ExecuteFunctionRequest
24
{
25
Id = Guid.Parse("{YOUR_FUNCTION_ID}")
26
});
27
}
28
}
29
}
Copied!
1
Copied!
1
use Codemash\CodemashClient;
2
use Codemash\CodemashCode;
3
4
class CodemashService
5
{
6
protected CodemashCode $codemashCode;
7
8
public function __construct()
9
{
10
$secretKey = '{YOUR_SECRET_KEY}';
11
$projectId = '{YOUR_PROJECT_ID}';
12
13
$client = new CodemashClient($secretKey, $projectId);
14
$this->codemashCode = new CodemashAuth($client);
15
}
16
17
public function executeFunction()
18
{
19
$responseData = $this->codemashCode->executeFunction([
20
'id' => '{YOUR_FUNCTION_ID}',
21
]);
22
}
23
}
Copied!

Working with Code Service

The following links explore the usage of code service:
Last modified 1yr ago