---
title: "Using a webhook to automatically seed new portfolios with cash"
slug: "using-a-webhook-to-automatically-seed-new-portfolios-with-cash"
updated: 2025-04-17T11:37:56Z
published: 2025-04-17T11:37:56Z
canonical: "support.lusid.com/using-a-webhook-to-automatically-seed-new-portfolios-with-cash"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.lusid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using a webhook to automatically seed new portfolios with cash

In this tutorial we'll see how to use the [Notification REST API](https://www.lusid.com/docs/api/notification/intro) to create a LUSID webhook notification.

Let's imagine we want to automatically seed all new portfolios we create with some cash. To do this, we need to subscribe to the portfolio created event that LUSID emits every time a transaction portfolio is created and attach a webhook notification to post to the LUSID [UpsertTransactions](https://www.lusid.com/docs/api/lusid/endpoints/transaction-portfolios/UpsertTransactions/) API.

> **Note**: To complete this tutorial, you must have suitable access control permissions. This can most easily be achieved by assigning your LUSID user the built-in `lusid-administrator` role, which should already be the case if you are the domain owner. If you are informed you do not have a license to perform a certain operation, [contact support](https://www.finbourne.com/contact).

## Step 1: Subscribing to the portfolio created event

Before we can create a notification, we need to subscribe to the portfolio created event using the [CreateSubscription](https://www.lusid.com/docs/api/notification/endpoints/subscriptions/CreateSubscription/) API, passing in:

- An API access token as a Bearer token in the Authorization HTTP header. [See how to obtain a token](/v1/docs/how-do-i-obtain-and-use-a-short-lived-api-access-token-from-okta).
- `PortfolioEvent` as our `scope` and `AnyPortfolioCreated` as our `code` for the subscription.
- A `displayName` and `description` for the subscription.
- The `eventType` to subscribe to. In our case, we want to subscribe to the `PortfolioCreated` event type [every time it occurs](/v1/docs/using-lusid-filtering-syntax-to-subscribe-to-events-conditionally), so we leave the `filter` parameter empty.

```json
curl -X POST "https://<your-domain>.lusid.com/notification/api/subscriptions" 
  -H "Authorization: Bearer <your-API-access-token>" 
  -H "Content-Type: application/json" 
  -d '{
  "id": {
    "scope": "PortfolioEvent",
    "code": "AnyPortfolioCreated"
  },
  "displayName": "Any Portfolio Created",
  "description": "Subscribes to all PortfolioCreated events",
  "status": "Active",
  "matchingPattern": {
    "eventType": "PortfolioCreated",
    "filter": ""
  }
}'
```

The response is as follows:

```json
{
  "id": {
    "scope": "PortfolioEvent",
    "code": "AnyPortfolioCreated"
  },
  "displayName": "Any Portfolio Created",
  "description": "Subscribes to all PortfolioCreated events",
  "status": "Active",
  "matchingPattern": {
    "eventType": "PortfolioCreated",
    "filter": ""
  },
  "createdAt": "2023-02-15T10:13:36.8915431+00:00",
  "userIdCreated": "00uji4twb7X42sdse2p7",
  "modifiedAt": "2023-02-15T10:13:36.8915431+00:00",
  "userIdModified": "00uji4twb7X42sdse2p7"
  "useAsAuth":"00uji4twb7X42sdse2p7"
  "href": "https://<your-domain>.lusid.com/notification/api/subscriptions/PortfolioEvent/AnyPortfolioCreated"
}
```

You can sign in to the LUSID web app to view the new subscription on the **Subscriptions** dashboard, available from the top left menu under **Notifications Management**: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/image(747).png)

## Step 2: Attaching a webhook notification to the subscription

Now that we have subscribed to the portfolio created event, we can create a webhook notification for the subscription to post to the `UpsertTransactions` API each time the event occurs.

In this tutorial, we want to seed all newly-created portfolios with 10,000,000 USD and 7,500,000 GBP cash. To do so, we call the [CreateNotification](https://www.lusid.com/docs/api/notification/endpoints/notifications/CreateNotification) API, passing in our API access token and:

- The `scope` and `code` of the subscription to attach the notification to. In our case, `PortfolioEvent` and `AnyPortfolioCreated`.
- A `displayName` and unique `notificationId` to refer to the notification once created.
- A `notificationType` containing:
  - A `Type` of `Webhook`.
  - The `HttpMethod` for the type of request we want to make to the LUSID REST API. In our case, we want to make a `POST` request.
  - The `Url` we want to make a POST request to.
  - A `ContentType` of `Json`.
  - A `Content` object which contains the expected payload for the [UpsertTransactions](https://www.lusid.com/docs/api/lusid/endpoints/transaction-portfolios/UpsertTransactions/) API.

```json
curl -X POST "https://<your-domain>.lusid.com/notification/api/subscriptions/PortfolioEvent/AnyPortfolioCreated/notifications" 
  -H "Authorization: Bearer <your-API-access-token>" 
  -H "Content-Type: application/json" 
  -d '{
  "notificationId": "PortfolioCreatedWebhook",
  "displayName": "Seed Portfolio With Cash", 
  "description": "Any portfolio created seed with cash",
  "notificationType": {
    "Type":  "Webhook",
    "HttpMethod": "Post",
    "Url": "/api/api/transactionportfolios/{{Body.portfolioScope}}/{{Body.portfolioCode}}/transactions",
    "AuthenticationType": "Lusid",
    "ContentType": "Json",
    "Content": [      { 
        "transactionId": "SeedFundsTransactionUSD",
        "type": "FundsIn",
        "instrumentIdentifiers": {"Instrument/default/Currency": "USD"},
        "transactionDate": "{{Header.timestamp}}",
        "settlementDate": "{{Header.timestamp}}",
        "units": 10000000,
        "transactionPrice": {
          "price": 1,
          "type": "Price"
        },
        "totalConsideration": {
          "amount": 10000000,
          "currency": "USD"
        },
        "transactionCurrency": "USD",
      },
      { 
        "transactionId": "SeedFundsTransactionGBP",
        "type": "FundsIn",
        "instrumentIdentifiers": {"Instrument/default/Currency": "GBP"},
        "transactionDate": "{{Header.timestamp}}",
        "settlementDate": "{{Header.timestamp}}",
        "units": 7500000,
        "transactionPrice": {
          "price": 1,
          "type": "Price"
        },
        "totalConsideration": {
          "amount": 7500000,
          "currency": "GBP"
        },
        "transactionCurrency": "GBP",
      }
     ]
}'
```

## Step 3: Checking that a new portfolio is automatically seeded with cash

Now that we have created a webhook notification, we can [create a new transaction portfolio](/v1/docs/how-do-i-create-a-transaction-portfolio) to check that new portfolios are now automatically seeded with cash. Let's create a new portfolio via the **Portfolios** dashboard in the [LUSID web app](https://www.lusid.com/app) with scope `FBNUniversity` and code `NewTradingPortfolio`​​​​​: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/image(748).png)

Once the new portfolio has been created, navigate from the top left menu in the web app to **Dashboard > Transactions** and select the new portfolio. We can see that the webhook notification has successfully seeded our new portfolio with the USD and GBP cash amounts specified earlier: ![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/image(749).png)
