# Macro Analysis Store API — Curl / Postman

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

Replace placeholders:

- `CATEGORY_ID` → a valid `research_categories.id` (Macro Analysis category)
- `REPORT_TYPE_ID` → a valid `report_types.id`
- file paths → real local files

```bash
curl --location --request POST "http://localhost/fintraBackend/fi_adm/public/api/research-company/research-macro-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "report_date=2026-03-31" \
  --form "report_type_id=REPORT_TYPE_ID" \
  --form "sub_heading=Inflation Outlook" \
  --form "is_featured=1" \
  --form "tags[]=macro" \
  --form "tags[]=inflation" \
  --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-macro-analysis-store" \
  --header "Accept: application/json" \
  --header "Authorization: Bearer YOUR_JWT_TOKEN" \
  --form "report_date=2026-03-31" \
  --form "report_type_id=REPORT_TYPE_ID" \
  --form "category_id=CATEGORY_ID"
```

---

## Field reference

| Field | Required | Type | Notes |
|---|---|---|---|
| `report_date` | Yes | date | Reporting Date |
| `report_type_id` | Yes | int | must exist in `report_types.id` |
| `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 Macro Analysis:** `quarter` (always `null`), securities, sectors.

`report_title` is generated server-side from the selected report type: `Budget Analysis Reports` becomes `Bangladesh National Budget_{year}` (e.g. `Bangladesh National Budget_2026`), `Monetary Policy Statement Notes` becomes `Monetary Policy Review_{report_date}` (e.g. `Monetary Policy Review_2026-03-31`), and any other report type falls back to `{report_type_name}_{report_date}`. Do not send it from the frontend.

---

## Postman setup

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

| Key | Type | Example value |
|---|---|---|
| `report_date` | Text | `2026-03-31` |
| `report_type_id` | Text | `1` |
| `category_id` | Text | `1` |
| `sub_heading` | Text | `Inflation Outlook` |
| `is_featured` | Text | `1` |
| `tags[]` | Text | `macro` |
| `tags[]` | Text | `inflation` |
| `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. For multiple tags use separate `tags[]` rows.

---

## Example `en_json` / `bn_json`

**en_json**
```json
{"title":"Macro Analysis","report_date":"2026-03-31","summary":"Inflation eased slightly amid stable policy rates.","pages":[{"page":1,"heading":"Key Takeaways","content":"CPI moderated while remittance inflows remained supportive."}]}
```

**bn_json**
```json
{"title":"ম্যাক্রো বিশ্লেষণ","report_date":"2026-03-31","summary":"স্থিতিশীল নীতি সুদের হারের মধ্যে মুদ্রাস্ফীতি কিছুটা কমেছে।","pages":[{"page":1,"heading":"মূল বিষয়","content":"সিপিআই হ্রাস পেয়েছে এবং রেমিট্যান্স প্রবাহ সহায়ক রয়েছে।"}]}
```

---

## Expected responses

**Success (201)**

```json
{
  "status": true,
  "message": "Macro Analysis report uploaded successfully",
  "data": {
    "id": 1,
    "category_id": 1,
    "report_type_id": 1,
    "report_title": "Monetary Policy Review_2026-03-31",
    "sub_heading": "Inflation Outlook",
    "quarter": null,
    "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\":[]}",
    "report_type": { "id": 1, "name": "..." },
    "category": { "id": 1, "name": "Macro Analysis" },
    "tags": [ ... ]
  }
}
```

**Validation fail (422)**

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

---

## `route_apis` insert

```sql
INSERT INTO `route_apis` (`api_id`, `name`, `url`, `controller`, `function`, `prefix`, `method`, `details`, `api_activity_flag`, `created_by`, `create_date`, `create_time`, `update_by`, `update_date`, `update_time`, `created_at`, `updated_at`) VALUES
(NULL, 'research-macro-analysis-store', 'research-macro-analysis-store', 'DiverseResearchController', 'storeMacroAnalysis', 'research-company', 'POST', 'research-macro-analysis-store API', 'R', '5', '2026-09-23', '21:36:00', NULL, NULL, NULL, '2026-09-23 21:36:00', '2026-09-23 21:36:00');
```
