Search for customer's addresses - Fabric

Search for customer's addresses

cURL

curl --request POST \
  --url https://api.fabric.inc/v3/customers/{customerId}/customer-address/search \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '\n{
  "match": {
    "county": {
      "op": "IN",
      "value": "King County"
    },
    "latitude": {
      "op": "LTE",
      "value": 47.6205
    },
    "longitude": {
      "op": "LTE",
      "value": -77.0364
    },
    "createdAt": {
      "op": "LTE",
      "value": "2023-08-30T23:20:42.822Z"
    },
    "updatedAt": {
      "op": "LTE",
      "value": "2023-08-30T23:20:42.822Z"
    },
    "deletedAt": {
      "op": "LTE",
      "value": "2023-08-30T23:20:42.822Z"
    },
    "additionalAttributes": {
      "op": "IN",
      "key": "gps",
      "value": "beach"
    },
    "isDeleted": false,
    "isDefault": true
  },
  "sort": "-createdAt",
  "offset": 0,
  "limit": 20
}
'

Python Example

import requests

url = "https://api.fabric.inc/v3/customers/{customerId}/customer-address/search"

payload = {
    "match": {
        "county": {
            "op": "IN",
            "value": "King County"
        },
        "latitude": {
            "op": "LTE",
            "value": 47.6205
        },
        "longitude": {
            "op": "LTE",
            "value": -77.0364
        },
        "createdAt": {
            "op": "LTE",
            "value": "2023-08-30T23:20:42.822Z"
        },
        "updatedAt": {
            "op": "LTE",
            "value": "2023-08-30T23:20:42.822Z"
        },
        "deletedAt": {
            "op": "LTE",
            "value": "2023-08-30T23:20:42.822Z"
        },
        "additionalAttributes": {
            "op": "IN",
            "key": "gps",
            "value": "beach"
        },
        "isDeleted": False,
        "isDefault": True
    },
    "sort": "-createdAt",
    "offset": 0,
    "limit": 20
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)

JavaScript Example

const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    match: {
      county: {op: 'IN', value: 'King County'},
      latitude: {op: 'LTE', value: 47.6205},
      longitude: {op: 'LTE', value: -77.0364},
      createdAt: {op: 'LTE', value: '2023-08-30T23:20:42.822Z'},
      updatedAt: {op: 'LTE', value: '2023-08-30T23:20:42.822Z'},
      deletedAt: {op: 'LTE', value: '2023-08-30T23:20:42.822Z'},
      additionalAttributes: {op: 'IN', key: 'gps', value: 'beach'},
      isDeleted: false,
      isDefault: true
    },
    sort: '-createdAt',
    offset: 0,
    limit: 20
  })
};

fetch('https://api.fabric.inc/v3/customers/{customerId}/customer-address/search', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

PHP Example

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.fabric.inc/v3/customers/{customerId}/customer-address/search",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'match' => [
        'county' => [
                'op' => 'IN',
                'value' => 'King County'
        ],
        'latitude' => [
                'op' => 'LTE',
                'value' => 47.6205
        ],
        'longitude' => [
                'op' => 'LTE',
                'value' => -77.0364
        ],
        'createdAt' => [
                'op' => 'LTE',
                'value' => '2023-08-30T23:20:42.822Z'
        ],
        'updatedAt' => [
                'op' => 'LTE',
                'value' => '2023-08-30T23:20:42.822Z'
        ],
        'deletedAt' => [
                'op' => 'LTE',
                'value' => '2023-08-30T23:20:42.822Z'
        ],
        'additionalAttributes' => [
                'op' => 'IN',
                'key' => 'gps',
                'value' => 'beach'
        ],
        'isDeleted' => false,
        'isDefault' => true
    ],
    'sort' => '-createdAt',
    'offset' => 0,
    'limit' => 20
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Response Format

{
  "query": {
    "offset": 0,
    "limit": 20,
    "count": 100
  },
  "data": [
    {
      "id": "61604a30fdfacd0009816e44",
      "address": {
        "type": "BILLING",
        "addressLine1": "123 Main St.",
        "addressLine2": "Suite 100",
        "addressLine3": "Seventh floor",
        "addressLine4": "Attention: Pat E. Doe",
        "city": "Seattle",
        "region": "WA",
        "postalCode": 98121,
        "county": "King County",
        "country": "US",
        "latitude": 47.6205,
        "longitude": -122.3493
      },
      "isDeleted": false,
      "createdAt": "2023-08-30T23:20:42.822Z",
      "updatedAt": "2023-08-30T23:20:42.822Z",
      "additionalAttributes": {
        "landmark": "Beach"
      },
      "isDefault": false,
      "deletedAt": "2023-08-30T23:20:42.822Z"
    }
  ]
}