> Connect a Plandalf price to an object in your own system, such as a membership, and see when the two drift apart.

Source: https://plandalf.com/docs/api/links

API and webhooks

# Links

A link connects a Plandalf price to something in your system that the price grants, such as a MemberPress membership. Plandalf includes the link on every invoice line in [webhooks](https://plandalf.com/docs/api/webhooks), so your system knows what to grant. Send a `snapshot` of your object's billing terms and each link reports `drift`: the fields where your object and the Plandalf price disagree.

## Example

```bash
curl -X POST https://admin.plandalf.dev/api/v1/links \
  -H "Authorization: Bearer $PLANDALF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "price_id": 1,
    "system": "memberpress",
    "site": "members.example.com",
    "external_type": "membership",
    "external_id": "123",
    "external_name": "Gold membership",
    "external_url": "https://members.example.com/wp-admin/post.php?post=123",
    "snapshot": { "amount_cents": 4900, "currency": "usd", "interval": "month", "interval_count": 1 }
  }'
```

A new link returns `201`; the same price, system, site and object again updates it and returns `200`. When the membership changes on your side, call `POST /api/v1/links/refresh` with the same `system`, `site`, `external_type` and `external_id` and a new snapshot.

## Endpoints

### List links

GET `/api/v1/links`

Links in creation order, up to 500, filtered by any of `system`, `site`, `external_type`, `external_id` and `price_id`. Each link carries `drift`: the fields where your snapshot and the Plandalf price disagree.

#### Parameters

Name

In

Type

What it is

`system` optional

query

`string | null`

`site` optional

query

`string | null`

`external_type` optional

query

`string | null`

`external_id` optional

query

`string | null`

`price_id` optional

query

`integer | null`

```bash
curl https://admin.plandalf.dev/api/v1/links \
  -H "Authorization: Bearer $PLANDALF_API_KEY"
```

#### Response

```json
{
  "data": [
    {
      "id": 0,
      "system": "string",
      "site": "string",
      "external_type": "string",
      "external_id": "string",
      "external_name": "string",
      "external_url": "string",
      "role": "string",
      "price": {
        "id": 0,
        "lookup_key": "string",
        "name": "string",
        "product": {
          "id": 0,
          "name": "string",
          "lookup_key": "string"
        },
        "amount_cents": 0,
        "currency": "string",
        "recurring": {
          "interval": "string",
          "interval_count": 0
        },
        "trial_period_days": 0,
        "active": true
      },
      "snapshot": {
        "amount_cents": 0,
        "currency": "string",
        "interval": "string",
        "interval_count": 0,
        "trial_period_days": 0
      },
      "drift": [
        {
          "field": "string",
          "plandalf": null,
          "external": null
        }
      ],
      "drift_acknowledged": true,
      "updated_at": "string"
    }
  ]
}
```

#### Errors

Status

When

`401`

The API key or OAuth token is missing or invalid.

`422`

The request failed validation; `errors` lists the problems by field.

### Create or update a link

POST `/api/v1/links`

Connects a Plandalf price to an object in your system. Upserts by price, `system`, `site`, `external_type` and `external_id`; returns `201` for a new link and `200` for an update. Send a `snapshot` of your object's billing terms so Plandalf can report drift.

#### Body

Field

Type

What it is

`system`

`string`

`site`

`string`

`external_type`

`string`

`external_id`

`string`

`external_name` optional

`string | null`

`external_url` optional

`string | null`

`price_id`

`integer`

`role` optional

`"grants"`

`snapshot` optional

`object`

```bash
curl -X POST https://admin.plandalf.dev/api/v1/links \
  -H "Authorization: Bearer $PLANDALF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"system":"string","site":"string","external_type":"string","external_id":"string","external_name":"string","external_url":"string","price_id":0,"role":"grants","snapshot":{"amount_cents":0,"currency":"string","interval":"day","interval_count":0,"trial_period_days":0}}'
```

#### Response

```json
{
  "id": 0,
  "system": "string",
  "site": "string",
  "external_type": "string",
  "external_id": "string",
  "external_name": "string",
  "external_url": "string",
  "role": "string",
  "price": {
    "id": 0,
    "lookup_key": "string",
    "name": "string",
    "product": {
      "id": 0,
      "name": "string",
      "lookup_key": "string"
    },
    "amount_cents": 0,
    "currency": "string",
    "recurring": {
      "interval": "string",
      "interval_count": 0
    },
    "trial_period_days": 0,
    "active": true
  },
  "snapshot": {
    "amount_cents": 0,
    "currency": "string",
    "interval": "string",
    "interval_count": 0,
    "trial_period_days": 0
  },
  "drift": [
    {
      "field": "string",
      "plandalf": null,
      "external": null
    }
  ],
  "drift_acknowledged": true,
  "updated_at": "string"
}
```

#### Errors

Status

When

`401`

The API key or OAuth token is missing or invalid.

`403`

The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request.

`422`

The request failed validation; `errors` lists the problems by field.

### Refresh links to one of your objects

POST `/api/v1/links/refresh`

Call it when your object changes (for example the membership was edited): updates the name, URL and snapshot on every link to it, so drift is current. Returns the updated links.

#### Body

Field

Type

What it is

`system`

`string`

`site`

`string`

`external_type`

`string`

`external_id`

`string`

`external_name` optional

`string | null`

`external_url` optional

`string | null`

`snapshot` optional

`object`

```bash
curl -X POST https://admin.plandalf.dev/api/v1/links/refresh \
  -H "Authorization: Bearer $PLANDALF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"system":"string","site":"string","external_type":"string","external_id":"string","external_name":"string","external_url":"string","snapshot":{"amount_cents":0,"currency":"string","interval":"day","interval_count":0,"trial_period_days":0}}'
```

#### Response

```json
{
  "data": [
    {
      "id": 0,
      "system": "string",
      "site": "string",
      "external_type": "string",
      "external_id": "string",
      "external_name": "string",
      "external_url": "string",
      "role": "string",
      "price": {
        "id": 0,
        "lookup_key": "string",
        "name": "string",
        "product": {
          "id": 0,
          "name": "string",
          "lookup_key": "string"
        },
        "amount_cents": 0,
        "currency": "string",
        "recurring": {
          "interval": "string",
          "interval_count": 0
        },
        "trial_period_days": 0,
        "active": true
      },
      "snapshot": {
        "amount_cents": 0,
        "currency": "string",
        "interval": "string",
        "interval_count": 0,
        "trial_period_days": 0
      },
      "drift": [
        {
          "field": "string",
          "plandalf": null,
          "external": null
        }
      ],
      "drift_acknowledged": true,
      "updated_at": "string"
    }
  ]
}
```

#### Errors

Status

When

`401`

The API key or OAuth token is missing or invalid.

`403`

The credentials are valid but not allowed here: a site-connection token outside its scope, or the organization can't make this request.

`422`

The request failed validation; `errors` lists the problems by field.

### Acknowledge a link's drift

POST `/api/v1/links/{link}/acknowledge`

Keeps the current difference on purpose (for example a promotional Plandalf price), so `drift_acknowledged` is true until the drift changes again.

#### Parameters

Name

In

Type

What it is

`link`

path

`integer`

```bash
curl -X POST https://admin.plandalf.dev/api/v1/links/:link/acknowledge \
  -H "Authorization: Bearer $PLANDALF_API_KEY"
```

#### Response

```json
{
  "id": 0,
  "system": "string",
  "site": "string",
  "external_type": "string",
  "external_id": "string",
  "external_name": "string",
  "external_url": "string",
  "role": "string",
  "price": {
    "id": 0,
    "lookup_key": "string",
    "name": "string",
    "product": {
      "id": 0,
      "name": "string",
      "lookup_key": "string"
    },
    "amount_cents": 0,
    "currency": "string",
    "recurring": {
      "interval": "string",
      "interval_count": 0
    },
    "trial_period_days": 0,
    "active": true
  },
  "snapshot": {
    "amount_cents": 0,
    "currency": "string",
    "interval": "string",
    "interval_count": 0,
    "trial_period_days": 0
  },
  "drift": [
    {
      "field": "string",
      "plandalf": null,
      "external": null
    }
  ],
  "drift_acknowledged": true,
  "updated_at": "string"
}
```

#### Errors

Status

When

`401`

The API key or OAuth token is missing or invalid.

### Delete a link

DELETE `/api/v1/links/{link}`

Removes the link between the price and your object. The price itself is unchanged.

#### Parameters

Name

In

Type

What it is

`link`

path

`integer`

```bash
curl -X DELETE https://admin.plandalf.dev/api/v1/links/:link \
  -H "Authorization: Bearer $PLANDALF_API_KEY"
```

#### Response

```json
{
  "id": 0,
  "deleted": true
}
```

#### Errors

Status

When

`401`

The API key or OAuth token is missing or invalid.

Something wrong or missing? Email [hello@plandalf.com](mailto:hello@plandalf.com).
