## Initiate export request

### cURL

```
curl --request POST \
  --url https://api.fabric.inc/v3/offers-exports \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
  --data '
{
  "type": "REDEMPTION",
  "filters": [\
    {\
      "field": "storeId",\
      "value": "store001",\
      "operator": "EQUAL"\
    }\
  ]
}
'
```

### Python

```
import requests

url = "https://api.fabric.inc/v3/offers-exports"

payload = {
    "type": "REDEMPTION",
    "filters": [\
        {\
            "field": "storeId",\
            "value": "store001",\
            "operator": "EQUAL"\
        }\
    ]
}
headers = {
    "x-fabric-tenant-id": "<x-fabric-tenant-id>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)
```

### JavaScript

```
const options = {
  method: 'POST',
  headers: {
    'x-fabric-tenant-id': '<x-fabric-tenant-id>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    type: 'REDEMPTION',
    filters: [{field: 'storeId', value: 'store001', operator: 'EQUAL'}]
  })
};

fetch('https://api.fabric.inc/v3/offers-exports', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### PHP

```
<?php

$curl = curl_init();

curl_setopt_array($curl, [\
  CURLOPT_URL => "https://api.fabric.inc/v3/offers-exports",\
  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([\
    'type' => 'REDEMPTION',\
    'filters' => [\
        [\
                'field' => 'storeId',\
                'value' => 'store001',\
                'operator' => 'EQUAL'\
        ]\
    ]\
  ]),\
  CURLOPT_HTTPHEADER => [\
    "Authorization: Bearer <token>",\
    "Content-Type: application/json",\
    "x-fabric-tenant-id: <x-fabric-tenant-id>"\
  ],\
]);

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

curl_close($curl);

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

### Go

```
package main

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

func main() {

url := "https://api.fabric.inc/v3/offers-exports"

payload := strings.NewReader("{\n  \"type\": \"REDEMPTION\",\n  \"filters\": [\n    {\n      \"field\": \"storeId\",\n      \"value\": \"store001\",\n      \"operator\": \"EQUAL\"\n    }\n  ]\n}")

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

req.Header.Add("x-fabric-tenant-id", "<x-fabric-tenant-id>")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

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

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

fmt.Println(string(body))
}
```

### Response Codes

- **201**: Created
- **400**: Bad Request
- **401**: Unauthorized
- **500**: Internal Server Error

### Sample Success Response

```
{
  "exportId": "ab50fe48-5da0-4e77-92d1-bb629eedf19e",
  "startedAt": "2023-05-17T21:24:52.398Z",
  "status": "IN_PROGRESS",
  "type": "REDEMPTION",
  "endedAt": "null",
  "totalDataExported": 0,
  "errors": [],
  "filters": [\
    {\
      "field": "storeId",\
      "value": "store001",\
      "operator": "EQUAL"\
    }\
  ]
}
```

### Sample Error Responses

Request Validation Error:
```
{
  "type": "REQUEST_VALIDATION",
  "message": "Export type not valid."
}
```

Unauthorized Error:
```
{
  "type": "UNAUTHORIZED",
  "message": "Invalid credentials"
}
```

Internal Server Error:
```
{
  "type": "INTERNAL_SERVER_ERROR",
  "message": "Internal server error"
}
```

### Authorizations

Authorization header required in the format:
```
Authorization: Bearer <token>
```

### Required Headers

- **x-fabric-tenant-id**: Must include in your request header.  
  Required string length: `24`.
- **Content-Type**: Application type for the request.
