# NOTE: This file is auto generated by OpenAPI Generator 6.2.0 (https://openapi-generator.tech).
# Do not edit this file manually.
defmodule BrazeEx.Api.PreferenceCenter do
@moduledoc """
API calls for all endpoints tagged `PreferenceCenter`.
"""
alias BrazeEx.Connection
import BrazeEx.RequestBuilder
@doc """
## List Preference Centers
> Use this endpoint to list your available preference centers.
## Prerequisites
To use this endpoint, you’ll need an API key with the `preference_center.list` permission.
## Rate limit
This endpoint has a rate limit of 1,000 requests per minute, per workspace.
## Path and request parameters
There are no path or request parameters for this endpoint.
## Example request
```
curl --location -g --request GET https://rest.iad-01.braze.com/preference_center/v1/list \
--header 'Authorization: Bearer YOUR-REST-API-KEY'
```
## Response
``` json
{
"preference_centers": [
{
"name": "My Preference Center 1",
"preference_center_api_id": "preference_center_api_id",
"created_at": "2022-08-17T15:46:10Z",
"updated_at": "2022-08-17T15:46:10Z"
},
{
"name": "My Preference Center 2",
"preference_center_api_id": "preference_center_api_id",
"created_at": "2022-08-19T11:13:06Z",
"updated_at": "2022-08-19T11:13:06Z"
},
{
"name": "My Preference Center 3",
"preference_center_api_id": "preference_center_api_id",
"created_at": "2022-08-19T11:30:50Z",
"updated_at": "2022-08-19T11:30:50Z"
},
{
"name": "My Preference Center 4",
"preference_center_api_id": "preference_center_api_id",
"created_at": "2022-09-13T20:41:34Z",
"updated_at": "2022-09-13T20:41:34Z"
}
]
}
```
### Parameters
- `connection` (BrazeEx.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:Authorization` (String.t):
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec preference_center_v1_list_get(Tesla.Env.client(), keyword()) ::
{:ok, nil} | {:error, Tesla.Env.t()}
def preference_center_v1_list_get(connection, opts \\ []) do
optional_params = %{
:Authorization => :headers
}
request =
%{}
|> method(:get)
|> url("/preference_center/v1/list")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, false}
])
end
@doc """
## Create Preference Center
> Use this endpoint to create a preference center to allow users to manage their notification preferences for email campaigns.
Check out [Creating a preference center via API](https://www.braze.com/docs/user_guide/message_building_by_channel/email/preference_center/) for details on how to include this in your email campaigns.
## Prerequisites
To use this endpoint, you’ll need an API key with the `preference_center.update` permission.
## Rate limit
This endpoint has a rate limit of 10 requests per minute, per workspace.
## Request parameters
| Parameter | Required | Data Type | Description |
| --- | --- | --- | --- |
| `name` | Required | String | The name of the preference center that meets the following requirements: <br>\- Only contains letters, numbers, hyphens, and underscores <br>\- Does not have spaces |
| `preference_center_title` | Optional | String | The title for the preference center and confirmation pages. If a title is not specified, the title of the pages will default to "Preference Center". |
| `preference_center_page_html` | Required | String | The HTML for the preference center page. |
| `confirmation_page_html` | Required | String | The HTML for the confirmation page. |
| `state` | Optional | String | Choose `active` or `draft`. Defaults to `active` if not specified. |
| `options` | Optional | Object | Attributes: `meta-viewport-content`. When present, a `viewport` meta tag will be added to the page with `content=` . |
> **Note:** The preference center name can't be edited after it's created.
### Liquid tags
Refer to the following Liquid tags that can be included in your HTML to generate a user's subscription state on the preference center page.
#### User subscription state
| Liquid | Description |
| --- | --- |
| `{{subscribed_state.${email_global}}}` | Get the global email subscribed state for the user (such as "opted_in", "subscribed", or "unsubscribed"). |
| `{{subscribed_state.${}}}` | |
#### Form inputs and action
| Liquid | Description |
| --- | --- |
| `{% form_field_name :email_global_state %}` | Indicates that a specific form input element corresponds to the user's global email subscribed state. The user's selection state should be "opted_in", "subscribed", or "unsubscribed" when the form is submitted with selection data for the global email subscribed state. If it's a checkbox, the user will either be "opted_in" or "unsubscribed". For a hidden input, the "subscribed" state will also be valid. |
| `{% form_field_name :subscription_group %}` | Indicates that a specific form input element corresponds to a given subscription group. The user's selection state should be either "subscribed" or "unsubscribed" when the form is submitted with selection data for a specific subscription group. |
| `{{preference_center_submit_url}}` | Generates URL for form submission. |
## Example response
```
{
"preference_center_api_id": "preference_center_api_id_example",
"liquid_tag": "{{preference_center.${MyPreferenceCenter2022-09-22}}}",
"created_at": "2022-09-22T18:28:07+00:00",
"message": "success"
}
```
### Parameters
- `connection` (BrazeEx.Connection): Connection to server
- `opts` (keyword): Optional parameters
- `:"Content-Type"` (String.t):
- `:Authorization` (String.t):
- `:body` (String.t):
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec preference_center_v1_post(Tesla.Env.client(), keyword()) ::
{:ok, nil} | {:error, Tesla.Env.t()}
def preference_center_v1_post(connection, opts \\ []) do
optional_params = %{
:"Content-Type" => :headers,
:Authorization => :headers,
:body => :body
}
request =
%{}
|> method(:post)
|> url("/preference_center/v1")
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, false}
])
end
@doc """
## View Details for Preference Center
> Use this endpoint to view the details for your preference centers, including when it was created and updated.
## Prerequisites
To use this endpoint, you'll need an API key with the `preference_center.get` permission.
## Rate limit
This endpoint has a rate limit of 1,000 requests per minute, per workspace.
## Path parameters
| Parameter | Required | Data Type | Description |
| --- | --- | --- | --- |
| `preferenceCenterExternalID` | Required | String | The ID for your preference center. |
## Request parameters
There are no request parameters for this endpoint.
## Example request
```
curl --location -g --request GET https://rest.iad-01.braze.com/preference_center/v1/preference_center_external_id \
--header 'Authorization: Bearer YOUR-REST-API-KEY'
```
## Response
``` json
{
"name": "My Preference Center",
"preference_center_api_id": "preference_center_api_id",
"created_at": "example_time_created",
"updated_at": "example_time_updated",
"preference_center_title": "Example preference center title",
"preference_center_page_html": "HTML for preference center here",
"confirmation_page_html": "HTML for confirmation page here",
"redirect_page_html": null,
"preference_center_options": {
"meta-viewport-content": "width=device-width, initial-scale=2"
},
"state": "active"
}
```
### Parameters
- `connection` (BrazeEx.Connection): Connection to server
- `preference_center_external_id` (String.t):
- `opts` (keyword): Optional parameters
- `:Authorization` (String.t):
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec preference_center_v1_preference_center_external_id_get(
Tesla.Env.client(),
String.t(),
keyword()
) :: {:ok, nil} | {:error, Tesla.Env.t()}
def preference_center_v1_preference_center_external_id_get(
connection,
preference_center_external_id,
opts \\ []
) do
optional_params = %{
:Authorization => :headers
}
request =
%{}
|> method(:get)
|> url("/preference_center/v1/#{preference_center_external_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, false}
])
end
@doc """
## Update Preference Center
> Use this endpoint to update a preference center.
## Prerequisites
To use this endpoint, you’ll need an API key with the `preference_center.update` permission.
## Rate limit
This endpoint has a rate limit of 10 requests per minute, per workspace.
## Path parameters
| Parameter | Required | Data Type | Description |
| --- | --- | --- | --- |
| `preferenceCenterExternalID` | Required | String | The ID for your preference center. |
## Request parameters
| Parameter | Required | Data Type | Description |
| --- | --- | --- | --- |
| `preference_center_page_html` | Required | String | The HTML for the preference center page. |
| `preference_center_title` | Optional | String | The title for the preference center and confirmation pages. If a title is not specified, the title of the pages will default to "Preference Center". |
| `confirmation_page_html` | Required | String | The HTML for the confirmation page. |
| `state` | Optional | String | Choose `active` or `draft`. |
| `options` | Optional | Object | Attributes: `meta-viewport-content`. When present, a `viewport` meta tag will be added to the page with `content=` . |
## Example request
```
curl --location --request POST 'https://rest.iad-01.braze.com/preference_center/v1/{preferenceCenterExternalId}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR-API-KEY-HERE' \
--data-raw '{
"name": "Example",
"preference_center_title": "Example Preference Center Title",
"preference_center_page_html": "HTML for preference center here",
"confirmation_page_html": "HTML here with a message to users here",
"state": "active"
}
'
```
## Example response
```
{
"preference_center_api_id": "8efc52aa-935e-42b7-bd6b-98f43bb9b0f1",
"created_at": "2022-09-22T18:28:07Z",
"updated_at": "2022-09-22T18:32:07Z",
"message": "success"
}
```
### Parameters
- `connection` (BrazeEx.Connection): Connection to server
- `preference_center_external_id` (String.t):
- `opts` (keyword): Optional parameters
- `:"Content-Type"` (String.t):
- `:Authorization` (String.t):
- `:body` (String.t):
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec preference_center_v1_preference_center_external_id_put(
Tesla.Env.client(),
String.t(),
keyword()
) :: {:ok, nil} | {:error, Tesla.Env.t()}
def preference_center_v1_preference_center_external_id_put(
connection,
preference_center_external_id,
opts \\ []
) do
optional_params = %{
:"Content-Type" => :headers,
:Authorization => :headers,
:body => :body
}
request =
%{}
|> method(:put)
|> url("/preference_center/v1/#{preference_center_external_id}")
|> add_optional_params(optional_params, opts)
|> ensure_body()
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, false}
])
end
@doc """
## Generate Preference Center URL
> Use this endpoint to generate a URL for a preference center.
Each preference center URL is unique to each user.
## Prerequisites
To use this endpoint, you’ll need an API key with the `preference_center.user.get` permission.
## Rate limit
This endpoint has a rate limit of 1,000 requests per minute, per workspace.
## Path parameters
| Parameter | Required | Data Type | Description |
| --- | --- | --- | --- |
| `preferenceCenterExternalID` | Required | String | The ID for your preference center. |
| `userID` | Required | String | The user ID. |
## Request parameters
| **Parameter** | **Required** | **Data Type** | **Description** |
| --- | --- | --- | --- |
| `preference_center_api_id` | Required | String | The ID for your preference center. |
| `external_id` | Required | String | The external ID for a user. |
## Example request
```
curl --location --request GET 'https://rest.iad-01.braze.com/preference_center/v1/$preference_center_external_id/url/$user_external_id' \
--header 'Authorization: Bearer YOUR-API-KEY-HERE'
```
## Response
``` json
{
"preference_center_url": "https://www.example.com/preferences"
}
```
### Parameters
- `connection` (BrazeEx.Connection): Connection to server
- `preference_center_external_id` (String.t):
- `user_id` (String.t):
- `opts` (keyword): Optional parameters
- `:Authorization` (String.t):
- `:preference_center_api_id` (String.t):
- `:external_id` (String.t): (Required) String
### Returns
- `{:ok, nil}` on success
- `{:error, Tesla.Env.t}` on failure
"""
@spec preference_center_v1_preference_center_external_id_url_user_id_get(
Tesla.Env.client(),
String.t(),
String.t(),
keyword()
) :: {:ok, nil} | {:error, Tesla.Env.t()}
def preference_center_v1_preference_center_external_id_url_user_id_get(
connection,
preference_center_external_id,
user_id,
opts \\ []
) do
optional_params = %{
:Authorization => :headers,
:preference_center_api_id => :query,
:external_id => :query
}
request =
%{}
|> method(:get)
|> url("/preference_center/v1/#{preference_center_external_id}/url/#{user_id}")
|> add_optional_params(optional_params, opts)
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response([
{200, false}
])
end
end