Color API

Description

Convert a color from one color-space to multiple. Supports the following formats: hex, rgb, rgba, cymk, hsb, hsl, hsla, xyz, CIELab.

Endpoint

> GET https://api.jsonrepo.com/v1/compute/converter/color

Headers

Field Description
api_key Required Your API Key

Parameters

Field Type Description
from String Required The color value to convert. Accepted formats:
#000000
rgb(255,255,255)
rgba(255,255,255,1)
hsl(260, 50%, 50%)
hsla(260,50%,50%,0.5)
cmyk(100,100,0,0)
hsb(110,40%,30%)
xyz(21.2469,42.6749,42.1306)
CIELab(12.81,15.4,-27.43)

Response

A successful request will result in a populated payload field with the expected output.

A failed request will result in an error output as detailed in Error Rules. If the endpoint validation fails due to missing, badly formatted or invalid parameters, the endpoint will return HTTP code 400 along with a message detailing the error.

See the examples section for more information.

Request

  • Curl
// Convert from HEX #FFA14E

curl -G \
https://api.jsonrepo.com/v1/compute/converter/color \
-H "api_key: {YOUR_API_KEY_HERE}" \
--data-urlencode "from=#ffa14e" 

// Same request but using RGB instead

curl -G \
https://api.jsonrepo.com/v1/compute/converter/color \
-H "api_key: {YOUR_API_KEY_HERE}" \
--data-urlencode "from=rgb(255,161,78)" 

Success Response

{
    "http_code": 200,
    "http_message": "Ok",
    "message": "Successful execution",
    "payload": {
        "color": {
            "input": {
                "red": 255,
                "green": 161,
                "blue": 78,
                "alpha": 1
            },
            "formats": {
                "hex": "#ffa14e",
                "rgb": "rgb(255,161,78)",
                "rgba": "rgba(255,161,78,1.00)",
                "cymk": "cmyk(0%,37%,69%,0%)",
                "hsb": "hsb(29,69%,100%)",
                "hsl": "hsl(28,100%,65%)",
                "hsla": "hsla(28,100%,65%,1)",
                "xyz": "xyz(55.36,47.2998,13.4197)",
                "cielab": "CIELab(74.38,27.99,56.3)"
            }
        }
    }
}

Error Response Examples

// Request with badly formatted `from` parameter

{
    "http_code": 400,
    "http_message": "Bad Request",
    "message": "Malformed request: `from` parameter contains an unrecognized color value.",
    "payload": []
}