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 API endpoint.
Headers
Authorization
required
string
Your project's secret key.
x-cm-projectid
required
string
Your project's ID. Can be passed as 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
.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

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 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 query parameter.
Body Parameters
recordId
required
string
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
.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

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 API endpoint.
Headers
Authorization
required
string
Your project's secret key.
x-cm-projectid
required
string
Your project's ID. Can be passed as query parameter.
Body Parameters
userId
required
string
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
.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"
}
);
}