# Create an offer fulfillment

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


This API notifies that a user has accepted an offer, logs an accepted event immediately for reporting, and triggers a backend processing depending on the offer's processing\_type. You can call this API when a user accepts an offer (e.g., the user clicked Accept Offer or a similar confirmation). This API will record an accepted event as soon as the API is called and initiate the appropriate fulfillment mechanism according to `processing_type`:

-   `billing_update`: Initiates subscription or billing record updates (e.g., applying a discount or changing a plan) asynchronously.
-   `checkout`: Returns a `hosted_page` object in the response, which contains a URL to render the hosted checkout flow.
-   `url_redirect`: Returns a redirect\_url. You are responsible for managing fulfillment on your end and must call the Update Offer Fulfillment API to report either completion or failure.
-   `webhook`: Sends a webhook, and you must also manage fulfillment on your end. Be sure to call the Update Offer Fulfillment API to report completion or failure.
-   `email`: Sends an email containing the offer details as configured. You are responsible for handling fulfillment on your side and must call the Update Offer Fulfillment API to report completion or failure. You can poll the Retrieve Offer Fulfillment endpoint for final status on `billing_update` and `checkout flows`. Upon actual fulfillment completion, the system logs a `fulfilled` event and sends notifications (webhook, Slack, email, Segment) as configured.

## Sample Request

#### cURL

```bash
curl  https://{site}.grow.chargebee.com/api/v2/offer_fulfillments \
     -u {site_api_key}:\
     --header 'Content-Type: application/json;charset=UTF-8' \
     --data '{
     "personalized_offer_id": "6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
     "option_id": "912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8"
}'
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = OfferFulfillment.OfferFulfillments()
		.PersonalizedOfferId("6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8")
		.OptionId("912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8")
		.Request();

OfferFulfillment offerFulfillment = result.OfferFulfillment;
HostedPage hostedPage = result.HostedPage;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    offerfulfillmentAction "github.com/chargebee/chargebee-go/v3/actions/offerfulfillment"
    "github.com/chargebee/chargebee-go/v3/models/offerfulfillment"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := offerfulfillmentAction.OfferFulfillments(&offerfulfillment.OfferFulfillmentsRequestParams{
        PersonalizedOfferId : "6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
        OptionId : "912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        OfferFulfillment := res.OfferFulfillment
        HostedPage := res.HostedPage
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.OfferFulfillmentOfferFulfillmentsRequest{
    PersonalizedOfferId : "6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
    OptionId : "912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8",
}
  res, err := client.OfferFulfillment.OfferFulfillments(req)
      if err != nil {
        fmt.Println(err)
    } else {
        OfferFulfillment := res.OfferFulfillment
        HostedPage := res.HostedPage
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = OfferFulfillment.offerFulfillments()
            .personalizedOfferId("6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8")
            .optionId("912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8")
            .request();

        OfferFulfillment offerFulfillment = result.offerFulfillment();
        HostedPage hostedPage = result.hostedPage();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.hostedPage.HostedPage;
import com.chargebee.v4.models.offerFulfillment.OfferFulfillment;
import com.chargebee.v4.models.offerFulfillment.params.OfferFulfillmentsParams;
import com.chargebee.v4.models.offerFulfillment.responses.OfferFulfillmentsResponse;

public class OfferFulfillments {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        OfferFulfillmentsParams params = OfferFulfillmentsParams.builder()
            .personalizedOfferId("6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8")
            .optionId("912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8")
            .build();

        OfferFulfillmentsResponse response = client.offerFulfillments().offerFulfillments(params);

        OfferFulfillment offerFulfillment = response.getOfferFulfillment();
        HostedPage hostedPage = response.getHostedPage();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.offerFulfillment.offerFulfillments({
        personalized_offer_id: "6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
        option_id: "912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8"
    });

    console.log(result);
    const offerFulfillment = result.offer_fulfillment;
    const hostedPage = result.hosted_page;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->offerFulfillment()->offerFulfillments([
    "personalized_offer_id" => "6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
    "option_id" => "912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8"
]);
$offerFulfillment = $result->offer_fulfillment;
$hostedPage = $result->hosted_page;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.OfferFulfillment.offer_fulfillments(
    cb_client.OfferFulfillment.OfferFulfillmentsParams(
        personalized_offer_id="6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
        option_id="912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8"
    )
)
offer_fulfillment = response.offer_fulfillment
hosted_page = response.hosted_page
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::OfferFulfillment.offer_fulfillments({
  :personalized_offer_id => "6Y2g7VklOw_904e543f-39da-451c-9a2c-4583284367e8",
  :option_id => "912aaab5-1336-4db2-9dba-18a452ba939c_904e543f-39da-451c-9a2c-4583284367e8"
})

offer_fulfillment = result.offer_fulfillment
hosted_page = result.hosted_page
```

## Sample Response

```json
{
  "offer_fulfillment": {
    "personalized_offer_id": "a52ge40b",
    "option_id": "b3b4741d",
    "processing_type": "checkout",
    "status": "in_progress"
  },
  "hosted_page": {
    "created_at": 1517464663,
    "embed": false,
    "expires_at": 1517468263,
    "id": "__one_time_checkout___test__cdqM9MLUubELMycut0Cr9sHq8gOTKEZSdcu",
    "resource_version": 1517444863979,
    "state": "created",
    "type": "checkout_one_time",
    "updated_at": 1517444863,
    "url": "https://yourapp.chargebee.com/pages/v4/__one_time_checkout___test__cdqM9MLUubELMycut0Cr9sHq8gOTKEZSdcu/",
    "object": "hosted_page"
  }
}
```

## URL Format

**POST** https://[site].grow.chargebee.com/api/v2/offer_fulfillments

## Input Parameters

- `personalized_offer_id` (required, string, max chars=50)
  ID of the personalized offer that was accepted.

- `option_id` (required, string, max chars=50)
  ID of the Offer Option that the user accepted.

## Returns

- `offer_fulfillment` (Offer fulfillment object)
  Represents the fulfillment created for the offer.

- `hosted_page` (Hosted page object)
  Represents the hosted page created for the offer. This is returned only if the selected offer option's `processing_type` is checkout.
