Request & Responses
This page provides a detailed overview of Firstock’s API response format, referencing the common fields you’ll see across multiple endpoints—whether the request succeeds or fails.
Overview
When you call a Firstock API endpoint, you’ll receive a JSON response that typically contains:
- A status field, indicating success or failed.
- A message field, providing a short description of the outcome.
- An optional code field—often a string or number resembling HTTP status codes (e.g., "400", "401", "429").
- A data field (on success) or an error object (on failure).
With this standardized approach, you can quickly determine if the request was successful, handle any returned data, or parse an error object to diagnose issues.
Common Code Response
Code | Name (If Present) | HTTP Equivalent |
Meaning / Typical Causes |
Resolution |
---|---|---|---|---|
200 |
N/A (Success) |
200 OK |
- Indicates a successful |
- No action needed |
400 |
BAD_REQUEST, |
400 Bad |
- Missing or malformed fields |
- Check which field |
401 |
INVALID_JKEY, |
401 |
- jKey (session token) is invalid |
- Re-authenticate the user. |
403 |
FORBIDDEN |
403 |
- User lacks permission |
- Verify user privileges. |
404 |
RESOURCE_ |
404 Not |
- The endpoint, symbol, or |
- Confirm correct |
429 |
RATE_LIMIT |
429 Too |
- Client has exceeded |
- Implement client-side |
500 |
INTERNAL_ |
500 Internal |
- Unexpected server issue. |
- Retry after a brief delay. |
503 |
SERVICE_ |
503 Service |
- The service is down |
- Try again after a |
Success Responses
When an API call is successful, you’ll see a minimal set of fields confirming the outcome and providing the requested data.
{
"status": "success",
"message": "Operation successful",
"data": {
// The payload, varying by endpoint
}
}
Fields in a Success Response
Field | Data Type | Description | Example |
---|---|---|---|
status |
string |
Always "success" for a successful request. |
"success" |
message |
string |
A short description or confirmation of |
"Login successful" |
data |
object or array |
The primary response payload, |
e.g., user profile, quote data, etc. |
->Some endpoints may return additional top-level fields (like "code") even on success, but commonly you’ll see status, message, and data.
Failure (Error) Responses
If an API call fails due to invalid input, expired tokens, or any other issue, the response includes:
- status set to "failed".
- An optional code resembling HTTP status codes (e.g., "400", "401", "429").
- A name or short label describing the error category.
- An error object detailing which field or parameter caused the failure.
For a deep dive into parsing and handling errors, see the Exception & Error Handling page.
Fields in an Error Response
{
"status": "failed",
"code": "400",
"name": "BAD_REQUEST",
"error": {
"field": "exchange",
"message": "required field is empty or missing: exchange"
}
}
Field | Data Type | Description | Example |
---|---|---|---|
status |
string |
Typically "failed" when the request |
"failed" |
code |
string or integer |
Numeric or string code resembling HTTP |
"400" |
name |
string |
Short label describing the error type |
"MISSING_FIELD", |
error |
object |
Object describing which field triggered |
See Error Object below |
Error Object
"error": {
"field": "tradingSymbol",
"message": "Trading Symbol is required"
}
- field: Indicates which parameter or resource caused the error (e.g., "tradingSymbol", "jKey").
- message: Explains the nature of the error—e.g., “cannot be empty,” “is invalid,” “expired token,” or “API rate limit exceeded.”
Best Practices & Recommendations
-
Check status
- Always verify if status is "success" or "failed" before processing data.
-
Use data Correctly
- If status = "success", parse data for the payload (e.g., quotes, user info, order details).
-
Inspect error Fields
- If status = "failed", parse error.field and error.message to pinpoint the cause.
-
Respect Rate Limits
- If you encounter code = "429", reduce requests or adopt a backoff to avoid spamming the server.
-
Maintain Authentication
- code = "401" or a name like "INVALIDJKEY" means your session token (jKey) is expired or invalid—prompt re-login or refresh the token.
-
Provide User Feedback
- Display descriptive error messages. For example, if field = "password", show “Your password cannot be empty.”
-
Logging & Monitoring
- Capture all failed responses in logs for debugging or analytics. Patterns in errors (e.g., repeated missing fields) can highlight UI or user flow issues.
Conclusion
A consistent response format—covering both success and failure cases—ensures you can seamlessly integrate Firstock’s APIs into your application. By following these guidelines:
- You’ll handle success responses by parsing data.
- You’ll manage failed responses by inspecting status, code, name, and especially the error object.
- You’ll respect API rate limits and maintain valid session tokens, resulting in a more stable, user-friendly trading experience.
For further information, refer to the Exception & Error Handling page for a deeper look into error parsing or consult Firstock’s official documentation for advanced usage.