Skip to main content
POST
Batch or Transaction
curl --request POST \
  --url http://localhost:8080/fhir/ \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/fhir+json' \
  --data '
{
  "resourceType": "Bundle",
  "type": "document"
}
'
{
  "resourceType": "Bundle",
  "type": "document",
  "total": 123,
  "link": [
    {
      "relation": "<string>",
      "url": "<string>"
    }
  ],
  "entry": [
    {
      "fullUrl": "<string>",
      "resource": {
        "resourceType": "<string>",
        "id": "<string>",
        "meta": {
          "versionId": "<string>",
          "lastUpdated": "2023-11-07T05:31:56Z",
          "profile": [
            "<string>"
          ],
          "tag": [
            {
              "system": "<string>",
              "version": "<string>",
              "code": "<string>",
              "display": "<string>"
            }
          ],
          "security": [
            {
              "system": "<string>",
              "version": "<string>",
              "code": "<string>",
              "display": "<string>"
            }
          ]
        }
      },
      "request": {
        "method": "GET",
        "url": "<string>"
      },
      "response": {
        "status": "<string>",
        "location": "<string>",
        "etag": "<string>",
        "lastModified": "2023-11-07T05:31:56Z",
        "outcome": {
          "resourceType": "OperationOutcome",
          "issue": [
            {
              "severity": "fatal",
              "code": "invalid",
              "details": {
                "coding": [
                  {
                    "system": "<string>",
                    "version": "<string>",
                    "code": "<string>",
                    "display": "<string>"
                  }
                ],
                "text": "<string>"
              },
              "diagnostics": "<string>",
              "location": [
                "<string>"
              ]
            }
          ]
        }
      }
    }
  ]
}

Transaction

Execute multiple FHIR operations as a single atomic transaction. All operations succeed or all fail together.

Endpoint

POST /fhir

Request Body

The request body is a Bundle with type set to transaction:
{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "request": {
        "method": "POST",
        "url": "Patient"
      },
      "resource": {
        "resourceType": "Patient",
        "name": [{"family": "Doe", "given": ["John"]}]
      }
    },
    {
      "request": {
        "method": "PUT",
        "url": "Patient/123"
      },
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        "name": [{"family": "Doe", "given": ["Jane"]}]
      }
    },
    {
      "request": {
        "method": "DELETE",
        "url": "Observation/456"
      }
    },
    {
      "request": {
        "method": "GET",
        "url": "Patient/789"
      }
    }
  ]
}

Request Methods

Each entry in the transaction can use different HTTP methods:
  • POST - Create a new resource
  • PUT - Update a resource (must include full resource)
  • PATCH - Patch a resource
  • DELETE - Delete a resource
  • GET - Read a resource

Request URL

The url in each request can be:
  • Absolute: Patient/123 - References a specific resource
  • Relative: Patient - Creates a new resource of that type
  • Conditional: Patient?identifier=http://example.org/mrn|12345 - Conditional operation

Response

Success (200 OK)

Returns a Bundle with type set to transaction-response:
{
  "resourceType": "Bundle",
  "type": "transaction-response",
  "entry": [
    {
      "response": {
        "status": "201",
        "location": "Patient/abc123",
        "etag": "W/\"1\""
      },
      "resource": {
        "resourceType": "Patient",
        "id": "abc123",
        ...
      }
    },
    {
      "response": {
        "status": "200",
        "location": "Patient/123",
        "etag": "W/\"2\""
      },
      "resource": {
        "resourceType": "Patient",
        "id": "123",
        ...
      }
    },
    {
      "response": {
        "status": "204"
      }
    },
    {
      "response": {
        "status": "200",
        "location": "Patient/789",
        "etag": "W/\"1\""
      },
      "resource": {
        "resourceType": "Patient",
        "id": "789",
        ...
      }
    }
  ]
}

Error (400 Bad Request)

If any operation fails, the entire transaction is rolled back:
{
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "error",
      "code": "invalid",
      "details": {
        "text": "Transaction failed: Resource validation error in entry 2"
      }
    }
  ]
}

Response Status Codes

Each entry’s response includes a status code:
  • 200 OK - Successful read or update
  • 201 Created - Resource created
  • 204 No Content - Successful delete
  • 400 Bad Request - Invalid request (transaction fails)
  • 404 Not Found - Resource not found (transaction fails)
  • 409 Conflict - Version conflict (transaction fails)

Conditional Operations

You can use conditional URLs in transactions:
{
  "request": {
    "method": "PUT",
    "url": "Patient?identifier=http://example.org/mrn|12345"
  },
  "resource": {
    "resourceType": "Patient",
    "identifier": [
      {
        "system": "http://example.org/mrn",
        "value": "12345"
      }
    ],
    "name": [{"family": "Doe"}]
  }
}

Ordering

Operations in a transaction are processed in order. Later operations can reference resources created earlier:
{
  "entry": [
    {
      "request": {
        "method": "POST",
        "url": "Patient"
      },
      "resource": {
        "resourceType": "Patient",
        "id": "will-be-assigned"
      }
    },
    {
      "request": {
        "method": "POST",
        "url": "Observation"
      },
      "resource": {
        "resourceType": "Observation",
        "subject": {
          "reference": "Patient/will-be-assigned"
        }
      }
    }
  ]
}
The server resolves references to resources created in the same transaction.

Notes

  • All operations are atomic - either all succeed or all fail
  • Operations are processed sequentially
  • Resources created in the transaction can be referenced by later operations
  • The transaction response includes the results of all operations
  • Use transactions to ensure data consistency across multiple operations

Authorizations

Authorization
string
header
required

Bearer token authentication

Body

A container for a collection of resources

resourceType
enum<string>
required

Resource type

Available options:
Bundle
type
enum<string>
required

Indicates the purpose of this bundle

Available options:
document,
message,
transaction,
transaction-response,
batch,
batch-response,
history,
searchset,
collection
total
integer

If search, the total number of matches

Links related to this Bundle

entry
object[]

Entry in the bundle

Response

Batch or transaction response

A container for a collection of resources

resourceType
enum<string>
required

Resource type

Available options:
Bundle
type
enum<string>
required

Indicates the purpose of this bundle

Available options:
document,
message,
transaction,
transaction-response,
batch,
batch-response,
history,
searchset,
collection
total
integer

If search, the total number of matches

Links related to this Bundle

entry
object[]

Entry in the bundle