RGB to Color Name API¶
Overview¶
Convert RGB values to the closest CSS color name. The API accepts a JSON request body and returns the selected name in the preview field.
Endpoint¶
| Method | URL |
|---|---|
POST | https://api.apidatatools.com/rgb-to-colorname-api |
Authentication¶
Include your API key in the x-api-key header:
x-api-key: YOUR_API_KEY
Input modes¶
This endpoint supports synchronous body mode.
Headers¶
Header names are case-insensitive. The spellings below are lowercase.
| Header | Type | Required | Default / values | Description |
|---|---|---|---|---|
x-api-key | string | Yes | Your API key | Authenticates the request. |
x-source-type | string | No | Default: body; use body for this endpoint. | Selects the input source type. |
Request body¶
Send a JSON object with all three RGB components:
| Field | Type | Required | Description |
|---|---|---|---|
r | number | Yes | Red component. |
g | number | Yes | Green component. |
b | number | Yes | Blue component. |
Each value is converted to a number and rounded to an integer before validation. The resulting values must be between 0 and 255, inclusive.
Example:
{
"r": 255,
"g": 0,
"b": 0
}
cURL example¶
curl --request POST \
--url https://api.apidatatools.com/rgb-to-colorname-api \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--data-raw '{"r":255,"g":0,"b":0}'
Success response¶
A successful response has HTTP status 200. The preview field is a string containing serialized JSON with the matched color name.
{
"request_id": "REQUEST_ID",
"status": "success",
"preview": "{\n \"name\": \"COLOR_NAME\"\n}"
}
Error handling¶
Errors use this envelope:
{
"status": "error",
"error": "ERROR_CODE",
"request_id": "REQUEST_ID",
"details": {
"message": "Error description"
}
}
details may also contain additional error-specific fields.
| HTTP status | Error code | Description |
|---|---|---|
400 | INVALID_JSON | The request body is not valid JSON. |
400 | MISSING_RGB_VALUES | The JSON body does not contain all of r, g, and b. |
400 | INVALID_RGB_NUMBER | An RGB value cannot be converted to a number. |
400 | RGB_OUT_OF_RANGE | A rounded RGB value is outside the range 0–255. |
400 | NO_COLOR_MATCH | A closest color could not be determined. |
400 | INVALID_SOURCE_TYPE | The source type is invalid. |
400 | INVALID_BODY_ENCODING | The request body could not be decoded. |
400 | EMPTY_BODY | The request body is empty. |
401 | UNAUTHORIZED | Authentication failed or is missing. |
404 | UNKNOWN_FUNCTION | The endpoint is not supported. |
404 | USER_NOT_FOUND | The authenticated user could not be found. |
413 | PAYLOAD_TOO_LARGE | The request body exceeds the limit for the plan. |
429 | QUOTA_EXCEEDED | The plan’s request quota has been exhausted. |
429 | RATE_LIMITED | The request rate limit has been exceeded. |
500 | PLAN_NOT_FOUND | Plan configuration could not be found. |
500 | INTERNAL_ERROR | The request could not be processed because of an internal error. |
Notes¶
- Request body size, quota, and rate limits depend on your plan. See API tool limits.