Files API

Overview of files API methods

post
Upload File

https://api.codemash.io/:version/files
Uploads a file.
Request
Response
Request
Path Parameters
version
required
string
The version of the API endpoint.
Headers
Authorization
required
string
Your project's secret key.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Body Parameters
path
optional
string
Path in your file browser.
Response
200: OK
Returns an ID of created notification group.
{
Result: ""
}
401: Unauthorized
Returns if the user does not have a valid permission to call this method.
500: Internal Server Error
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = $"{directory}\\test.txt";
using (var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read))
{
var response = await filesService.UploadFileAsync(fsSource, "test.txt",
new UploadFileRequest
{
Path = "folder1"
}
);
}
Node
PHP
use Codemash\CodemashClient;
use Codemash\CodemashFile;
class CodemashService
{
protected CodemashFile $codemashFile;
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashFile = new CodemashFile($client);
}
public function uploadFile()
{
$responseData = $this->codemashFile->uploadFile([
'path' => 'folder1',
'fileUri' => '{YOUR_FILE_PATH}',
'fileName' => '{YOUR_FILE_NAME}',
]);
}
}

post
Upload Record File

https://api.codemash.io/:version/db/:collectionName/files
Uploads a file for a record field.
Request
Response
Request
Path Parameters
version
required
string
The version of the API endpoint.
collectionName
required
string
Name of a collection.
Headers
Authorization
required
string
Your project's secret key.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Body Parameters
recordId
required
string
The ID of a record inside collection.
uniqueFieldName
required
string
Record file field name.
Response
200: OK
Returns an ID of created notification group.
{
Result: ""
}
401: Unauthorized
Returns if the user does not have a valid permission to call this method.
500: Internal Server Error
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = $"{directory}\\test.txt";
using (var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read))
{
var response = await filesService.UploadRecordFileAsync(fsSource, "test.txt",
new UploadRecordFileRequest
{
RecordId = "{RECORD_ID}",
UniqueFieldName = "file_field_name"
}
);
}
Node
PHP
use Codemash\CodemashClient;
use Codemash\CodemashFile;
class CodemashService
{
protected CodemashFile $codemashFile;
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashFile = new CodemashFile($client);
}
public function uploadRecordFile()
{
$responseData = $this->codemashFile->uploadRecordFile([
'fileUri' => '{YOUR_FILE_PATH}',
'fileName' => '{YOUR_FILE_NAME}',
'collectionName' => '{COLLECTION_NAME}',
'recordId' => '{RECORD_ID}',
'uniqueFieldName' => 'file_field_name',
]);
}
}

post
Upload User File

https://api.codemash.io/:version/membership/users/files
Uploads a file for a user meta field.
Request
Response
Request
Path Parameters
version
required
string
The version of the API endpoint.
Headers
Authorization
required
string
Your project's secret key.
x-cm-projectid
required
string
Your project's ID. Can be passed as a query parameter.
Body Parameters
userId
required
string
The ID of a user.
metaFieldName
required
string
User meta-file field name.
Response
200: OK
Returns an ID of created notification group.
{
Result: ""
}
401: Unauthorized
Returns if the user does not have a valid permission to call this method.
500: Internal Server Error
.NET
Node
PHP
.NET
var client = new CodeMashClient(apiKey, projectId);
var filesService = new CodeMashFilesService(client);
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filePath = $"{directory}\\test.txt";
using (var fsSource = new FileStream(path, FileMode.Open, FileAccess.Read))
{
var response = await filesService.UploadUserFileAsync(fsSource, "test.txt",
new UploadUserFileRequest
{
UserId = "{USER_ID}",
MetaFieldName = "file_field_name"
}
);
}
Node
PHP
use Codemash\CodemashClient;
use Codemash\CodemashFile;
class CodemashService
{
protected CodemashFile $codemashFile;
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashFile = new CodemashFile($client);
}
public function uploadUserFile()
{
$responseData = $this->codemashFile->uploadUserFile([
'fileUri' => '{YOUR_FILE_PATH}',
'fileName' => '{YOUR_FILE_NAME}',
'userId' => '{USER_ID}',
'metaFieldName' => 'file_field_name',
]);
}
}