# Keep the items that match any of several values

`POST /v1/find/array`

Keeps the items equal to, or containing, starting or ending with any of the values, in their original order, and reports their positions. Invert keeps everything that matches none of them.

## Request body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| key | string | no | For an array of objects, the property to compare (a dotted path such as owner.email reaches into nested objects). An object without it never matches |
| match | one of: exact, contains, starts_with, ends_with | no | exact, contains, starts_with or ends_with (default `"exact"`) |
| ignore_case | boolean | no | Treat text that differs only by upper and lower case as equal (default `false`) |
| trim | boolean | no | Ignore spaces around text when comparing (default `false`) |
| items | array of any | yes | The array |
| values | array of any | yes | An item matches when it matches any of these |
| invert | boolean | no | True keeps the items that match none of the values (default `false`) |

## Example request

A request body that works, as JSON.

```json
{
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}
```

## Code samples

Replace YOUR_TOKEN with your access token.

### curl

```shell
curl -X POST 'https://api.skillfulsardine.com/v1/find/array' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}'
```

### PowerShell

```powershell
$body = @'
{
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}
'@
$response = Invoke-RestMethod -Method Post -Uri 'https://api.skillfulsardine.com/v1/find/array' `
  -Headers @{ Authorization = 'Bearer YOUR_TOKEN' } `
  -ContentType 'application/json; charset=utf-8' `
  -Body ([System.Text.Encoding]::UTF8.GetBytes($body))
$response | ConvertTo-Json -Depth 10
```

### Python

```python
import requests

payload = {
    "items": [
        "a.pdf",
        "b.docx",
        "c.pdf",
    ],
    "values": [
        "pdf",
    ],
    "match": "ends_with",
}

response = requests.post(
    "https://api.skillfulsardine.com/v1/find/array",
    headers={"Authorization": "Bearer YOUR_TOKEN"},
    json=payload,
    timeout=30,
)
print(response.json())
```

### JavaScript

```javascript
const response = await fetch("https://api.skillfulsardine.com/v1/find/array", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_TOKEN",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}),
});
const result = await response.json();
console.log(result);
```

### Node

```javascript
// Node 18 or later. Save as call.mjs and run: API_TOKEN=... node call.mjs
const token = process.env.API_TOKEN;

const response = await fetch("https://api.skillfulsardine.com/v1/find/array", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${token}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}),
});
const result = await response.json();
console.log(result);
```

### Rust

```rust
// Cargo.toml: reqwest = { version = "0.12", features = ["blocking", "json"] }, serde_json = "1"
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let body: serde_json::Value = serde_json::from_str(r#"{
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}"#)?;
    let response = reqwest::blocking::Client::new()
        .post("https://api.skillfulsardine.com/v1/find/array")
        .bearer_auth("YOUR_TOKEN")
        .json(&body)
        .send()?;
    println!("{}", response.text()?);
    Ok(())
}
```

### Swift

```swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.skillfulsardine.com/v1/find/array")!)
request.httpMethod = "POST"
request.setValue("Bearer YOUR_TOKEN", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = Data(#"""
{
  "items": [
    "a.pdf",
    "b.docx",
    "c.pdf"
  ],
  "values": [
    "pdf"
  ],
  "match": "ends_with"
}
"""#.utf8)

let (data, _) = try await URLSession.shared.data(for: request)
print(String(decoding: data, as: UTF8.self))
```

## Response

The fields inside `data` of a successful response.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| items | array of any | yes | The items kept |
| indexes | array of integer | yes | Their positions in the original array |
| count | integer | yes | Number of items kept |

## Example response

A real answer from the operation, as JSON. The fields in the table above are inside `data`.

```json
{
  "data": {
    "items": [
      "a.pdf",
      "c.pdf"
    ],
    "indexes": [
      0,
      2
    ],
    "count": 2
  },
  "errors": null,
  "meta": {
    "request_id": "024eafa1-cfd3-445f-85d9-9626d01ae1b5",
    "timestamp": "2026-10-27T07:19:42.117328Z",
    "version": "2026-03-26"
  },
  "pagination": null
}
```

## Responses

| Status | When it happens |
| --- | --- |
| 200 | Successful Response |
| 400 | The body respects the operation schema, but the use case rejected it. Each problem is one ApiError entry |
| 413 | The request is larger than the request size limit of the API allows |
| 422 | The body does not respect the operation schema. Each problem is one ApiError entry with the code validation_error |
| 500 | Something failed inside the server and was not an input problem. The same envelope, errors may be empty |

---
Source: https://skillfulsardine.com/developers/api/filter-array/