> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.robaws.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Calculating through the API

### Simple example

To have a quotation calculated through the API, you have to create it as follows. Note that you can use real formulas in the quantityFormula fields.

```
POST https://app.robaws.com/api/v2/offers
Content-Type: application/json

{
  "calculated": true, //indicates that this is a calculated quotation (versus a simple quotation)
  "addressDistance": { //optionally pass the number of kilometres to the site
    "value": "10",
    "unit": "KM"
  },
  "lineItems": [
    {
      "quantityFormula": "DISTANCE_KM", //example: use the predefined DISTANCE_KM variable to take the number of kilometres as the quantity
      "calculationLineItems": [
        {
          "description": "Kilometers",
          "quantityFormula": "1",
          "price": 0.5
        }
      ]
    }
  ]
}
```

If all is well, you get a 201 CREATED response back containing, among other things:

```
 "calculationStatus": "PENDING"
```

The status "PENDING" indicates that the calculation has been requested and is queued. You can either poll (retrieve the quotation regularly) until the status is "DONE", or you can use a webhook to know that the calculation is finished (recommended).

### Webhook for calculationStatus

Register a webhook as follows to be notified when the calculation of a quotation is finished.

```
POST https://app.robaws.com/api/v2/webhook-endpoints
Content-Type: application/json

{
  "url": "https://webhooks.your-app.com/robaws/offer/recalculated",
  "events": ["offer.recalculated"]
}
```

The message we will send to your application through the webhook looks like this:
([Click here](https://support.robaws.com/en/article/webhooks-1wvslvy/) for more information about webhooks)

```
{
  "id": "08241443-0335-4f3d-94a2-d6da6c201545",
  "event": "offer.recalculated",
  "resource": "/offers/3409",
  "user": null,
  "timestamp": "2025-09-15T06:35:10.329Z",
  "data": {
    "id": "3409"
  }
}
```

If you then do a GET on the quotation in question, you can retrieve the totals and subtotals.

### Example with post numbers

If you want to work with predefined post numbers, that is possible too. The POST request then looks like this:

```
POST https://app.robaws.com/api/v2/offers
Content-Type: application/json

{
  "calculated": true, //indicates that this is a calculated quotation (versus a simple quotation)
  "addressDistance": { //optionally pass the number of kilometres to the site
    "value": "10",
    "unit": "KM"
  },
  "lineItems": [
    {
      "quantityFormula": "1",
      "chapter": "1.1" // this is where you pass the post number
    },
    {
      "quantityFormula": "1",
      "chapter": "1.2" // this is where you pass the post number
    }
  ],
  "actions": [
    {
      "action": "ASSIGN_POSTS" //assign posts from the library based on chapter
    },
    {
      "action": "UPDATE_PRICES", // make sure the prices are correct based on the latest prices from your item library
      "strategy": "UPDATE_COST_PRICE_AND_SALES_PRICE" //or UPDATE_COST_PRICE_KEEP_MARGIN	
    }
  ]
}
```