# Company Analysis Store API — Curl / Postman

**Method:** `POST`  
**URL:** `/api/research-company-analysis-store`  
**Route name:** `research-company-analysis-store`  
**Controller:** `DiverseResearchController@store`  
**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 Company Analysis report

Replace placeholders:

- `CATEGORY_ID` → a valid `research_categories.id` (Company Analysis category)
- `SECURITY_ID` → a valid `mkt_security_code.id`
- file paths → real local files

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/research-company-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "report_date=2026-03-31" \
  --form "stock_share_ids[]=SECURITY_ID" \
  --form "sub_heading=Q1 Company Snapshot" \
  --form "quarter=Q1" \
  --form "is_featured=1" \
  --form "tags[]=equity" \
  --form "tags[]=bank" \
  --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-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "report_date=2026-03-31" \
  --form "stock_share_ids[]=SECURITY_ID" \
  --form "category_id=CATEGORY_ID"
```

### Multi-select securities example

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/research-company-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "report_date=2026-03-31" \
  --form "stock_share_ids[]=1" \
  --form "stock_share_ids[]=2" \
  --form "category_id=CATEGORY_ID" \
  --form "quarter=Q2" \
  --form "english_pdf=@C:/path/to/english.pdf"
```

---

## Field reference

| Field | Required | Type | Notes |
|---|---|---|---|
| `report_date` | Yes | date | e.g. `2026-03-31` |
| `stock_share_ids[]` | Yes | array of ints | must exist in `mkt_security_code.id` |
| `category_id` | Yes | int | must exist in `research_categories.id` |
| `sub_heading` | No | string | max 255 |
| `quarter` | No | string | `Q1` / `Q2` / `Q3` / `Q4` |
| `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 |

`report_title` is generated server-side as `{security_codes}_{quarter}_{year}_{report_date}` (e.g. `ACI_Q1_2026_2026-03-31`); multiple securities are joined with underscores and the quarter part is skipped when no quarter is sent. Do not send it from the frontend.

---

## Postman setup

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

| Key | Type | Example value |
|---|---|---|
| `report_date` | Text | `2026-03-31` |
| `stock_share_ids[]` | Text | `1` |
| `stock_share_ids[]` | Text | `2` *(add another row for multi)* |
| `category_id` | Text | `1` |
| `sub_heading` | Text | `Q1 Company Snapshot` |
| `quarter` | Text | `Q1` |
| `is_featured` | Text | `1` |
| `tags[]` | Text | `equity` |
| `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.

---

## Expected responses

**Success (201)**

```json
{
  "status": true,
  "message": "Company Analysis report uploaded successfully",
  "data": {
    "id": 1,
    "category_id": 1,
    "report_type_id": null,
    "report_title": "ACI_Q1_2026_2026-03-31",
    "sub_heading": "Q1 Company Snapshot",
    "quarter": "Q1",
    "report_date": "2026-03-31",
    "featured_image_url": "research_reports/...",
    "is_featured": true,
    "english_pdf_url": "research_reports/...",
    "bangla_pdf_url": "research_reports/...",
    "en_json": "{\"pages\":[]}",
    "bn_json": "{\"pages\":[]}",
    "securities": [ ... ],
    "tags": [ ... ]
  }
}
```

**Validation fail (422)**

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

**Server error (500)**

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