Memokit
API Reference

Relations API

Create and manage relationships between entities

Relations API

The Relations API allows you to create and manage relationships between entities, building a knowledge graph.

Relation Object

FieldTypeDescription
idstringUnique relation identifier
sourceIdstringSource entity ID
targetIdstringTarget entity ID
typestringRelationship type
metadataobjectCustom metadata
createdAtstringISO 8601 timestamp

Relationship Types

Common relationship types (you can define your own):

TypeDescriptionExample
WORKS_FOREmployment relationshipJohn WORKS_FOR Acme Corp
KNOWSPersonal connectionJohn KNOWS Jane
LOCATED_INGeographic locationAcme Corp LOCATED_IN San Francisco
PART_OFMembership/hierarchyEngineering PART_OF Acme Corp
CREATEDAuthorship/creationJohn CREATED Project X
RELATED_TOGeneral relationshipTopic A RELATED_TO Topic B

Create Relation

Create a new relationship between two entities.

POST /v1/relations

Request Body

FieldTypeRequiredDescription
sourceIdstringYesSource entity ID
targetIdstringYesTarget entity ID
typestringYesRelationship type
metadataobjectNoCustom metadata

Example Request

curl -X POST https://api.memokit.dev/v1/relations \
  -H "Authorization: Bearer mk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "sourceId": "ent_john123",
    "targetId": "ent_acme456",
    "type": "WORKS_FOR",
    "metadata": {
      "startDate": "2023-01-15",
      "role": "Senior Engineer"
    }
  }'

Response

{
  "id": "rel_abc123",
  "sourceId": "ent_john123",
  "targetId": "ent_acme456",
  "type": "WORKS_FOR",
  "metadata": {
    "startDate": "2023-01-15",
    "role": "Senior Engineer"
  },
  "createdAt": "2024-01-15T10:30:00Z"
}

List Relations

Retrieve a paginated list of relations.

GET /v1/relations

Query Parameters

ParameterTypeRequiredDescription
sourceIdstringNoFilter by source entity
targetIdstringNoFilter by target entity
typestringNoFilter by relationship type
pagenumberNoPage number (default: 1)
limitnumberNoItems per page (default: 20, max: 100)

Example Request

curl -X GET "https://api.memokit.dev/v1/relations?sourceId=ent_john123" \
  -H "Authorization: Bearer mk_your_api_key"

Response

{
  "items": [
    {
      "id": "rel_abc123",
      "sourceId": "ent_john123",
      "targetId": "ent_acme456",
      "type": "WORKS_FOR",
      "source": {
        "id": "ent_john123",
        "name": "John Smith",
        "type": "PERSON"
      },
      "target": {
        "id": "ent_acme456",
        "name": "Acme Corp",
        "type": "ORGANIZATION"
      },
      "createdAt": "2024-01-15T10:30:00Z"
    },
    {
      "id": "rel_def456",
      "sourceId": "ent_john123",
      "targetId": "ent_jane789",
      "type": "KNOWS",
      "source": {
        "id": "ent_john123",
        "name": "John Smith",
        "type": "PERSON"
      },
      "target": {
        "id": "ent_jane789",
        "name": "Jane Doe",
        "type": "PERSON"
      },
      "createdAt": "2024-01-14T15:20:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 2,
    "totalPages": 1
  }
}

Get Relation

Retrieve a specific relation by ID.

GET /v1/relations/:id

Path Parameters

ParameterTypeDescription
idstringRelation ID

Example Request

curl -X GET https://api.memokit.dev/v1/relations/rel_abc123 \
  -H "Authorization: Bearer mk_your_api_key"

Response

{
  "id": "rel_abc123",
  "sourceId": "ent_john123",
  "targetId": "ent_acme456",
  "type": "WORKS_FOR",
  "source": {
    "id": "ent_john123",
    "name": "John Smith",
    "type": "PERSON"
  },
  "target": {
    "id": "ent_acme456",
    "name": "Acme Corp",
    "type": "ORGANIZATION"
  },
  "metadata": {
    "startDate": "2023-01-15",
    "role": "Senior Engineer"
  },
  "createdAt": "2024-01-15T10:30:00Z"
}

Delete Relation

Delete a relation permanently.

DELETE /v1/relations/:id

Path Parameters

ParameterTypeDescription
idstringRelation ID

Example Request

curl -X DELETE https://api.memokit.dev/v1/relations/rel_abc123 \
  -H "Authorization: Bearer mk_your_api_key"

Response

{
  "success": true,
  "id": "rel_abc123"
}

Error Codes

CodeDescription
RELATION_NOT_FOUNDThe specified relation does not exist
SOURCE_ENTITY_NOT_FOUNDThe source entity does not exist
TARGET_ENTITY_NOT_FOUNDThe target entity does not exist
INVALID_RELATION_TYPEThe relation type is not valid

On this page