## Accessing History in the Medplum App  
To access a resource's history in the [Medplum App](https://app.medplum.com/), follow these steps:

- Navigate to the resources page at [http://app.medplum.com/:resourceType](http://app.medplum.com/:resourceType).
- Select your desired resource. This will bring you to that resource's page.
- Select the `History` tab from the array of tabs at the top of the page.

Alternatively, you can navigate directly to this page at [https://app.medplum.com/:resourceType/:id/history](https://app.medplum.com/:resourceType/:id/history).

The `History` tab shows every version of the selected resource, representing each time the resource was changed. Along with this, it will show when the change was made, as well as the user who made the update.

Selecting a version will bring you to the `Diff` page, which displays the differences between that version and the version directly previous to it.

You can also view the raw JSON of the selected version by clicking on the `Raw` tab.

## Accessing the /_history Endpoint  
The history of a resource can also be viewed by accessing the `/_history` endpoint in the FHIR API. This endpoint allows you to retrieve the history of an individual resource, a resource type, or all resources in your system.

To access the `/_history` endpoint, make a GET request to the URL of the desired resource or resource type.

The Medplum SDK also provides the `readHistory` helper function to access the `/_history` endpoint.

- Typescript  
    ```ts  
    await medplum.readHistory('Patient', 'homer-simpson');  
    ```  
- CLI  
    ```bash  
    medplum get 'Patient/homer-simpson/_history'  
    ```  
- cURL  
    ```bash  
    curl 'https://api.medplum.com/fhir/R4/Patient/homer-simpson/_history' \
      -H 'authorization: Bearer $ACCESS_TOKEN' \
      -H 'content-type: application/fhir+json' \
    ```

These requests return a `Bundle` resource with the different versions stored as an array of resources in the `entry` field.

## Resource Creation Time  
There is currently no support for directly accessing the time and date that a resource was initially created. To do this use the `/_history` endpoint to retrieve all versions and view the `lastUpdated` field of the original version. Note that the GraphQL endpoint does not currently have a spec for the history API.

## Reverting Changes to a Resource  
While there is no direct method to revert changes made to a resource, it can be easily done using the `readHistory` and `readVersion` helper functions provided by Medplum.

The `readHistory` function is used to get the entire history of the resource. You can then choose the version and use `readVersion` to return the complete details of that version of the resource. The current resource can then be updated to the historic details.

Example: Revert resource to a previous version

```ts
// Read the history, returning a bundle of history entries

const history = await medplum.readHistory('Patient', 'homer-simpson');

// Implement your own logic to get the historic version of the resource you want.
// You will need the versionId to use the readVersion function.

const versionId = getVersionId(history);

// readVersion will return the historic Patient resource

const version = await medplum.readVersion('Patient', 'homer-simpson', versionId);

// Pass the historic version to updateResource to revert to that version
await medplum.updateResource(version);
```

This method does not actually revert the resources to the previous version, but it creates a new entry in the resource's history with all of the same details as the historic version.

- [Accessing History in the Medplum App](/content/docs/fhir-datastore/resource-history#accessing-history-in-the-medplum-app/index.html)
- [Accessing the /_history Endpoint](/content/docs/fhir-datastore/resource-history#accessing-the-_history-endpoint/index.html)
- [Reverting Changes to a Resource](/content/docs/fhir-datastore/resource-history#reverting-changes-to-a-resource/index.html)
