> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bigcommerce.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bigcommerce.com/_mcp/server.

# Set Cookie Consent Preferences

POST https://your_store.example.com/api/storefront/consent
Content-Type: application/json

Sets the status of a customer's consent to allow data collection by cookies and scripts according to the following consent categories:

  1. Analytics — These cookies provide statistical information on site usage so the store owner can improve the website over time.  
  2. Functional — These cookies enable enhanced functionality, such as videos and live chat. If a shopper does not allow these, then some or all of these functions may not work properly. 
  3. Targeting; Advertising — These cookies allow merchants to create profiles or personalize content to enhance users' shopping experience.
  
  
This endpoint only works if the cookie consent feature is enabled. It is assumed the shopper has not consented to anything until a value is explicitly set. The request body must be populated with a complete set of allowed and denied categories.

Once set, consent preferences will be saved as a cookie for guest shoppers. Consent preferences will be persisted to a shopper's account to be used for future sessions once they have logged in. Consent preferences can also be managed using the [Update customer consent](/developer/api-reference/rest/admin/management/customers/v3/consent/update-customer-consent) endpoint.   

> #### Note
> * Substitute your storefront domain for `yourstore.example.com`. 


Reference: https://docs.bigcommerce.com/developer/api-reference/rest/storefront/consent/post-cookie-consent

## Request

### Headers

- `Accept` (string, required, default: application/json) — The [MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of the response body.

### Body (application/json)

This endpoint expects a ConsentPreferences.

- `allow` (list of enum, required) — Explicitly allowed consent categories. Allowed values are 1, 2, 3.
  - Allowed values: `1`, `2`, `3`
- `deny` (list of enum, required) — Denied consent categories. Allowed values are 2, 3, 4.
  - Allowed values: `1`, `2`, `3`

## Response

### 200

Consent Settings Saved

## Errors

### 400 Bad Request Error

Invalid input

- `any`

## Examples

**Request**

```json
{
  "allow": [
    1,
    2
  ],
  "deny": [
    3
  ]
}
```

**Response**

```json
{}
```

**SDK Code**

```python Example
import requests

url = "https://your_store.example.com/api/storefront/consent"

payload = {
    "allow": [1, 2],
    "deny": [3]
}
headers = {
    "Accept": "application/json",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Example
const url = 'https://your_store.example.com/api/storefront/consent';
const options = {
  method: 'POST',
  headers: {Accept: 'application/json', 'Content-Type': 'application/json'},
  body: '{"allow":[1,2],"deny":[3]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://your_store.example.com/api/storefront/consent"

	payload := strings.NewReader("{\n  \"allow\": [\n    1,\n    2\n  ],\n  \"deny\": [\n    3\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Accept", "application/json")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Example
require 'uri'
require 'net/http'

url = URI("https://your_store.example.com/api/storefront/consent")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Accept"] = 'application/json'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"allow\": [\n    1,\n    2\n  ],\n  \"deny\": [\n    3\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://your_store.example.com/api/storefront/consent")
  .header("Accept", "application/json")
  .header("Content-Type", "application/json")
  .body("{\n  \"allow\": [\n    1,\n    2\n  ],\n  \"deny\": [\n    3\n  ]\n}")
  .asString();
```

```php Example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://your_store.example.com/api/storefront/consent', [
  'body' => '{
  "allow": [
    1,
    2
  ],
  "deny": [
    3
  ]
}',
  'headers' => [
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Example
using RestSharp;

var client = new RestClient("https://your_store.example.com/api/storefront/consent");
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"allow\": [\n    1,\n    2\n  ],\n  \"deny\": [\n    3\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Example
import Foundation

let headers = [
  "Accept": "application/json",
  "Content-Type": "application/json"
]
let parameters = [
  "allow": [1, 2],
  "deny": [3]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://your_store.example.com/api/storefront/consent")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```