Skip to content

RGB to HEX API

Overview

Convert RGB values to a hexadecimal color. This endpoint accepts a JSON request body and processes it synchronously.

Endpoint

POST https://api.apidatatools.com/rgb-to-hex-api

Authentication

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

Input modes

This endpoint supports body mode only.

Headers

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

Request body

Send a JSON object containing r, g, and b values. Each value must be numeric and, after conversion and rounding to an integer, must be between 0 and 255 inclusive.

{
  "r": 255,
  "g": 128,
  "b": 64
}

The response hex color uses uppercase letters.

curl example

curl -X POST 'https://api.apidatatools.com/rgb-to-hex-api' \
  -H 'x-api-key: YOUR_API_KEY' \
  --data-raw '{"r":255,"g":128,"b":64}'

Success responses

A successful request returns HTTP 200. The preview field is a string containing serialized JSON with the converted color.

{
  "request_id": "REQUEST_ID",
  "status": "success",
  "preview": "{\n    \"hex_color\": \"#FF8040\"\n}"
}

Error handling

Errors use this envelope. Additional fields may be included in details.

{
  "status": "error",
  "error": "ERROR_CODE",
  "request_id": "REQUEST_ID",
  "details": {
    "message": "Description of the error"
  }
}
HTTP status Error code Description
400 INVALID_JSON The request body is not valid JSON.
400 MISSING_RGB_VALUES The JSON object is missing one or more of r, g, or b.
400 INVALID_RGB_NUMBER An RGB value cannot be converted to a number.
400 RGB_OUT_OF_RANGE An RGB value is outside the allowed range of 0–255 after rounding.
400 RGB_TO_HEX_FAILED The RGB-to-HEX conversion failed.
400 INVALID_SOURCE_TYPE x-source-type is not a supported value for the request.
400 INVALID_BODY_ENCODING The request body could not be decoded.
400 EMPTY_BODY The request body is empty.
401 UNAUTHORIZED Authentication context 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 plan.
429 QUOTA_EXCEEDED The plan’s monthly request quota has been reached.
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.

Notes

  • Request-body size limits, quotas, and rate limits depend on your plan. See tool limits.
  • RGB values are rounded to integers before the range check and conversion.