RGB to HEX API Documentation¶
Overview¶
The RGB to HEX API converts RGB color values into their corresponding HEX color code.
It accepts a JSON body containing red (r), green (g), and blue (b) values, validates them, and returns the HEX color representation.
This API supports synchronous body-based requests only.
No asynchronous (URL or file) modes are available for this tool.
Endpoint (POST)¶
POST https://api.apidatatools.com/rgb-to-hex-api
Headers¶
| Header | Type | Required | Description |
|---|---|---|---|
Content-Type | application/json | Yes | Must be application/json |
x-api-key | string | Yes | Your API key for authentication |
x-source-type | string | Optional | Must be body (default) |
Accepted File Extensions¶
This tool does not accept file uploads or remote URLs.
It only supports direct JSON input in the request body.
Input Example (Body Mode)¶
{
"r": 255,
"g": 165,
"b": 0
}
Example Request¶
Synchronous (Body Input)¶
curl -X POST "https://api.apidatatools.com/rgb-to-hex-api" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{"r": 255, "g": 165, "b": 0}'
Example Response¶
Successful (Body Mode)¶
Status Code: 200 OK
{
"status": "success",
"request_id": "c3a2b1d4-5678-90ef-1234-56789abcdef0",
"preview": "{\n \"hex_color\": \"#FFA500\"\n}"
}
Error Handling¶
Below are all possible error responses returned by this API.
| Error Code | HTTP Status | Description | Example Response |
|---|---|---|---|
INVALID_JSON | 400 | Input is not valid JSON. | json { "status": "error", "error": "INVALID_JSON", "request_id": "uuid", "details": { "message": "Input must be valid JSON." } } |
MISSING_RGB_VALUES | 400 | One or more of r, g, or b keys are missing. | json { "status": "error", "error": "MISSING_RGB_VALUES", "request_id": "uuid", "details": { "message": "JSON must contain r, g, b keys.", "input_keys": ["r", "b"] } } |
INVALID_RGB_NUMBER | 400 | One or more RGB values are not numeric. | json { "status": "error", "error": "INVALID_RGB_NUMBER", "request_id": "uuid", "details": { "message": "r, g, b values must be numeric.", "values": {"r": "abc", "g": 100, "b": 50} } } |
RGB_OUT_OF_RANGE | 400 | RGB values are outside the 0–255 range. | json { "status": "error", "error": "RGB_OUT_OF_RANGE", "request_id": "uuid", "details": { "message": "RGB values must be between 0 and 255.", "r": 300, "g": 100, "b": 50 } } |
RGB_TO_HEX_FAILED | 400 | Conversion failed due to internal formatting issue. | json { "status": "error", "error": "RGB_TO_HEX_FAILED", "request_id": "uuid", "details": { "message": "Failed to convert RGB to HEX." } } |
EMPTY_BODY | 400 | Request body is empty. | json { "status": "error", "error": "EMPTY_BODY", "request_id": "uuid", "details": { "message": "Request body is empty." } } |
PAYLOAD_TOO_LARGE | 413 | Request body exceeds allowed size limit. | json { "status": "error", "error": "PAYLOAD_TOO_LARGE", "request_id": "uuid", "details": { "message": "Request body exceeds 5120KB limit for your plan." } } |
UNKNOWN_FUNCTION | 404 | Endpoint not recognized. | json { "status": "error", "error": "UNKNOWN_FUNCTION", "request_id": "uuid", "details": { "message": "Unsupported API endpoint." } } |
INTERNAL_ERROR | 500 | Unexpected internal error occurred. | json { "status": "error", "error": "INTERNAL_ERROR", "request_id": "uuid", "details": { "message": "Failed to process your request" } } |
Async Job Status¶
Not applicable for this tool.
The RGB to HEX API operates synchronously only.
Notes for Developers¶
- Input Validation:
- The request body must be valid JSON with numeric
r,g, andbkeys. -
Each value must be within the range
0–255. -
Output:
-
The response includes a
hex_colorfield in uppercase HEX format (e.g.,#FFA500). -
Request ID:
-
Every response includes a unique
request_idfor traceability. -
Modes:
- Only body mode is supported.
-
x-source-typeshould remainbody(default). -
Authentication:
-
Requires a valid API key via the
x-api-keyheader. -
Content Type:
-
Always use
application/jsonfor both request and response. -
Error Consistency:
- All errors follow a standardized structure with
status,error,request_id, anddetails.