# Create referrals

> You can create referral codes for your campaign by importing them into Talon.One or building a rule with an effect consisting of creating referral codes when conditions are met.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

You can also create referral codes
[programmatically](/management-api#tag/Referrals).

## Create a referral code

You can create referrals [as an effect](/docs/product/rules/effects/use-effects.md#create-a-referral-code)
in your rules.

Learn more about it in [our Developer
Docs](/docs/dev/integration-api/api-effects/#referrals).

## Import referral codes

You can import referrals from any marketing tool to use them in Talon.One.

1. Click **Referrals** on the left-side menu of your campaign.
1. In the top-right corner of the page, click **Import Referrals**.
1. Click <Import className="icon" /> **Upload a CSV file**.
1. Select a CSV file of referral codes from your computer. Ensure the file does not
   contain any duplicate records.

   :::tip
- To see the required structure of the CSV file, click **Download a sample file**.
- To upload codes with custom attributes,
  see [Importing codes with custom attributes](#import-codes-with-custom-attributes).
:::

1. Click **Import Referrals**.

To import more data, click <Import className="icon" /> **Import Referrals**.

:::important
When you import a CSV file with referrals, a [customer profile](/docs/dev/concepts/entities/customer-profiles.md) is **not** automatically created for each `advocateprofileintegrationid` column value. Use
the [Update customer profile](/integration-api#tag/Customer-profiles/operation/updateCustomerProfileV2)
endpoint or the [Update multiple customer profiles](/integration-api#tag/Customer-profiles/operation/updateCustomerProfilesV2)
endpoint to create the customer profiles.
:::

:::note
If no limit is set for an imported referral, the default is single-use.
:::

### Import coupons with custom attributes {#import-codes-with-custom-attributes}

:::important
Before you begin, we recommend you:
- Familiarize yourself with the
  JSON [syntax](https://www.w3schools.com/js/js_json_syntax.asp)
  and [data types](https://www.w3schools.com/js/js_json_datatypes.asp).
- Ensure you know each
  attribute's API name, type, and value.
- Ensure that [location attribute data](/docs/dev/tutorials/use-geolocation) is managed by a technical user.
:::

To import coupons with [custom attributes](/docs/product/account/dev-tools/manage-attributes):

1. In your CSV file, add a column called `attributes`.
1. Insert a **JSON object** listing the key-value pairs in the `attributes` column.

   The pattern is: `{"api_name_1": my_integer_value, "api_name_2": "my_string_value", ...}`.

   :::tip Troubleshooting

   If you use a text editor to edit your CSV file, you may encounter `Import Error: Read
   CSV error parse error on line 2` when you upload the file.
   To solve it, **duplicate all double-quotes**.

   The pattern is: `"{""api_name_1"": my_integer_value, ""api_name_2"": ""my_string_value"", ...}"`.
   :::

The format of the attribute value depends on the attribute type, as shown in the following table:

{

  <colgroup>
    <col span="1" style={{width:20+"%"}}/>
    <col span="1" style={{width:80+"%"}}/>
  </colgroup>
  
    
      Attribute type
      Attribute value format
    
  
  
    
      String
      <code>"value"</code>
    
    
      Number
      <code>1</code>
    
    
      Boolean
      <code>true</code> or <code>false</code>
    
    
      Time
      <code>"2022-03-15T00:00:00Z"</code>
    
    
      Location
      <code>"{'{'}\"name\":\"geofence_name\",\"format\":\"geojson-base64\",\"object\":\"geofence_data\"{'}'}"</code>
    
    
      List of strings
      <code>["value1", "value2", "value3"]</code>
    
    
      List of numbers
      <code>[1, 2, 3]</code>
    
    
      List of dates
      <code>["2022-02-15T00:00:00+02:00", "2022-10-15T00:00:00+02:00", "2022-03-16T00:00:00+02:00"]</code>
    
    
      List of locations
      <code>["{'{'}\"name\":\"geofence_name1\",\"format\":\"geojson-base64\",\"object\":\"geofence_data1\"{'}'}", "{'{'}\"name\":\"geofence_name2\",\"format\":\"geojson-base64\",\"object\":\"geofence_data2\"{'}'}", "{'{'}\"name\":\"geofence_name3\",\"format\":\"geojson-base64\",\"object\":\"geofence_data3\"{'}'}"]</code>
    
  

}

:::note Example
Imagine we want to import a coupon that has two custom attributes:
- A _string_ attribute called `type`.
- A _boolean_ attribute called `added_customer_benefits`.

The content of the `attributes` column in our CSV file must be:
`{"type": "special", "added_customer_benefits": true}`.
:::

## Create a referral code programmatically

To create codes programmatically, use the
[Import referrals](/management-api#tag/Referrals/operation/importReferrals) endpoint.
It does the same thing as the import feature inside the Campaign Manager.

## Related pages

- [Create campaign budgets](/docs/product/campaigns/settings/manage-campaign-budgets.md)
- [Basic referral](/docs/product/tutorials/referrals/basic-referral.md)
- [Create a referral code](/docs/product/rules/effects/use-effects.md#create-a-referral-code)
