Skip to content

HEX to Color Name API

Overview

Convert a HEX color value to the closest matching color name. Send a JSON request body containing a hex value. The request is processed synchronously.

Endpoint

Method URL
POST https://api.apidatatools.com/hex-to-colorname-api

Authentication

Include your API key in the x-api-key header:

x-api-key: YOUR_API_KEY

Input modes

This converter supports body mode only. Requests are processed synchronously.

Headers

Header names are case-insensitive.

Header Type Required Default / values Description
x-api-key String Yes — Your API key.
x-source-type String No Defaults to body; use body for this API. Selects the input mode.

Request body

Send a JSON object with a hex property. The value must contain three or six hexadecimal digits, with or without a leading #. Letter case is not significant.

{
  "hex": "#FF5733"
}

Three-digit shorthand values are expanded before matching. The API trims whitespace around the supplied value.

curl example

curl -X POST "https://api.apidatatools.com/hex-to-colorname-api" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "x-source-type: body" \
  --data '{"hex":"#FF5733"}'

Success responses

A successful response has HTTP status 200. This converter returns data, so the response includes request_id, status, and preview. The preview value is a string containing serialized JSON with the matched color name.

{
  "request_id": "<request ID>",
  "status": "success",
  "preview": "{\n    \"name\": \"<matched color name>\"\n}"
}

Error handling

Errors use an envelope containing status, error, request_id, and details.message. Additional fields may appear in details.

HTTP status Error code(s) When it can occur
400 EMPTY_BODY The request body is empty.
400 INVALID_JSON The body is not valid JSON.
400 MISSING_HEX_KEY The JSON input does not contain a hex key.
400 INVALID_HEX_FORMAT The value is not three or six hexadecimal digits, optionally preceded by #.
400 HEX_TO_RGB_FAILED The HEX value could not be converted to RGB.
400 NO_COLOR_MATCH No matching color name could be determined.
400 INVALID_SOURCE_TYPE The source-type header contains an unsupported value.
400 INVALID_BODY_ENCODING The request body could not be decoded.
401 UNAUTHORIZED Authentication is missing or invalid.
404 USER_NOT_FOUND The authenticated user could not be found.
404 UNKNOWN_FUNCTION The requested API endpoint is not supported.
413 PAYLOAD_TOO_LARGE The request body exceeds the limit for the account’s plan.
429 QUOTA_EXCEEDED The account’s request quota has been reached.
429 RATE_LIMITED The request rate exceeds the account’s limit.
500 PLAN_NOT_FOUND The account’s plan configuration could not be found.
500 INTERNAL_ERROR An unexpected processing error occurred.

Example error response:

{
  "status": "error",
  "error": "INVALID_HEX_FORMAT",
  "request_id": "<request ID>",
  "details": {
    "message": "HEX must be 3 or 6 hex characters (with or without '#')."
  }
}

Notes

  • Request-body size limits, quotas, and rate limits depend on your plan. See API tool limits.
  • This endpoint does not document URL or file input modes.