Relationships

Relationships

The Snapbooks API uses relationship fields to represent connections between resources. This allows you to include related data in your requests and understand how different resources are connected.

Resource Relationships

Resources can have different types of relationships:

  • One-to-one (e.g., document -> voucher)
  • One-to-many (e.g., client account -> documents)
  • Many-to-many (e.g., users -> client accounts)

You can include related resources in your response using the with query parameter:

GET /api/v2/documents/123?with=voucher,client_account

Relationship Structure

Relationships are represented in the response JSON as follows:

{
  "data": {
    "id": "123",
    "type": "documents",
    "attributes": {
      "name": "Invoice 2024-001"
    },
    "relationships": {
      "voucher": {
        "data": {
          "id": "456",
          "type": "vouchers"
        }
      },
      "client_account": {
        "data": {
          "id": "789",
          "type": "client_accounts"
        }
      }
    }
  },
  "included": [
    {
      "id": "456",
      "type": "vouchers",
      "attributes": {
        "number": "V2024-001"
      }
    },
    {
      "id": "789",
      "type": "client_accounts",
      "attributes": {
        "name": "ACME Inc"
      }
    }
  ]
}

Available Relationships

Each resource documentation page lists its available relationships in the “Relationships” section. These define which related resources can be included in requests using the with parameter.

Relaterte artikler