Skip to content

HEX to RGB API

Overview

Convert a 3- or 6-digit hexadecimal color value to red, green, and blue integer channels. This endpoint accepts a JSON request body and returns the RGB values in preview.

Endpoint

Method URL
POST https://api.apidatatools.com/hex-to-rgb-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 synchronous.

Headers

Header Type Required Default / values Description
x-api-key string Yes Your API key Authenticates the request.
x-source-type string No body Selects the input mode. Use body for this endpoint.

Request body

Send a JSON object with a hex field. The value may have an optional leading # and must contain either 3 or 6 hexadecimal characters. Letter case is not significant; surrounding whitespace is trimmed.

{
  "hex": "#FF0080"
}

A 3-character value is expanded by repeating each character. For example, F08 is converted as FF0088.

curl example

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

Success response

A successful response has HTTP status 200. The RGB result is returned as a serialized JSON string in preview.

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "preview": "{\n    \"r\": 255,\n    \"g\": 0,\n    \"b\": 128\n}"
}

The r, g, and b values are integer color channels.

Error handling

Errors use this envelope. Additional fields may appear in details.

{
  "status": "error",
  "error": "ERROR_CODE",
  "request_id": "REQUEST_ID",
  "details": {
    "message": "Description of the error."
  }
}
HTTP status Error code(s) Description
400 EMPTY_BODY The request body is empty.
400 INVALID_BODY_ENCODING The request body could not be decoded.
400 INVALID_JSON The body is not valid JSON.
400 MISSING_HEX_VALUE The JSON body does not contain hex.
400 EMPTY_HEX_VALUE The hex value is empty after trimming whitespace.
400 INVALID_HEX_FORMAT The value is not a 3- or 6-character hexadecimal color, with an optional leading #.
400 HEX_TO_RGB_FAILED The HEX value could not be converted.
400 INVALID_SOURCE_TYPE The source type is invalid. Use body for this endpoint.
401 UNAUTHORIZED Authentication failed or is missing.
404 USER_NOT_FOUND The account associated with the request was not found.
404 UNKNOWN_FUNCTION The requested API endpoint is unsupported.
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 An unexpected error occurred while processing the request.

Notes

  • Body-size limits, quotas, and rate limits depend on the plan. See API tool limits.
  • This endpoint returns RGB data in preview; it does not produce a downloadable file.