# Settings

The admin settings API allows you to do the following:

* fetch setting sections
* fetch a section's list of fields
* &#x20;read, update and delete setting options for ACFW.

### GE&#x54;**:** /wp-json/coupons/v1/settings/sections <a href="#get-wp-json-loyalty-program-v-1-dashboard" id="get-wp-json-loyalty-program-v-1-dashboard"></a>

Fetch all sections of ACFW settings.

{% tabs %}
{% tab title="Request" %}
**Requirements:**

* Logged-in user
* user role with `manage_woocommerce` user capability

| Method | Endpoint                              |
| ------ | ------------------------------------- |
| GET    | /wp-json/coupons/v1/settings/sections |

| Request Headers | Required | Type    | Description                                                                                  |
| --------------- | -------- | ------- | -------------------------------------------------------------------------------------------- |
| ​section        | ​false   | ​string | <p>Slug of the current section.</p><p>When filled, it will preload the section's fields.</p> |
| {% endtab %}    |          |         |                                                                                              |

{% tab title="Request Example" %}
Get all sections

```
GET: http://example.com/wp-json/coupons/v1/settings/sections
```

Preload fields for a specified section

```
GET: http://example.com/wp-json/coupons/v1/settings/sections

Custom Headers JSON
{
    "section": "bogo_deals_section"
}
```

{% endtab %}

{% tab title="Response Example" %}
**Status: 200 OK**

Get all setting sections.

```
[
  {
    "id": "general_section",
    "title": "General",
    "fields": [],
    "show": true,
    "module": false
  },
  {
    "id": "bogo_deals_section",
    "title": "BOGO Deals",
    "fields": [],
    "show": true,
    "module": "acfw_bogo_deals_module"
  },
  {
    "id": "scheduler_section",
    "title": "Scheduler",
    "fields": [],
    "show": true,
    "module": "acfw_scheduler_module"
  },
  {
    "id": "role_restrictions_section",
    "title": "Role Restrictions",
    "fields": [],
    "show": true,
    "module": "acfw_role_restrict_module"
  },
  {
    "id": "url_coupons_section",
    "title": "URL Coupons",
    "fields": [],
    "show": true,
    "module": "acfw_url_coupons_module"
  },
  {
    "id": "modules_section",
    "title": "Modules",
    "fields": [],
    "show": true,
    "module": false
  }
]
```

Get all setting sections and load fields for current section

```
[
  {
    "id": "general_section",
    "title": "General",
    "fields": [],
    "show": true,
    "module": false
  },
  {
    "id": "bogo_deals_section",
    "title": "BOGO Deals",
    "fields": [
      {
        "title": "BOGO Deals",
        "type": "title",
        "desc": "",
        "id": "acfw_bogo_deals_main_title",
        "value": false
      },
      ...fields
    ],
    "show": true,
    "module": "acfw_bogo_deals_module"
  },
  {
    "id": "scheduler_section",
    "title": "Scheduler",
    "fields": [],
    "show": true,
    "module": "acfw_scheduler_module"
  },
  {
    "id": "role_restrictions_section",
    "title": "Role Restrictions",
    "fields": [],
    "show": true,
    "module": "acfw_role_restrict_module"
  },
  {
    "id": "url_coupons_section",
    "title": "URL Coupons",
    "fields": [],
    "show": true,
    "module": "acfw_url_coupons_module"
  },
  {
    "id": "modules_section",
    "title": "Modules",
    "fields": [],
    "show": true,
    "module": false
  }
]
```

**Status: 403 Forbidden**

```
{
    "code": "rest_forbidden_context",
    "message": "Sorry, you are not allowed access to this endpoint.",
    "data": {
        "status": 401
    }
}
```

{% endtab %}
{% endtabs %}

### GE&#x54;**:** /wp-json/coupons/v1/settings/sections/{section\_id} <a href="#get-wp-json-loyalty-program-v-1-dashboard" id="get-wp-json-loyalty-program-v-1-dashboard"></a>

Get fields for a given setting section

{% tabs %}
{% tab title="Request" %}
**Requirements:**

* Logged-in user
* user role with `manage_woocommerce` user capability

| Method       | Endpoint                                            |
| ------------ | --------------------------------------------------- |
| GET          | /wp-json/coupons/v1/settings/sections/{section\_id} |
| {% endtab %} |                                                     |

{% tab title="Request Example" %}
Get fields for general section

```
GET: http://example.com/wp-json/coupons/v1/settings/sections/general
```

{% endtab %}

{% tab title="Response Example" %}
**Status: 200 OK**

Get fields for general section

```
{
  "id": "general_section",
  "fields": [
    {
      "title": "General",
      "type": "title",
      "desc": "",
      "id": "acfw_general_main_title",
      "value": false
    },
    {
      "title": "Default coupon category",
      "type": "select",
      "desc_tip": "If a coupon is saved without specifying a category, give it this default category. This is useful when third-party tools create coupons or for coupons created via API.",
      "id": "acfw_default_coupon_category",
      "class": "wc-enhanced-select",
      "placeholder": "Select a category",
      "taxonomy": "shop_coupon_cat",
      "options": [
        {
          "key": 55,
          "label": "BOGO coupons"
        },
        {
          "key": 35,
          "label": "Redeemed"
        },
        {
          "key": 19,
          "label": "Uncategorized"
        },
        {
          "key": 54,
          "label": "User Owned"
        }
      ],
      "value": "19"
    }
  ]
}
```

**Status: 403 Forbidden**

```
{
    "code": "rest_forbidden_context",
    "message": "Sorry, you are not allowed access to this endpoint.",
    "data": {
        "status": 401
    }
}
```

{% endtab %}
{% endtabs %}

### GET: /wp-json/coupons/v1/settings/{setting\_id}

Get the value of an ACFW setting option.

{% tabs %}
{% tab title="Request" %}

| Method       | Endpoint                                   |
| ------------ | ------------------------------------------ |
| GET          | /wp-json/coupons/v1/settings/{setting\_id} |
| {% endtab %} |                                            |

{% tab title="Request Example" %}
Get the value of a BOGO Deals global notice message setting value.

```
GET: http://example.com/wp-json/coupons/v1settings/acfw_bogo_deals_notice_message
```

{% endtab %}

{% tab title="Response Example" %}
**Status: 200 OK**

Get the value of a BOGO Deals global notice message setting value.

```
{
  "id": "acfw_bogo_deals_notice_message",
  "value": "Your current cart is eligible to redeem deals"
}
```

**Status: 403 Forbidden**

```
{
    "code": "rest_forbidden_context",
    "message": "Sorry, you are not allowed access to this endpoint.",
    "data": {
        "status": 401
    }
}
```

{% endtab %}
{% endtabs %}

### PU&#x54;**:** /wp-json/coupons/v1/settings/{setting\_id} <a href="#get-wp-json-loyalty-program-v-1-dashboard" id="get-wp-json-loyalty-program-v-1-dashboard"></a>

Update value of an ACFW setting option.

{% tabs %}
{% tab title="Request" %}
**Requirements:**

* Logged-in user
* user role with `manage_woocommerce` user capability

| Method | Endpoint                                   |
| ------ | ------------------------------------------ |
| PUT    | /wp-json/coupons/v1/settings/{setting\_id} |

| Query Parameters | Required | Type    | Description                                                        |
| ---------------- | -------- | ------- | ------------------------------------------------------------------ |
| value            | true     | mixed   | Value to update                                                    |
| ​type            | ​false   | ​string | <p>​Format type of value.</p><p>Default as <code>string</code></p> |
| {% endtab %}     |          |         |                                                                    |

{% tab title="Request Example" %}
Update value of **BOGO Deals:** **Global notice button text** setting option.

```
PUT: http://example.com/wp-json/coupons/v1/settings/acfw_bogo_deals_notice_button_text

JSON Body:
{
    value: "View Deals", 
    type: "text"
}
```

Disable  **Sort Coupons in Cart** module

```
PUT: http://example.com/wp-json/coupons/v1/settings/acfw_sort_coupons_module

JSON Body:
{
    value: "", 
    type: "module"
}
```

{% endtab %}

{% tab title="Response Example" %}
**Status: 200 OK**

Update value of **BOGO Deals:** **Global notice button text** setting option.

```
{
    "id":"acfw_bogo_deals_notice_button_text",
    "value":"View Deals"
}
```

Disable  **Sort Coupons in Cart** module

```
{
    "id":"acfw_sort_coupons_module",
    "value":""
}
```

Update  **Spending over a threshold (breakpoints)** setting

**Status: 403 Forbidden**

```
{
    "code": "rest_forbidden_context",
    "message": "Sorry, you are not allowed access to this endpoint.",
    "data": {
        "status": 401
    }
}
```

{% endtab %}
{% endtabs %}

### DELET&#x45;**:** /wp-json/coupons/v1/settings/{setting\_id} <a href="#get-wp-json-loyalty-program-v-1-dashboard" id="get-wp-json-loyalty-program-v-1-dashboard"></a>

Update value of an ACFW setting option.

{% tabs %}
{% tab title="Request" %}
**Requirements:**

* Logged-in user
* user role with `manage_woocommerce` user capability

| Method       | Endpoint                                   |
| ------------ | ------------------------------------------ |
| DELETE       | /wp-json/coupons/v1/settings/{setting\_id} |
| {% endtab %} |                                            |

{% tab title="Request Example" %}
Get value for **BOGO Deals:** **Global notice button text** setting option.

```
DELETE: http://example.com/wp-json/loyalty-program/v1/settings/acfw_bogo_deals_notice_button_text

```

{% endtab %}

{% tab title="Response Example" %}
**Status: 200 OK**

Delete **Price to points earned ratio** setting option.

```
{
    "updated": true,
    "previous": {
        "id": "acfw_bogo_deals_notice_button_text",
        "value": "View Deals"
    }
}
```

**Status: 403 Forbidden**

```
{
    "code": "rest_forbidden_context",
    "message": "Sorry, you are not allowed access to this endpoint.",
    "data": {
        "status": 401
    }
}
```

{% endtab %}
{% endtabs %}
