prince1604 commited on
Commit ·
b8a29b5
1
Parent(s): fc24f5c
Support both JSON body and query params for scanstart endpoint
Browse files- POSTMAN_FIX.md +88 -0
- api.py +20 -2
POSTMAN_FIX.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## ❌ Current Issue in Your Postman Request
|
| 2 |
+
|
| 3 |
+
**What you're doing:**
|
| 4 |
+
```
|
| 5 |
+
POST https://ubuntu593-alt-scraper-api.hf.space/api/scanstart?domain=https://wpengine.com/&limit=26
|
| 6 |
+
```
|
| 7 |
+
With parameters in the **Params** tab.
|
| 8 |
+
|
| 9 |
+
**Why it fails:** The POST endpoint expects JSON in the **Body**, not query parameters.
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
## ✅ FIX: Correct Postman Configuration
|
| 14 |
+
|
| 15 |
+
### Step-by-Step:
|
| 16 |
+
|
| 17 |
+
1. **Set the URL** (Remove all query parameters):
|
| 18 |
+
```
|
| 19 |
+
https://ubuntu593-alt-scraper-api.hf.space/api/scanstart
|
| 20 |
+
```
|
| 21 |
+
|
| 22 |
+
2. **Method**: Keep it as `POST`
|
| 23 |
+
|
| 24 |
+
3. **Go to the "Body" tab** (NOT "Params")
|
| 25 |
+
- Select `raw`
|
| 26 |
+
- Change dropdown from "Text" to `JSON`
|
| 27 |
+
|
| 28 |
+
4. **Paste this into the Body**:
|
| 29 |
+
```json
|
| 30 |
+
{
|
| 31 |
+
"domain": "https://wpengine.com/",
|
| 32 |
+
"limit": 26
|
| 33 |
+
}
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
5. **Headers** (should auto-populate, but verify):
|
| 37 |
+
- `Content-Type: application/json`
|
| 38 |
+
|
| 39 |
+
6. **Click "Send"**
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## ✅ Expected Response:
|
| 44 |
+
```json
|
| 45 |
+
{
|
| 46 |
+
"job_id": "abc-123-def-456"
|
| 47 |
+
}
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
Then use that `job_id` to check progress:
|
| 51 |
+
```
|
| 52 |
+
GET https://ubuntu593-alt-scraper-api.hf.space/api/progress?job_id=abc-123-def-456
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## 🖼️ Visual Guide for Postman
|
| 58 |
+
|
| 59 |
+
### Screenshot 1: URL Setup
|
| 60 |
+
- URL: `https://ubuntu593-alt-scraper-api.hf.space/api/scanstart`
|
| 61 |
+
- Method: `POST`
|
| 62 |
+
- **Params tab should be EMPTY** ❌
|
| 63 |
+
|
| 64 |
+
### Screenshot 2: Body Setup
|
| 65 |
+
- Go to **Body** tab
|
| 66 |
+
- Select **raw**
|
| 67 |
+
- Select **JSON** from dropdown
|
| 68 |
+
- Paste:
|
| 69 |
+
```json
|
| 70 |
+
{
|
| 71 |
+
"domain": "https://wpengine.com/",
|
| 72 |
+
"limit": 26
|
| 73 |
+
}
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
### Screenshot 3: Headers
|
| 77 |
+
- Should show `Content-Type: application/json` automatically
|
| 78 |
+
|
| 79 |
+
---
|
| 80 |
+
|
| 81 |
+
## 🚀 Alternative: Use Query Parameters (I'll add support)
|
| 82 |
+
|
| 83 |
+
If you prefer using query parameters like:
|
| 84 |
+
```
|
| 85 |
+
POST /api/scanstart?domain=...&limit=...
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
Let me know and I'll modify the API to support both methods!
|
api.py
CHANGED
|
@@ -195,7 +195,25 @@ def get_system_status(domain: Optional[str] = None):
|
|
| 195 |
return stats
|
| 196 |
|
| 197 |
@app.post("/api/scanstart")
|
| 198 |
-
def start_scan(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
job_id = str(uuid4())
|
| 200 |
JOBS[job_id] = {
|
| 201 |
"status": "pending",
|
|
@@ -208,7 +226,7 @@ def start_scan(payload: StartReq, bg: BackgroundTasks):
|
|
| 208 |
"result": None,
|
| 209 |
"error": None,
|
| 210 |
}
|
| 211 |
-
bg.add_task(run_scan_job, job_id,
|
| 212 |
return {"job_id": job_id}
|
| 213 |
|
| 214 |
@app.get("/api/progress/{job_id}")
|
|
|
|
| 195 |
return stats
|
| 196 |
|
| 197 |
@app.post("/api/scanstart")
|
| 198 |
+
def start_scan(
|
| 199 |
+
bg: BackgroundTasks,
|
| 200 |
+
payload: Optional[StartReq] = None,
|
| 201 |
+
domain: Optional[str] = Query(None),
|
| 202 |
+
limit: Optional[int] = Query(25)
|
| 203 |
+
):
|
| 204 |
+
# Support both JSON body and query parameters
|
| 205 |
+
if payload:
|
| 206 |
+
target_domain = payload.domain
|
| 207 |
+
target_limit = payload.limit
|
| 208 |
+
elif domain:
|
| 209 |
+
target_domain = domain
|
| 210 |
+
target_limit = limit
|
| 211 |
+
else:
|
| 212 |
+
return JSONResponse(
|
| 213 |
+
status_code=400,
|
| 214 |
+
content={"error": "Must provide either JSON body or query parameters (domain required)"}
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
job_id = str(uuid4())
|
| 218 |
JOBS[job_id] = {
|
| 219 |
"status": "pending",
|
|
|
|
| 226 |
"result": None,
|
| 227 |
"error": None,
|
| 228 |
}
|
| 229 |
+
bg.add_task(run_scan_job, job_id, target_domain, target_limit)
|
| 230 |
return {"job_id": job_id}
|
| 231 |
|
| 232 |
@app.get("/api/progress/{job_id}")
|