# Document-wide id

**URL:** <https://discuss.jsonapi.org/t/document-wide-id/597>\
**Category:** Uncategorized\
**Created:** [July 20, 2016, 6:34pm UTC](https://discuss.jsonapi.org/t/document-wide-id/597 "2016-07-20T18:34:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![espadrine](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/espadrine/32/303_2.png) [@espadrine](https://discuss.jsonapi.org/u/espadrine)\
**Post date:** [July 20, 2016, 6:34pm UTC](https://discuss.jsonapi.org/t/document-wide-id/597/1 "2016-07-20T18:34:58Z")

</div>

In a document, you may want to create a resource object that doesn’t correspond to a database object, and therefore, that doesn’t have a unique id from which you can recover that data.

However, [the spec](http://jsonapi.org/format/#document-resource-object-identification) states:

> Within a given API, each resource object’s type and id pair MUST identify a single, unique resource.

Does that imply that we should have the ability to retrieve that resource with that id?

If we want to have document-wide ids (which therefore might have a new id if the request was to be repeated), is the current solution to generate a UUIDv4 for each of those ids?

Could we standardize a way to say, “this id is document-wide, not API-wide”, to avoid having huge ids everywhere? For instance, if the id starts with an underscore, it is document-wide, otherwise it is API-wide. It doesn’t functionally break backwards compatibility: an existing id starting with `_` that was assumed to be API-wide in v1.0 becomes a document-wide id which incidentally is the same across requests.

---

<div class="post-metadata">

**Author:** ![jlangley](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jlangley](https://discuss.jsonapi.org/u/jlangley)\
**Post date:** [July 22, 2016, 10:08pm UTC](https://discuss.jsonapi.org/t/document-wide-id/597/2 "2016-07-22T22:08:28Z")

</div>

> [@espadrine](#):
>
> Does that imply that we should have the ability to retrieve that resource with that id?

It might _imply_ it, but I don’t believe it is _required_. JSON API resources are accessed via URLs, not via `type` + `id` keys (though usually there will be a strong correlation between the two).

Given this, it is a bit surprising that the resource identifier objects are not allowed to contain a `related` link that would enable you to retrieve the relevant resource object.

---

<div class="post-metadata">

**Author:** ![ethanresnick](https://avatars.discourse-cdn.com/v4/letter/e/45deac/32.png) [@ethanresnick](https://discuss.jsonapi.org/u/ethanresnick)\
**Post date:** [September 20, 2016, 1:24am UTC](https://discuss.jsonapi.org/t/document-wide-id/597/3 "2016-09-20T01:24:34Z")

</div>

As @jlangey said, there’s no requirement that any given resource be retrievable.

For generating the required id, if UUIDs are too long, you could also use a simple prefixing strategy, like `"id": "documentXXX-1"` and `"documentXXX-2"`
