# Update by ID

> Update a single record in a collection based on its unique identifier using API Maker's g.sys.db.updateById method.

Source: https://docs.apimaker.dev/v4/examples/sys/db/updateById.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.updateById` calls the [update by id schema API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-update-by-id-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).

## Update by id

**TypeScript**

**Update By Id**

```typescript
let updateById = await g.sys.db.updateById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: 1,
    updateData: {
        "first_name": "MALLORY"
    }
});
```

**Python**

**Update By Id**

```python
update_by_id = await g.sys.db.update_by_id(
    'mysql_8', 'inventory', 'customers',
    1,
    update_data={
        'first_name': 'MALLORY',
    },
)
```

**PHP**

**Update By Id**

```php
$updateById = $g->sys->db->updateById(
    'mysql_8', 'inventory', 'customers',
    1,
    updateData: [
        'first_name' => 'MALLORY',
    ],
);
```

**C#**

**Update By Id**

```csharp
var updateById = await g.Sys.Db.UpdateById(new UpdateById("mysql_8", "inventory", "customers", 1)
{
    UpdateData = new JsonObject
    {
        ["first_name"] = "MALLORY",
    },
});
```

**Go**

**Update By Id**

```go
updateById, err := g.Sys.Db.UpdateById(am.UpdateById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id: 1,
	UpdateData: am.M{
		"first_name": "MALLORY",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Update By Id**

```rust
let update_by_id = g.sys.db.update_by_id(
    UpdateById::new("mysql_8", "inventory", "customers", json!(1))
        .update_data(json!({
            "first_name": "MALLORY",
        })),
)?;
```

**Java**

**Update By Id**

```java
var updateById = g.sys.db.updateById(new UpdateById("mysql_8", "inventory", "customers", 1)
    .updateData(Map.of(
        "first_name", "MALLORY"
    )));
```

**Kotlin**

**Update By Id**

```kotlin
val updateById = g.sys.db.updateById(
    UpdateById("mysql_8", "inventory", "customers", 1)
        .updateData(mapOf(
            "first_name" to "MALLORY",
        )),
)
```

## Update by id primaryKey override

**TypeScript**

**Update By Id primarykey override**

```typescript
let updateById = await g.sys.db.updateById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: "Alice",
    primaryKey: "first_name",
    updateData: {
        "first_name": "MALLORY"
    }
});
```

**Python**

**Update By Id primarykey override**

```python
update_by_id = await g.sys.db.update_by_id(
    'mysql_8', 'inventory', 'customers',
    'Alice',
    primary_key='first_name',
    update_data={
        'first_name': 'MALLORY',
    },
)
```

**PHP**

**Update By Id primarykey override**

```php
$updateById = $g->sys->db->updateById(
    'mysql_8', 'inventory', 'customers',
    'Alice',
    primaryKey: 'first_name',
    updateData: [
        'first_name' => 'MALLORY',
    ],
);
```

**C#**

**Update By Id primarykey override**

```csharp
var updateById = await g.Sys.Db.UpdateById(new UpdateById("mysql_8", "inventory", "customers", "Alice")
{
    PrimaryKey = "first_name",
    UpdateData = new JsonObject
    {
        ["first_name"] = "MALLORY",
    },
});
```

**Go**

**Update By Id primarykey override**

```go
updateById, err := g.Sys.Db.UpdateById(am.UpdateById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id:         "Alice",
	PrimaryKey: "first_name",
	UpdateData: am.M{
		"first_name": "MALLORY",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Update By Id primarykey override**

```rust
let update_by_id = g.sys.db.update_by_id(
    UpdateById::new("mysql_8", "inventory", "customers", "Alice")
        .primary_key("first_name")
        .update_data(json!({
            "first_name": "MALLORY",
        })),
)?;
```

**Java**

**Update By Id primarykey override**

```java
var updateById = g.sys.db.updateById(new UpdateById("mysql_8", "inventory", "customers", "Alice")
    .primaryKey("first_name")
    .updateData(Map.of(
        "first_name", "MALLORY"
    )));
```

**Kotlin**

**Update By Id primarykey override**

```kotlin
val updateById = g.sys.db.updateById(
    UpdateById("mysql_8", "inventory", "customers", "Alice")
        .primaryKey("first_name")
        .updateData(mapOf(
            "first_name" to "MALLORY",
        )),
)
```

## Update by id [upsert]

**TypeScript**

**Update By Id with upsert**

```typescript
let updateById = await g.sys.db.updateById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: "202",
    updateData: {
        "first_name": "MALLORY",
        "last_name": "ANI"
    },
    upsert: true
});
```

**Python**

**Update By Id with upsert**

```python
update_by_id = await g.sys.db.update_by_id(
    'mysql_8', 'inventory', 'customers',
    '202',
    update_data={
        'first_name': 'MALLORY',
        'last_name': 'ANI',
    },
    upsert=True,
)
```

**PHP**

**Update By Id with upsert**

```php
$updateById = $g->sys->db->updateById(
    'mysql_8', 'inventory', 'customers',
    '202',
    updateData: [
        'first_name' => 'MALLORY',
        'last_name' => 'ANI',
    ],
    upsert: true,
);
```

**C#**

**Update By Id with upsert**

```csharp
var updateById = await g.Sys.Db.UpdateById(new UpdateById("mysql_8", "inventory", "customers", "202")
{
    UpdateData = new JsonObject
    {
        ["first_name"] = "MALLORY",
        ["last_name"] = "ANI",
    },
    Upsert = true,
});
```

**Go**

**Update By Id with upsert**

```go
updateById, err := g.Sys.Db.UpdateById(am.UpdateById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id: "202",
	UpdateData: am.M{
		"first_name": "MALLORY",
		"last_name":  "ANI",
	},
	Upsert: true,
})
if err != nil {
	return nil, err
}
```

**Rust**

**Update By Id with upsert**

```rust
let update_by_id = g.sys.db.update_by_id(
    UpdateById::new("mysql_8", "inventory", "customers", "202")
        .update_data(json!({
            "first_name": "MALLORY",
            "last_name": "ANI",
        }))
        .upsert(true),
)?;
```

**Java**

**Update By Id with upsert**

```java
var updateById = g.sys.db.updateById(new UpdateById("mysql_8", "inventory", "customers", "202")
    .updateData(Map.of(
        "first_name", "MALLORY",
        "last_name", "ANI"
    ))
    .upsert(true));
```

**Kotlin**

**Update By Id with upsert**

```kotlin
val updateById = g.sys.db.updateById(
    UpdateById("mysql_8", "inventory", "customers", "202")
        .updateData(mapOf(
            "first_name" to "MALLORY",
            "last_name" to "ANI",
        ))
        .upsert(true),
)
```

## Update by id [returnDocument]  

**TypeScript**

**Update By Id with returnDocument**

```typescript
let updateById = await g.sys.db.updateById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: "202",
    updateData: {
        "first_name": "MALLORY"
    },
    returnDocument: 'before', // return old doc if value 'before'. Supported values are 'before' | 'after'.
});
```

**Python**

**Update By Id with returnDocument**

```python
update_by_id = await g.sys.db.update_by_id(
    'mysql_8', 'inventory', 'customers',
    '202',
    update_data={
        'first_name': 'MALLORY',
    },
    return_document='before',  # return old doc if value 'before'. Supported values are 'before' | 'after'.
)
```

**PHP**

**Update By Id with returnDocument**

```php
$updateById = $g->sys->db->updateById(
    'mysql_8', 'inventory', 'customers',
    '202',
    updateData: [
        'first_name' => 'MALLORY',
    ],
    returnDocument: 'before', // return old doc if value 'before'. Supported values are 'before' | 'after'.
);
```

**C#**

**Update By Id with returnDocument**

```csharp
var updateById = await g.Sys.Db.UpdateById(new UpdateById("mysql_8", "inventory", "customers", "202")
{
    UpdateData = new JsonObject
    {
        ["first_name"] = "MALLORY",
    },
    ReturnDocument = "before", // return old doc if value 'before'. Supported values are 'before' | 'after'.
});
```

**Go**

**Update By Id with returnDocument**

```go
updateById, err := g.Sys.Db.UpdateById(am.UpdateById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id: "202",
	UpdateData: am.M{
		"first_name": "MALLORY",
	},
	ReturnDocument: "before", // return old doc if value 'before'. Supported values are 'before' | 'after'.
})
if err != nil {
	return nil, err
}
```

**Rust**

**Update By Id with returnDocument**

```rust
let update_by_id = g.sys.db.update_by_id(
    UpdateById::new("mysql_8", "inventory", "customers", "202")
        .update_data(json!({
            "first_name": "MALLORY",
        }))
        .return_document("before"), // return old doc if value 'before'. Supported values are 'before' | 'after'.
)?;
```

**Java**

**Update By Id with returnDocument**

```java
var updateById = g.sys.db.updateById(new UpdateById("mysql_8", "inventory", "customers", "202")
    .updateData(Map.of(
        "first_name", "MALLORY"
    ))
    .returnDocument("before")); // return old doc if value 'before'. Supported values are 'before' | 'after'.
```

**Kotlin**

**Update By Id with returnDocument**

```kotlin
val updateById = g.sys.db.updateById(
    UpdateById("mysql_8", "inventory", "customers", "202")
        .updateData(mapOf(
            "first_name" to "MALLORY",
        ))
        .returnDocument("before"), // return old doc if value 'before'. Supported values are 'before' | 'after'.
)
```

## Structure

**TypeScript**

**Update by id with all params**

```typescript
let updateById = await g.sys.db.updateById({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    id: 1008,
    primaryKey: "id",
    updateData: {
        "first_name": "Tanmay",
    },
    returnDocument: 'before', // return old doc if value 'before'. Supported values are 'before' | 'after'.
    select: "COLUMN_NAMES",
    upsert: false,
    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**

**Update by id with all params**

```python
update_by_id = await g.sys.db.update_by_id(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    1008,
    primary_key='id',
    update_data={
        'first_name': 'Tanmay',
    },
    return_document='before',  # return old doc if value 'before'. Supported values are 'before' | 'after'.
    select='COLUMN_NAMES',
    upsert=False,
    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**

**Update by id with all params**

```php
$updateById = $g->sys->db->updateById(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    1008,
    primaryKey: 'id',
    updateData: [
        'first_name' => 'Tanmay',
    ],
    returnDocument: 'before', // return old doc if value 'before'. Supported values are 'before' | 'after'.
    select: 'COLUMN_NAMES',
    upsert: false,
    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#**

**Update by id with all params**

```csharp
var updateById = await g.Sys.Db.UpdateById(new UpdateById("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", 1008)
{
    PrimaryKey = "id",
    UpdateData = new JsonObject
    {
        ["first_name"] = "Tanmay",
    },
    ReturnDocument = "before", // return old doc if value 'before'. Supported values are 'before' | 'after'.
    Select = "COLUMN_NAMES",
    Upsert = false,
    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**

**Update by id with all params**

```go
updateById, err := g.Sys.Db.UpdateById(am.UpdateById{
	Instance: "INSTANCE_NAME", Database: "DB_NAME", Collection: "COLLECTION_NAME",
	Id:         1008,
	PrimaryKey: "id",
	UpdateData: am.M{
		"first_name": "Tanmay",
	},
	ReturnDocument: "before", // return old doc if value 'before'. Supported values are 'before' | 'after'.
	Select:         "COLUMN_NAMES",
	Upsert:         false,
	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**

**Update by id with all params**

```rust
let update_by_id = g.sys.db.update_by_id(
    UpdateById::new("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", json!(1008))
        .primary_key("id")
        .update_data(json!({
            "first_name": "Tanmay",
        }))
        .return_document("before") // return old doc if value 'before'. Supported values are 'before' | 'after'.
        .select("COLUMN_NAMES")
        .upsert(false)
        .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**

**Update by id with all params**

```java
var updateById = g.sys.db.updateById(new UpdateById("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", 1008)
    .primaryKey("id")
    .updateData(Map.of(
        "first_name", "Tanmay"
    ))
    .returnDocument("before") // return old doc if value 'before'. Supported values are 'before' | 'after'.
    .select("COLUMN_NAMES")
    .upsert(false)
    .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**

**Update by id with all params**

```kotlin
val updateById = g.sys.db.updateById(
    UpdateById("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", 1008)
        .primaryKey("id")
        .updateData(mapOf(
            "first_name" to "Tanmay",
        ))
        .returnDocument("before") // return old doc if value 'before'. Supported values are 'before' | 'after'.
        .select("COLUMN_NAMES")
        .upsert(false)
        .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**

**Update the customer 1 of the tenant acme**

```typescript
let updateById = await g.sys.db.updateById({
    instance: "crm::acme", database: "crm", collection: "customers",
    id: 1,
    updateData: {
        "first_name": "MALLORY"
    }
});
```

**Python**

**Update the customer 1 of the tenant acme**

```python
update_by_id = await g.sys.db.update_by_id(
    'crm::acme', 'crm', 'customers',
    1,
    update_data={
        'first_name': 'MALLORY',
    },
)
```

**PHP**

**Update the customer 1 of the tenant acme**

```php
$updateById = $g->sys->db->updateById(
    'crm::acme', 'crm', 'customers',
    1,
    updateData: [
        'first_name' => 'MALLORY',
    ],
);
```

**C#**

**Update the customer 1 of the tenant acme**

```csharp
var updateById = await g.Sys.Db.UpdateById(new UpdateById("crm::acme", "crm", "customers", 1)
{
    UpdateData = new JsonObject
    {
        ["first_name"] = "MALLORY",
    },
});
```

**Go**

**Update the customer 1 of the tenant acme**

```go
updateById, err := g.Sys.Db.UpdateById(am.UpdateById{
	Instance: "crm::acme", Database: "crm", Collection: "customers",
	Id: 1,
	UpdateData: am.M{
		"first_name": "MALLORY",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Update the customer 1 of the tenant acme**

```rust
let update_by_id = g.sys.db.update_by_id(
    UpdateById::new("crm::acme", "crm", "customers", json!(1))
        .update_data(json!({
            "first_name": "MALLORY",
        })),
)?;
```

**Java**

**Update the customer 1 of the tenant acme**

```java
var updateById = g.sys.db.updateById(new UpdateById("crm::acme", "crm", "customers", 1)
    .updateData(Map.of(
        "first_name", "MALLORY"
    )));
```

**Kotlin**

**Update the customer 1 of the tenant acme**

```kotlin
val updateById = g.sys.db.updateById(
    UpdateById("crm::acme", "crm", "customers", 1)
        .updateData(mapOf(
            "first_name" to "MALLORY",
        )),
)
```

## Without a schema

`g.sys.db.gen.updateByIdGen` takes the same arguments and calls the [update by id generated API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-update-by-id-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.updateByIdGen(…)` |
| Python | `g.sys.db.gen.update_by_id_gen(…)` |
| PHP | `$g->sys->db->gen->updateByIdGen(…)` |
| C#, Go | `g.Sys.Db.Gen.UpdateByIdGen(…)` |
| Rust | `g.sys.db.update_by_id_gen(UpdateById::new(…))` |
| Java, Kotlin | `g.sys.db.gen.updateByIdGen(…)` |

## Related

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