Insert

Inserts a single document

[InsertOne] - Inserts a single document

post

Inserts a new document into database. https://docs.codemash.io/api/database/collections/insert

Authorizations
AuthorizationstringRequired
Path parameters
CollectionNamestringRequired

Collection name - unique, lowercased, collection name without whitespace. E.g., if your collection title you have entered in the CodeMash dashboard is "Business Trips" then collection name would be "business-trips".

versionstringRequired

The CodeMash API version used to fetch data from the API. If not specified, the last version will be used. E.g.: v2

Header parameters
Acceptstring ยท enumRequired

Accept Header

Possible values:
X-CM-ClusterstringOptional

API key of your cluster. Can be passed in a header as X-CM-Cluster.

X-CM-ProjectIdstringRequired

ID of your project. Can be passed in a header as X-CM-ProjectId.

CultureCodestringOptional

Specify culture code when your response from the API should be localised. E.g.: en

Body
BypassDocumentValidationbooleanOptional

Records are validated against CodeMash JSON Schema before each insert. That can slow down API performance. If you have already validated your data with JSON Schema and you can assure of data integrity, you can bypass document validation by setting this property to true.

WaitForFileUploadbooleanOptional

By default file uploads are done after the record is inserted, set to true in case you need to wait for files to be uploaded

IgnoreTriggersbooleanOptional

Triggers are called each time you insert the document. You can disable triggers if it's not needed. This is really important when you insert in database from trigger itself, so then you can avoid infinite loop.

ResponsibleUserIdstringOptional

Set responsible user for document, but be sure the caller of API has right set of permissions.

ResolveProviderFilesbooleanOptional

If your document has file field(s), then you set field value with Id that comes from your file storage provider. E.g.: When your file provider is AWS S3, so then you can set field value to S3 file key, and this will be automatically combined between your file service provider and CodeMash.

Responses
200

Success

application/json
post
/{version}/db/{CollectionName}
POST /{version}/db/{CollectionName} HTTP/1.1
Host: api.codemash.io/
Authorization: YOUR_API_KEY
Accept: application/json
X-CM-ProjectId: text
Content-Type: application/x-www-form-urlencoded
Content-Length: 135

"BypassDocumentValidation=true&WaitForFileUpload=true&IgnoreTriggers=true&ResponsibleUserId='text'&ResolveProviderFiles=true"
200

Success

{
  "response_status": {
    "error_code": "text",
    "message": "text",
    "stack_trace": "text",
    "errors": [
      {
        "error_code": "text",
        "field_name": "text",
        "message": "text",
        "meta": {
          "ANY_ADDITIONAL_PROPERTY": "text"
        }
      }
    ],
    "meta": {
      "ANY_ADDITIONAL_PROPERTY": "text"
    }
  },
  "result": "text"
}
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);

var person = new Person { Name = "John" };

await service.InsertOneAsync(person, new DatabaseInsertOneOptions());

Check the information about entities on how your class objects are serialized.

Last updated

Was this helpful?