# Master Save/Update

> Perform save or update operations on single or multiple records with master-level control using API Maker.

Source: https://docs.apimaker.dev/v4/examples/sys/db/masterSave.html

> **The code in every language**
>
> Each example is the inside of `main`, written in every [language](https://docs.apimaker.dev/v4/docs/languages/index.html) API Maker runs : pick yours in the tabs, and every page shows it from then on. The types a call takes (`GetAll`, `DeepItem`…) are those of `am` : `from am import GetAll` in Python, `use am::GetAll;` in Rust, `import am.GetAll;` in Java and Kotlin ; PHP and C# have them without an import, Go names them `am.GetAll`.

`g.sys.db.masterSave` calls the [master save schema API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-master-save-api.html) of any table from your code, with the same headers and query parameters as over HTTP. It returns the data. The whole envelope (`success`, `statusCode`, `data`, `totalCount`, `errors`…) comes back when `true` is passed as the second argument in TypeScript, and through `full` in the other languages : `g.sys.db.full` (`g.Sys.Db.Full` in C# and Go, `$g->sys->db->full` in PHP).

## master save single data

**TypeScript**

**Master save**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "mysql_8", database: "inventory", collection: "customers",
    saveData: {
        "first_name": "Bob",
        "last_name": "Lin"
    }
});
```

**Python**

**Master save**

```python
master_save = await g.sys.db.master_save(
    'mysql_8', 'inventory', 'customers',
    {
        'first_name': 'Bob',
        'last_name': 'Lin',
    },
)
```

**PHP**

**Master save**

```php
$masterSave = $g->sys->db->masterSave(
    'mysql_8', 'inventory', 'customers',
    [
        'first_name' => 'Bob',
        'last_name' => 'Lin',
    ],
);
```

**C#**

**Master save**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("mysql_8", "inventory", "customers", new JsonObject
{
    ["first_name"] = "Bob",
    ["last_name"] = "Lin",
}));
```

**Go**

**Master save**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	SaveData: am.M{
		"first_name": "Bob",
		"last_name":  "Lin",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save**

```rust
let master_save = g.sys.db.master_save(
    Save::new("mysql_8", "inventory", "customers", json!({
        "first_name": "Bob",
        "last_name": "Lin",
    })),
)?;
```

**Java**

**Master save**

```java
var masterSave = g.sys.db.masterSave(new Save("mysql_8", "inventory", "customers", Map.of(
    "first_name", "Bob",
    "last_name", "Lin"
)));
```

**Kotlin**

**Master save**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("mysql_8", "inventory", "customers", mapOf(
        "first_name" to "Bob",
        "last_name" to "Lin",
    )),
)
```

## master save multiple data

**TypeScript**

**Master save**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "mysql_8", database: "inventory", collection: "customers",
    saveData: [
        {
            "first_name": "Bob",
            "last_name": "Lin"
        },
        {
            "first_name": "Bob",
            "last_name": "Lin"
        }
    ]
});
```

**Python**

**Master save**

```python
master_save = await g.sys.db.master_save(
    'mysql_8', 'inventory', 'customers',
    [
        {
            'first_name': 'Bob',
            'last_name': 'Lin',
        },
        {
            'first_name': 'Bob',
            'last_name': 'Lin',
        },
    ],
)
```

**PHP**

**Master save**

```php
$masterSave = $g->sys->db->masterSave(
    'mysql_8', 'inventory', 'customers',
    [
        [
            'first_name' => 'Bob',
            'last_name' => 'Lin',
        ],
        [
            'first_name' => 'Bob',
            'last_name' => 'Lin',
        ],
    ],
);
```

**C#**

**Master save**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("mysql_8", "inventory", "customers", new JsonArray
{
    new JsonObject
    {
        ["first_name"] = "Bob",
        ["last_name"] = "Lin",
    },
    new JsonObject
    {
        ["first_name"] = "Bob",
        ["last_name"] = "Lin",
    },
}));
```

**Go**

**Master save**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	SaveData: []any{
		am.M{
			"first_name": "Bob",
			"last_name":  "Lin",
		},
		am.M{
			"first_name": "Bob",
			"last_name":  "Lin",
		},
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save**

```rust
let master_save = g.sys.db.master_save(
    Save::new("mysql_8", "inventory", "customers", json!([
        {
            "first_name": "Bob",
            "last_name": "Lin",
        },
        {
            "first_name": "Bob",
            "last_name": "Lin",
        },
    ])),
)?;
```

**Java**

**Master save**

```java
var masterSave = g.sys.db.masterSave(new Save("mysql_8", "inventory", "customers", List.of(
    Map.of(
        "first_name", "Bob",
        "last_name", "Lin"
    ),
    Map.of(
        "first_name", "Bob",
        "last_name", "Lin"
    )
)));
```

**Kotlin**

**Master save**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("mysql_8", "inventory", "customers", listOf(
        mapOf(
            "first_name" to "Bob",
            "last_name" to "Lin",
        ),
        mapOf(
            "first_name" to "Bob",
            "last_name" to "Lin",
        ),
    )),
)
```

## with header

**TypeScript**

**Master save with header**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "mysql_8", database: "inventory", collection: "customers",
    saveData: {
        "first_name": "Bob",
        "last_name": "Lin"
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Python**

**Master save with header**

```python
master_save = await g.sys.db.master_save(
    'mysql_8', 'inventory', 'customers',
    {
        'first_name': 'Bob',
        'last_name': 'Lin',
    },
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
)
```

**PHP**

**Master save with header**

```php
$masterSave = $g->sys->db->masterSave(
    'mysql_8', 'inventory', 'customers',
    [
        'first_name' => 'Bob',
        'last_name' => 'Lin',
    ],
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    ],
);
```

**C#**

**Master save with header**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("mysql_8", "inventory", "customers", new JsonObject
{
    ["first_name"] = "Bob",
    ["last_name"] = "Lin",
})
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Go**

**Master save with header**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	SaveData: am.M{
		"first_name": "Bob",
		"last_name":  "Lin",
	},
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save with header**

```rust
let master_save = g.sys.db.master_save(
    Save::new("mysql_8", "inventory", "customers", json!({
        "first_name": "Bob",
        "last_name": "Lin",
    }))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
)?;
```

**Java**

**Master save with header**

```java
var masterSave = g.sys.db.masterSave(new Save("mysql_8", "inventory", "customers", Map.of(
    "first_name", "Bob",
    "last_name", "Lin"
))
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )));
```

**Kotlin**

**Master save with header**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("mysql_8", "inventory", "customers", mapOf(
        "first_name" to "Bob",
        "last_name" to "Lin",
    ))
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
)
```

## multiple database entry

**TypeScript**

**Master save with multy data[with help of schema configuration]**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "mysql_8", database: "inventory", collection: "customers",
    saveData: {
        "city_name": "Wembley", //city_name save in mysql database
        "state_id": {
            "state_name": "London", //state_name save in maria database
            "country_id": {
                "country_name":"UK" //country_name save in postGreSql database
            }
        }
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Python**

**Master save with multy data[with help of schema configuration]**

```python
master_save = await g.sys.db.master_save(
    'mysql_8', 'inventory', 'customers',
    {
        'city_name': 'Wembley',  # city_name save in mysql database
        'state_id': {
            'state_name': 'London',  # state_name save in maria database
            'country_id': {
                'country_name': 'UK',  # country_name save in postGreSql database
            },
        },
    },
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
)
```

**PHP**

**Master save with multy data[with help of schema configuration]**

```php
$masterSave = $g->sys->db->masterSave(
    'mysql_8', 'inventory', 'customers',
    [
        'city_name' => 'Wembley', // city_name save in mysql database
        'state_id' => [
            'state_name' => 'London', // state_name save in maria database
            'country_id' => [
                'country_name' => 'UK', // country_name save in postGreSql database
            ],
        ],
    ],
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    ],
);
```

**C#**

**Master save with multy data[with help of schema configuration]**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("mysql_8", "inventory", "customers", new JsonObject
{
    ["city_name"] = "Wembley", // city_name save in mysql database
    ["state_id"] = new JsonObject
    {
        ["state_name"] = "London", // state_name save in maria database
        ["country_id"] = new JsonObject
        {
            ["country_name"] = "UK", // country_name save in postGreSql database
        },
    },
})
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Go**

**Master save with multy data[with help of schema configuration]**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	SaveData: am.M{
		"city_name": "Wembley", // city_name save in mysql database
		"state_id": am.M{
			"state_name": "London", // state_name save in maria database
			"country_id": am.M{
				"country_name": "UK", // country_name save in postGreSql database
			},
		},
	},
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save with multy data[with help of schema configuration]**

```rust
let master_save = g.sys.db.master_save(
    Save::new("mysql_8", "inventory", "customers", json!({
        "city_name": "Wembley", // city_name save in mysql database
        "state_id": {
            "state_name": "London", // state_name save in maria database
            "country_id": {
                "country_name": "UK", // country_name save in postGreSql database
            },
        },
    }))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
)?;
```

**Java**

**Master save with multy data[with help of schema configuration]**

```java
var masterSave = g.sys.db.masterSave(new Save("mysql_8", "inventory", "customers", Map.of(
    "city_name", "Wembley", // city_name save in mysql database
    "state_id", Map.of(
        "state_name", "London", // state_name save in maria database
        "country_id", Map.of(
            "country_name", "UK" // country_name save in postGreSql database
        )
    )
))
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )));
```

**Kotlin**

**Master save with multy data[with help of schema configuration]**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("mysql_8", "inventory", "customers", mapOf(
        "city_name" to "Wembley", // city_name save in mysql database
        "state_id" to mapOf(
            "state_name" to "London", // state_name save in maria database
            "country_id" to mapOf(
                "country_name" to "UK", // country_name save in postGreSql database
            ),
        ),
    ))
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
)
```

## multiple database multiple entry

**TypeScript**

**Master save with multy data[with help of schema configuration]**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "mysql_8", database: "inventory", collection: "customers",
    saveData: [{
        "city_name": "Wembley",
        "state_id": {
            "state_name": "London",
            "country_id": 302
        }
    },
    {
        "city_name": "Buffalo",
        "state_id": {
            "state_name": "Chicago",
            "country_id": 303
        }
    }],
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Python**

**Master save with multy data[with help of schema configuration]**

```python
master_save = await g.sys.db.master_save(
    'mysql_8', 'inventory', 'customers',
    [
        {
            'city_name': 'Wembley',
            'state_id': {
                'state_name': 'London',
                'country_id': 302,
            },
        },
        {
            'city_name': 'Buffalo',
            'state_id': {
                'state_name': 'Chicago',
                'country_id': 303,
            },
        },
    ],
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
)
```

**PHP**

**Master save with multy data[with help of schema configuration]**

```php
$masterSave = $g->sys->db->masterSave(
    'mysql_8', 'inventory', 'customers',
    [
        [
            'city_name' => 'Wembley',
            'state_id' => [
                'state_name' => 'London',
                'country_id' => 302,
            ],
        ],
        [
            'city_name' => 'Buffalo',
            'state_id' => [
                'state_name' => 'Chicago',
                'country_id' => 303,
            ],
        ],
    ],
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    ],
);
```

**C#**

**Master save with multy data[with help of schema configuration]**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("mysql_8", "inventory", "customers", new JsonArray
{
    new JsonObject
    {
        ["city_name"] = "Wembley",
        ["state_id"] = new JsonObject
        {
            ["state_name"] = "London",
            ["country_id"] = 302,
        },
    },
    new JsonObject
    {
        ["city_name"] = "Buffalo",
        ["state_id"] = new JsonObject
        {
            ["state_name"] = "Chicago",
            ["country_id"] = 303,
        },
    },
})
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
});
```

**Go**

**Master save with multy data[with help of schema configuration]**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	SaveData: []any{
		am.M{
			"city_name": "Wembley",
			"state_id": am.M{
				"state_name": "London",
				"country_id": 302,
			},
		},
		am.M{
			"city_name": "Buffalo",
			"state_id": am.M{
				"state_name": "Chicago",
				"country_id": 303,
			},
		},
	},
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save with multy data[with help of schema configuration]**

```rust
let master_save = g.sys.db.master_save(
    Save::new("mysql_8", "inventory", "customers", json!([
        {
            "city_name": "Wembley",
            "state_id": {
                "state_name": "London",
                "country_id": 302,
            },
        },
        {
            "city_name": "Buffalo",
            "state_id": {
                "state_name": "Chicago",
                "country_id": 303,
            },
        },
    ]))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
)?;
```

**Java**

**Master save with multy data[with help of schema configuration]**

```java
var masterSave = g.sys.db.masterSave(new Save("mysql_8", "inventory", "customers", List.of(
    Map.of(
        "city_name", "Wembley",
        "state_id", Map.of(
            "state_name", "London",
            "country_id", 302
        )
    ),
    Map.of(
        "city_name", "Buffalo",
        "state_id", Map.of(
            "state_name", "Chicago",
            "country_id", 303
        )
    )
))
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )));
```

**Kotlin**

**Master save with multy data[with help of schema configuration]**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("mysql_8", "inventory", "customers", listOf(
        mapOf(
            "city_name" to "Wembley",
            "state_id" to mapOf(
                "state_name" to "London",
                "country_id" to 302,
            ),
        ),
        mapOf(
            "city_name" to "Buffalo",
            "state_id" to mapOf(
                "state_name" to "Chicago",
                "country_id" to 303,
            ),
        ),
    ))
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
)
```

## Structure

**TypeScript**

**Master save**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    saveData: {
        "COLUMN_NAME": "VALUE",
        "COLUMN_NAME2": "VALUE",
    },
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type": "make_flat", // no_action | make_flat
        "x-am-meta": "true", // true, false
        "x-am-internationalization": "USER_I18N_ID",
        "x-am-run-in-sandbox": "2",
        "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control": "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout": "13000",
        "x-no-compression": "true", // true | false
        "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization": "AUTHORIZATION_TOKEN",
        "x-am-user-authorization": "API_USER_TOKEN",
        "x-aws-authorization": "AWS_TOKEN",
        "x-google-authorization": "GOOGLE_TOKEN",
        "x-azure-authorization": "AZURE_TOKEN",
    },
});
```

**Python**

**Master save**

```python
master_save = await g.sys.db.master_save(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    {
        'COLUMN_NAME': 'VALUE',
        'COLUMN_NAME2': 'VALUE',
    },
    headers={
        'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        'x-am-response-object-type': 'make_flat',  # no_action | make_flat
        'x-am-meta': 'true',  # true, false
        'x-am-internationalization': 'USER_I18N_ID',
        'x-am-run-in-sandbox': '2',
        'x-am-content-type-response': 'text/xml',  # application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        'x-am-cache-control': 'reset_cache',  # no_action | reset_cache
        'x-am-get-encrypted-data': 'get_only_encryption',  # no_encryption | get_only_encryption | get_data_and_encryption
        'x-am-sandbox-timeout': '13000',
        'x-no-compression': 'true',  # true | false
        'x-am-encrypted-payload': 'true',  # user will send 'true', when payload is encrypted for transfer
        # Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        'x-am-tenant-username': 'TENANT_USERNAME',  # ex: acme
        # Authorization headers
        'x-am-authorization': 'AUTHORIZATION_TOKEN',
        'x-am-user-authorization': 'API_USER_TOKEN',
        'x-aws-authorization': 'AWS_TOKEN',
        'x-google-authorization': 'GOOGLE_TOKEN',
        'x-azure-authorization': 'AZURE_TOKEN',
    },
)
```

**PHP**

**Master save**

```php
$masterSave = $g->sys->db->masterSave(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    [
        'COLUMN_NAME' => 'VALUE',
        'COLUMN_NAME2' => 'VALUE',
    ],
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        'x-am-response-object-type' => 'make_flat', // no_action | make_flat
        'x-am-meta' => 'true', // true, false
        'x-am-internationalization' => 'USER_I18N_ID',
        'x-am-run-in-sandbox' => '2',
        'x-am-content-type-response' => 'text/xml', // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        'x-am-cache-control' => 'reset_cache', // no_action | reset_cache
        'x-am-get-encrypted-data' => 'get_only_encryption', // no_encryption | get_only_encryption | get_data_and_encryption
        'x-am-sandbox-timeout' => '13000',
        'x-no-compression' => 'true', // true | false
        'x-am-encrypted-payload' => 'true', // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        'x-am-tenant-username' => 'TENANT_USERNAME', // ex: acme
        // Authorization headers
        'x-am-authorization' => 'AUTHORIZATION_TOKEN',
        'x-am-user-authorization' => 'API_USER_TOKEN',
        'x-aws-authorization' => 'AWS_TOKEN',
        'x-google-authorization' => 'GOOGLE_TOKEN',
        'x-azure-authorization' => 'AZURE_TOKEN',
    ],
);
```

**C#**

**Master save**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", new JsonObject
{
    ["COLUMN_NAME"] = "VALUE",
    ["COLUMN_NAME2"] = "VALUE",
})
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        ["x-am-response-object-type"] = "make_flat", // no_action | make_flat
        ["x-am-meta"] = "true", // true, false
        ["x-am-internationalization"] = "USER_I18N_ID",
        ["x-am-run-in-sandbox"] = "2",
        ["x-am-content-type-response"] = "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        ["x-am-cache-control"] = "reset_cache", // no_action | reset_cache
        ["x-am-get-encrypted-data"] = "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        ["x-am-sandbox-timeout"] = "13000",
        ["x-no-compression"] = "true", // true | false
        ["x-am-encrypted-payload"] = "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        ["x-am-tenant-username"] = "TENANT_USERNAME", // ex: acme
        // Authorization headers
        ["x-am-authorization"] = "AUTHORIZATION_TOKEN",
        ["x-am-user-authorization"] = "API_USER_TOKEN",
        ["x-aws-authorization"] = "AWS_TOKEN",
        ["x-google-authorization"] = "GOOGLE_TOKEN",
        ["x-azure-authorization"] = "AZURE_TOKEN",
    },
});
```

**Go**

**Master save**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "INSTANCE_NAME", Database: "DB_NAME", Collection: "COLLECTION_NAME",
	SaveData: am.M{
		"COLUMN_NAME":  "VALUE",
		"COLUMN_NAME2": "VALUE",
	},
	Headers: am.M{
		"x-am-response-case":         "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
		"x-am-response-object-type":  "make_flat",   // no_action | make_flat
		"x-am-meta":                  "true",        // true, false
		"x-am-internationalization":  "USER_I18N_ID",
		"x-am-run-in-sandbox":        "2",
		"x-am-content-type-response": "text/xml",            // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
		"x-am-cache-control":         "reset_cache",         // no_action | reset_cache
		"x-am-get-encrypted-data":    "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
		"x-am-sandbox-timeout":       "13000",
		"x-no-compression":           "true", // true | false
		"x-am-encrypted-payload":     "true", // user will send 'true', when payload is encrypted for transfer
		// Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
		"x-am-tenant-username": "TENANT_USERNAME", // ex: acme
		// Authorization headers
		"x-am-authorization":      "AUTHORIZATION_TOKEN",
		"x-am-user-authorization": "API_USER_TOKEN",
		"x-aws-authorization":     "AWS_TOKEN",
		"x-google-authorization":  "GOOGLE_TOKEN",
		"x-azure-authorization":   "AZURE_TOKEN",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save**

```rust
let master_save = g.sys.db.master_save(
    Save::new("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", json!({
        "COLUMN_NAME": "VALUE",
        "COLUMN_NAME2": "VALUE",
    }))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type": "make_flat", // no_action | make_flat
            "x-am-meta": "true", // true, false
            "x-am-internationalization": "USER_I18N_ID",
            "x-am-run-in-sandbox": "2",
            "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control": "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout": "13000",
            "x-no-compression": "true", // true | false
            "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization": "AUTHORIZATION_TOKEN",
            "x-am-user-authorization": "API_USER_TOKEN",
            "x-aws-authorization": "AWS_TOKEN",
            "x-google-authorization": "GOOGLE_TOKEN",
            "x-azure-authorization": "AZURE_TOKEN",
        })),
)?;
```

**Java**

**Master save**

```java
var masterSave = g.sys.db.masterSave(new Save("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", Map.of(
    "COLUMN_NAME", "VALUE",
    "COLUMN_NAME2", "VALUE"
))
    .headers(JsonObject.of(
        "x-am-response-case", "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type", "make_flat", // no_action | make_flat
        "x-am-meta", "true", // true, false
        "x-am-internationalization", "USER_I18N_ID",
        "x-am-run-in-sandbox", "2",
        "x-am-content-type-response", "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control", "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data", "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout", "13000",
        "x-no-compression", "true", // true | false
        "x-am-encrypted-payload", "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username", "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization", "AUTHORIZATION_TOKEN",
        "x-am-user-authorization", "API_USER_TOKEN",
        "x-aws-authorization", "AWS_TOKEN",
        "x-google-authorization", "GOOGLE_TOKEN",
        "x-azure-authorization", "AZURE_TOKEN"
    )));
```

**Kotlin**

**Master save**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", mapOf(
        "COLUMN_NAME" to "VALUE",
        "COLUMN_NAME2" to "VALUE",
    ))
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type" to "make_flat", // no_action | make_flat
            "x-am-meta" to "true", // true, false
            "x-am-internationalization" to "USER_I18N_ID",
            "x-am-run-in-sandbox" to "2",
            "x-am-content-type-response" to "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control" to "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data" to "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout" to "13000",
            "x-no-compression" to "true", // true | false
            "x-am-encrypted-payload" to "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username" to "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization" to "AUTHORIZATION_TOKEN",
            "x-am-user-authorization" to "API_USER_TOKEN",
            "x-aws-authorization" to "AWS_TOKEN",
            "x-google-authorization" to "GOOGLE_TOKEN",
            "x-azure-authorization" to "AZURE_TOKEN",
        )),
)
```

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](https://docs.apimaker.dev/v4/docs/features/multi-tenant.html) instance `crm`.
- With `instance: "crm"`, the call works on the database of the tenant of the request: a custom API called with the [x-am-tenant-username](https://docs.apimaker.dev/v4/docs/apis-all/header/requestHeader.html#x-am-tenant-username) header passes it on to the APIs it calls. A request without a tenant works on the structure database.

**TypeScript**

**Master save a customer of the tenant acme**

```typescript
let masterSave = await g.sys.db.masterSave({
    instance: "crm::acme", database: "crm", collection: "customers",
    saveData: {
        "first_name": "Bob",
        "last_name": "Lin"
    }
});
```

**Python**

**Master save a customer of the tenant acme**

```python
master_save = await g.sys.db.master_save(
    'crm::acme', 'crm', 'customers',
    {
        'first_name': 'Bob',
        'last_name': 'Lin',
    },
)
```

**PHP**

**Master save a customer of the tenant acme**

```php
$masterSave = $g->sys->db->masterSave(
    'crm::acme', 'crm', 'customers',
    [
        'first_name' => 'Bob',
        'last_name' => 'Lin',
    ],
);
```

**C#**

**Master save a customer of the tenant acme**

```csharp
var masterSave = await g.Sys.Db.MasterSave(new Save("crm::acme", "crm", "customers", new JsonObject
{
    ["first_name"] = "Bob",
    ["last_name"] = "Lin",
}));
```

**Go**

**Master save a customer of the tenant acme**

```go
masterSave, err := g.Sys.Db.MasterSave(am.Save{
	Instance: "crm::acme", Database: "crm", Collection: "customers",
	SaveData: am.M{
		"first_name": "Bob",
		"last_name":  "Lin",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Master save a customer of the tenant acme**

```rust
let master_save = g.sys.db.master_save(
    Save::new("crm::acme", "crm", "customers", json!({
        "first_name": "Bob",
        "last_name": "Lin",
    })),
)?;
```

**Java**

**Master save a customer of the tenant acme**

```java
var masterSave = g.sys.db.masterSave(new Save("crm::acme", "crm", "customers", Map.of(
    "first_name", "Bob",
    "last_name", "Lin"
)));
```

**Kotlin**

**Master save a customer of the tenant acme**

```kotlin
val masterSave = g.sys.db.masterSave(
    Save("crm::acme", "crm", "customers", mapOf(
        "first_name" to "Bob",
        "last_name" to "Lin",
    )),
)
```

## Without a schema

`g.sys.db.gen.masterSaveGen` takes the same arguments and calls the [master save generated API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-master-save-api.html#without-a-schema) : no schema, so the data is read and written as it is in the table, without the conversions, validations and defaults of the schema.

| Language | The call |
|---|---|
| TypeScript | `g.sys.db.gen.masterSaveGen(…)` |
| Python | `g.sys.db.gen.master_save_gen(…)` |
| PHP | `$g->sys->db->gen->masterSaveGen(…)` |
| C#, Go | `g.Sys.Db.Gen.MasterSaveGen(…)` |
| Rust | `g.sys.db.master_save_gen(Save::new(…))` |
| Java, Kotlin | `g.sys.db.gen.masterSaveGen(…)` |

## Related

- [Master save API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-master-save-api.html) · [Generated API from code](https://docs.apimaker.dev/v4/examples/sys/db/masterSave.html#without-a-schema) · [The global object g](https://docs.apimaker.dev/v4/docs/pre-defined-terms/global-object-g.html)
