# Custom Job IDs

BullMQ automatically generate job ids for all the jobs added to a queue. The job id is an increasing integer number. This is the default and recommended behaviour for most use cases.

It is however possible to add jobs with a custom ID that will be used instead of the one auto-generated. The particularity is that there cannot be 2 jobs with the same job ID, so if you add a second job with the same ID as an existing job in the queue, the second job will just be ignored.

&#x20;This is usually useful in order to implement "debouncing". For example, lets say that you have some system that generates a lot of messages, but you only care to process 1 job, at least until that job has been completely processed. By using a custom job ID, only 1 job will exist in the queue until this job has been processed. If you keep the job in the completed set (the default), or the job fails and is kept in the failed set (also the default), then no new jobs will be added to the queue if they use the same job id. Therefore you must choose a proper "removeOnComplete/Fail" strategy suitable for your particular use case. You can read more about these options in the "Workers" section.

In order to specify a custom job id, just set the jobId field in the job's options:

```typescript
interface JobOpts {
  jobId: string;
  // ... More opts
}
```

{% tabs %}
{% tab title="Curl" %}

```powershell
curl --location 'http://mydomain.dev/queues/my-queue/jobs' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer my-secret-token' \
--data '[{
	  "name": "paint-black",
          "data": {},
          "opts": {
            "jobId": "my-custom-id"
           }
         } 
]'
```

{% endtab %}
{% endtabs %}

This call will add a job with a custom id, note that the data returned by the call now includes the custom id in the id field instead of the autogenerated one.

```json
[
  {
    "name": "paint-black",
    "data": {},
    "opts": { "attempts": 0, "delay": 0, "jobId": "my-custom-id" },
    "id": "my-custom-id",
    "progress": 0,
    "returnvalue": null,
    "stacktrace": null,
    "attemptsStarted": 0,
    "attemptsMade": 0,
    "delay": 0,
    "timestamp": 1708618768745,
    "queueQualifiedName": "bull:my-test-queue"
  }
]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bullmq.net/http-api/queues/adding-jobs/custom-job-ids.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
