> For the complete documentation index, see [llms.txt](https://docs.shoffi.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shoffi.app/the-shoffi-api/create-new-affiliate.md).

# Create New Affiliate

## Create a new affiliate and get its affiliate link

<mark style="color:green;">`POST`</mark> `https://platform.shoffi.app/API/affiliate/create`

#### Request Body

| Name                                               | Type    | Description                                                     |
| -------------------------------------------------- | ------- | --------------------------------------------------------------- |
| apiKey<mark style="color:red;">\*</mark>           | String  | Your Shoffi app API Key                                         |
| appId<mark style="color:red;">\*</mark>            | Integer | Your app ID                                                     |
| affiliateDetails<mark style="color:red;">\*</mark> | Object  | Affiliate account details                                       |
| groupId                                            | Integer | Affiliate group ID. If sent, Shoffi applies the group terms.    |
| affiliateTerms                                     | Object  | Affiliate contract terms. Used only when `groupId` is not sent. |

{% hint style="info" %}
Shoffi applies terms in this order:

1. `groupId`
2. `affiliateTerms`
3. Your app default group

If you send both `groupId` and `affiliateTerms`, `groupId` takes priority.
{% endhint %}

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "affiliateDetails": {
        "email": "tobias@lutke.com",
        "firstName": "Tobias",
        "lastName": "Lütke",
        "nickName": "tobi"
    },
    "affiliateTerms": {
        "revenueShare": 30,
        "cpi": 10,
        "limitPeriod": 24,
        "minWithdrawal": 50,
        "recurringChargeOnly": true,
        "isNetAmount": false
    },
    "affiliateLink": "https://platform.shoffi.app/r/rl_xxxxxxxx"
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "status": 400,
    "message": "Error details"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Please Note!**\
If the email you send in the POST request is already associated with an affiliate account in Shoffi, we will not create a new account.\
We will update the existing one with a new connection to your app with the group terms or affiliate terms you sent. You will still get a "200" response with the relevant data.
{% endhint %}

### Example request with custom terms

```bash
curl -X POST \
  https://platform.shoffi.app/API/affiliate/create \
  -H 'Content-Type: application/json' \
  -d '{
    "apiKey": "YourKey",
    "appId": 00000000,
    "affiliateDetails": {
        "email": "tobias@lutke.com",
        "firstName": "Tobias",
        "lastName": "Lütke",
        "nickName": "tobi"
    },
    "affiliateTerms": {
        "revenueShare": 30,
        "cpi": 10,
        "limitPeriod": 24,
        "minWithdrawal": 50,
        "recurringChargeOnly": true,
        "isNetAmount": false
    }
}'
```

### Example request with group terms

```bash
curl -X POST \
  https://platform.shoffi.app/API/affiliate/create \
  -H 'Content-Type: application/json' \
  -d '{
    "apiKey": "YourKey",
    "appId": 00000000,
    "affiliateDetails": {
        "email": "tobias@lutke.com",
        "firstName": "Tobias",
        "lastName": "Lütke",
        "nickName": "tobi"
    },
    "groupId": 12345
}'
```

## Parameter breakdown

### affiliateDetails

* `email:`\
  The new affiliate email address
* `firstName:`\
  The new affiliate first name
* `lastName:`\
  The new affiliate last name
* `nickName:`\
  The new affiliate nickname

### groupId

* `groupId:`\
  The ID of the affiliate group to assign to the affiliate. When this value is sent, Shoffi uses the group's terms.

You can find the group ID under `Groups` → click the group name → `Group ID` field.

### affiliateTerms

* `revenueShare:`\
  The percentage you are willing to pay the affiliate for every transaction made by a store they referred. You can read more about [the affiliate commission](/general/the-affiliate-commission.md).
* `cpi:`\
  Cost per install. The amount the affiliate will be rewarded for each successful app install. You can set the amount to `0` if you do not want to pay per install.
* `limitPeriod:`\
  The period in which the affiliate will earn commissions from transactions made by the referred store, in months. If not limited, the affiliate will earn commissions as long as the referral is active.
* `minWithdrawal:`\
  The minimum amount an affiliate must earn before they can request a withdrawal. This amount is in USD.
* `recurringChargeOnly:`\
  Apply affiliate earnings from recurring charges only, excluding one-time fees charged by the app.
* `isNetAmount:`\
  Calculate revenue share from the net amount. Default is `false`.

## Response example

```json
200 OK
Content-Type: application/json
```

<pre class="language-json"><code class="lang-json"><strong>{
</strong>    "affiliateDetails": {
        "email": "tobias@lutke.com",
        "firstName": "Tobias",
        "lastName": "Lütke",
        "nickName": "tobi"
    },
    "affiliateTerms": {
        "revenueShare": 30,
        "cpi": 10,
        "limitPeriod": 24,
        "minWithdrawal": 50,
        "recurringChargeOnly": true,
        "isNetAmount": false
    },
    "affiliateLink": "https://platform.shoffi.app/r/rl_xxxxxxxx"
}
</code></pre>
