# Create Filter (counting)

```javascript
let storageId = 123
let filter = {
  name:"my first filter",
  type :"SEGMENT",
  dimension_indexes:[1], // add column index 1 (postal code in example) in the stats file
  column_filter:[ // filter on column value
    {
    column_index:1, // index 1, postal code in example
    values:["54","67","57","68"], // postal code must start with this values
    operator:"PREFIX" // indicate type of filter: EQUAL,PREFIX etc, see reference
    not:false // if true reverse the condition (here, must not start with selected values)
    }
  ]
  segment_filter:{
    segment: [{id:456}, {id:789}], // count for hash in segment 456 or 789
  }
}
fetch("https://gateway.sirdata.io/api/v1/public/customer/storage/"+storageId+"/filter?=", {
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "x-api-token": "XXXXX-XXXXX-XXXXX-XXXXX",
  },
  "body": JSON.stringify(filter)
})
.then(response => {
  console.log(response);
})
.catch(err => {
  console.error(err);
});
```

If response status code is 202 then proceed to get filter object each x seconds to check status until ERROR or OK

### Get filter segments stats

Reference: <https://openapi.sirdata.io/customer/#tag/filter/paths/~1customer~1storage~1{id}~1filter~1{filterId}~1counting/get>

```javascript
let storageId = 123;
let filterId = 456;

fetch("https://gateway.sirdata.io/api/v1/public/customer/storage/"+storageId+"/filter/"+filterId+"/counting?=", {
  "method": "GET",
  "headers": {
    "x-api-token": "XXXXX-XXXXX-XXXXX-XXXXX",
  },
})
.then(response => {
  console.log(response);
})
.catch(err => {
  console.error(err);
});
```

Example of CSV stats

```csv
segment_name,segment_id,count
Sirdata [Interest] Ecology & Environment,14,375921
Sirdata [Interest] Auto & Vehicles > Electric Cars,1293,88115
Sirdata [Intent] Life Events > Home Movers,578,52699
Sirdata [Inferred] Life Events > Home Movers,2381,51828
Sirdata [Intent] Auto & Vehicles > Electric Cars,599,38929

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sirdata.net/customer-api/create-filter-counting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
