# Sector Analysis Store API — Curl / Postman

**Method:** `POST`  
**URL:** `/api/research-company/research-sector-analysis-store`  
**Route name:** `research-sector-analysis-store`  
**Controller:** `DiverseResearchController@storeSectorAnalysis`  
**Content-Type:** `multipart/form-data` (required because of file uploads)

Base URL (XAMPP local):

```text
http://localhost/fintraBackend/fi_adm/public/api
```

Replace `YOUR_JWT_TOKEN` with the `access_token` from login.  
Requires middleware: `jwt.auth`, `check.token`, `dynamic.permission`  
(assign this route to the user’s role in route-API permissions first).

---

## 0. Login (get JWT)

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/auth/login" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data-raw "{
    \"email\": \"your.backoffice@email.com\",
    \"password\": \"your_password\"
  }"
```

Copy `access_token` from the response.

---

## 1. Store Sector Analysis report

Replace placeholders:

- `CATEGORY_ID` → a valid `research_categories.id` (Sector Analysis category)
- `SECTOR_ID` → a valid `mkt_security_sector_info.id`
- file paths → real local files

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/research-company/research-sector-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "sector_ids[]=SECTOR_ID" \
  --form "report_date=2026-09-28" \
  --form "sub_heading=Banking Sector Overview" \
  --form "is_featured=1" \
  --form "tags[]=sector" \
  --form "tags[]=banking" \
  --form "category_id=CATEGORY_ID" \
  --form "en_json={\"pages\":[]}" \
  --form "bn_json={\"pages\":[]}" \
  --form "featured_image=@C:/path/to/image.jpg" \
  --form "english_pdf=@C:/path/to/english.pdf" \
  --form "bangla_pdf=@C:/path/to/bangla.pdf"
```

### Minimal required-only request

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/research-company/research-sector-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "sector_ids[]=SECTOR_ID" \
  --form "report_date=2026-09-28" \
  --form "category_id=CATEGORY_ID"
```

### Multi-select sectors example

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/research-company/research-sector-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "sector_ids[]=1" \
  --form "sector_ids[]=2" \
  --form "report_date=2026-09-28" \
  --form "category_id=CATEGORY_ID" \
  --form "sub_heading=Multi Sector Review" \
  --form "english_pdf=@C:/path/to/english.pdf"
```

---

## Field reference

| Field | Required | Type | Notes |
|---|---|---|---|
| `sector_ids[]` | Yes | array of ints | must exist in `mkt_security_sector_info.id` |
| `report_date` | Yes | date | `YYYY-MM-DD`, used to build `report_title` |
| `category_id` | Yes | int | must exist in `research_categories.id` |
| `sub_heading` | No | string | max 255 |
| `is_featured` | No | boolean | `1` / `0` / `true` / `false` |
| `tags[]` | No | array of strings | created via `firstOrCreate` |
| `featured_image` | No | file | jpeg/png/jpg, max 2MB |
| `english_pdf` | No | file | pdf, max 10MB |
| `bangla_pdf` | No | file | pdf, max 10MB |
| `en_json` | No | string | JSON text |
| `bn_json` | No | string | JSON text |

**Not used for Sector Analysis** (left `null` in DB): `quarter`, `report_type_id`, securities.

`report_title` is generated server-side as `{sector_titles}_{report_date}` (e.g. `Bank_2026-09-28`); multiple sectors are joined with underscores. Do not send it from the frontend.

---

## Postman setup

1. Method: **POST**
2. URL: `{{base_url}}/research-company/research-sector-analysis-store`
3. Authorization: **Bearer Token** → paste JWT
4. Headers: `Accept: application/json`
5. Body → **form-data** (not raw JSON):

| Key | Type | Example value |
|---|---|---|
| `sector_ids[]` | Text | `1` |
| `sector_ids[]` | Text | `2` *(add another row for multi)* |
| `report_date` | Text | `2026-09-28` |
| `category_id` | Text | `1` |
| `sub_heading` | Text | `Banking Sector Overview` |
| `is_featured` | Text | `1` |
| `tags[]` | Text | `sector` |
| `tags[]` | Text | `banking` |
| `en_json` | Text | `{"pages":[]}` |
| `bn_json` | Text | `{"pages":[]}` |
| `featured_image` | File | choose image |
| `english_pdf` | File | choose PDF |
| `bangla_pdf` | File | choose PDF |

Do **not** set `Content-Type` manually in Postman; it must auto-set the multipart boundary.

For multiple sectors/tags: use **separate rows** with the same `[]` key. Do **not** send `1,2` as one comma-separated value.

---

## Example `en_json` / `bn_json` (paste as Text)

**en_json**
```json
{"title":"Sector Analysis","sector":"Bank","summary":"Overview of banking sector performance.","pages":[{"page":1,"heading":"Highlights","content":"Sector NPL improved slightly this quarter."}]}
```

**bn_json**
```json
{"title":"খাত বিশ্লেষণ","sector":"ব্যাংক","summary":"ব্যাংক খাতের কর্মক্ষমতার সংক্ষিপ্ত পর্যালোচনা।","pages":[{"page":1,"heading":"হাইলাইটস","content":"এই প্রান্তিকে খাতের এনপিএল সামান্য উন্নতি হয়েছে।"}]}
```

---

## Expected responses

**Success (201)**

```json
{
  "status": true,
  "message": "Sector Analysis report uploaded successfully",
  "data": {
    "id": 1,
    "category_id": 1,
    "report_type_id": null,
    "report_title": "Bank_2026-09-28",
    "sub_heading": "Banking Sector Overview",
    "quarter": null,
    "report_date": "2026-09-28",
    "featured_image_url": "research_reports/...",
    "is_featured": true,
    "english_pdf_url": "research_reports/...",
    "bangla_pdf_url": "research_reports/...",
    "en_json": "{\"pages\":[]}",
    "bn_json": "{\"pages\":[]}",
    "sectors": [ ... ],
    "tags": [ ... ]
  }
}
```

**Validation fail (422)**

```json
{
  "status": false,
  "message": "Validation failed",
  "errors": { ... }
}
```

**Server error (500)**

```json
{
  "status": false,
  "message": "Failed to upload Sector Analysis report",
  "error": "..."
}
```
