# Delete Record by ID API

> Securely delete specific records by ID with API Maker’s reliable remove API.

Source: https://docs.apimaker.dev/v1/examples/sys/db/gen/removeByIdGen.html

`g.sys.db.gen.removeByIdGen` calls the [remove by id generated API](https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-remove-by-id-api.html) from your code : no schema, the data as it is in the table.

## Structure

**Remove by id**

```typescript
let removeById = await g.sys.db.gen.removeByIdGen({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    select: "COLUMN_NAMES",
    id: 7878,
    primaryKey: "COLUMN_NAME"
});
```

## Simple removeById

**Remove By Id**

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

## removeById primaryKey override

**Remove By Id primarykey override**

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

## removeById [header]

**Remove By Id header**

```typescript
let updateById = await g.sys.db.gen.removeByIdGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    id: "Bob",
    primaryKey: "first_name",    
    updateData: {
        "first_name": "MALLORY"
    },
    headers: {
        "x-am-response-case": "capitalCase"
    }
});
```

## removeById [select]

**Remove By Id header**

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

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](https://docs.apimaker.dev/v1/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/v1/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.

**Remove the customer 101 of the tenant acme**

```typescript
let removeById = await g.sys.db.gen.removeByIdGen({
    instance: "crm::acme", database: "crm", collection: "customers",
    id: 101
});
```

## Related

- [Remove by id generated API](https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-remove-by-id-api.html) · [Schema API from code](https://docs.apimaker.dev/v1/examples/sys/db/removeById.html) · [The global object g](https://docs.apimaker.dev/v1/docs/pre-defined-terms/global-object-g.html)
