How to compress images using TinyPNG via API

I recently used TinyPNG’s API for a client but it took me a little while to make a successful request, so I thought I’d share what I did here. There’s no native integration in Make, so we have to set it up using the HTTP > Make a request module.

TinyPNG states " Authentication to the API is done with HTTP Basic Auth. All requests require an Authorization header that contains a Base64 digest of the authentication string api:YOUR_API_KEY where YOUR_API_KEY is the key that can be found on your API account page."

Configuration:


Response:

I’ve personally never used anything like Basic(base64(API_KEY)) so it was a bit of a challenge. Anyway, if anyone’s struggling, hope this helps :slight_smile:

Also, if anyone needs a blueprint, get it here:
Making a request to TinyPNG.json (9.6 KB)

1 Like

Putting the keys in the scenario is terrible practice, because that can be stolen by anyone in your organization, or unintentionally shared when you export the scenario blueprint.

You can use the HTTP “Make an API Auth Request” module instead.

It works:

Screenshot_2024-05-08_210528

samliewrequest private consultation

Join the unofficial Make Discord server to chat with other makers!

1 Like

Oh cool! Would you mind sharing the blueprint here with me?

Sure.

blueprint.json (17.9 KB)

As you can see, there are NO api keys in my blueprint or module export.

Module Export

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the JSON code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the canvas.

  3. Click on each imported module and save it for validation. You may be prompted to remap some variables and connections.

View Module Export Code

JSON

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 1,
                    "module": "http:ActionSendDataAPIKeyAuth",
                    "version": 3,
                    "parameters": {
                        "auth": 16337,
                        "handleErrors": true
                    },
                    "mapper": {
                        "url": "https://api.tinify.com/shrink",
                        "serializeUrl": false,
                        "method": "post",
                        "headers": [],
                        "qs": [],
                        "bodyType": "raw",
                        "parseResponse": true,
                        "timeout": "",
                        "shareCookies": false,
                        "ca": "",
                        "rejectUnauthorized": true,
                        "followRedirect": true,
                        "useQuerystring": false,
                        "gzip": true,
                        "useMtls": false,
                        "contentType": "application/json",
                        "data": "{\n  \"source\": {\n    \"url\": \"https://tinypng.com/images/panda-happy.png\"  }\n}",
                        "followAllRedirects": false
                    },
                    "metadata": {
                        "designer": {
                            "x": -60,
                            "y": 181,
                            "name": "Tinify Compress"
                        },
                        "restore": {
                            "parameters": {
                                "auth": {
                                    "label": "tinify.com API Key"
                                }
                            },
                            "expect": {
                                "method": {
                                    "mode": "chose",
                                    "label": "POST"
                                },
                                "headers": {
                                    "mode": "chose"
                                },
                                "qs": {
                                    "mode": "chose"
                                },
                                "bodyType": {
                                    "label": "Raw"
                                },
                                "contentType": {
                                    "label": "JSON (application/json)"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "auth",
                                "type": "keychain:apikeyauth",
                                "label": "Credentials",
                                "required": true
                            },
                            {
                                "name": "handleErrors",
                                "type": "boolean",
                                "label": "Evaluate all states as errors (except for 2xx and 3xx )",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "url",
                                "type": "url",
                                "label": "URL",
                                "required": true
                            },
                            {
                                "name": "serializeUrl",
                                "type": "boolean",
                                "label": "Serialize URL",
                                "required": true
                            },
                            {
                                "name": "method",
                                "type": "select",
                                "label": "Method",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "get",
                                        "head",
                                        "post",
                                        "put",
                                        "patch",
                                        "delete",
                                        "options"
                                    ]
                                }
                            },
                            {
                                "name": "headers",
                                "type": "array",
                                "label": "Headers",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Value",
                                        "type": "text"
                                    }
                                ]
                            },
                            {
                                "name": "qs",
                                "type": "array",
                                "label": "Query String",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Value",
                                        "type": "text"
                                    }
                                ]
                            },
                            {
                                "name": "bodyType",
                                "type": "select",
                                "label": "Body type",
                                "validate": {
                                    "enum": [
                                        "raw",
                                        "x_www_form_urlencoded",
                                        "multipart_form_data"
                                    ]
                                }
                            },
                            {
                                "name": "parseResponse",
                                "type": "boolean",
                                "label": "Parse response",
                                "required": true
                            },
                            {
                                "name": "timeout",
                                "type": "uinteger",
                                "label": "Timeout",
                                "validate": {
                                    "max": 300,
                                    "min": 1
                                }
                            },
                            {
                                "name": "shareCookies",
                                "type": "boolean",
                                "label": "Share cookies with other HTTP modules",
                                "required": true
                            },
                            {
                                "name": "ca",
                                "type": "cert",
                                "label": "Self-signed certificate"
                            },
                            {
                                "name": "rejectUnauthorized",
                                "type": "boolean",
                                "label": "Reject connections that are using unverified (self-signed) certificates",
                                "required": true
                            },
                            {
                                "name": "followRedirect",
                                "type": "boolean",
                                "label": "Follow redirect",
                                "required": true
                            },
                            {
                                "name": "useQuerystring",
                                "type": "boolean",
                                "label": "Disable serialization of multiple same query string keys as arrays",
                                "required": true
                            },
                            {
                                "name": "gzip",
                                "type": "boolean",
                                "label": "Request compressed content",
                                "required": true
                            },
                            {
                                "name": "useMtls",
                                "type": "boolean",
                                "label": "Use Mutual TLS",
                                "required": true
                            },
                            {
                                "name": "contentType",
                                "type": "select",
                                "label": "Content type",
                                "validate": {
                                    "enum": [
                                        "text/plain",
                                        "application/json",
                                        "application/xml",
                                        "text/xml",
                                        "text/html",
                                        "custom"
                                    ]
                                }
                            },
                            {
                                "name": "data",
                                "type": "buffer",
                                "label": "Request content"
                            },
                            {
                                "name": "followAllRedirects",
                                "type": "boolean",
                                "label": "Follow all redirect",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 2,
                    "module": "http:ActionSendDataAPIKeyAuth",
                    "version": 3,
                    "parameters": {
                        "auth": 16337,
                        "handleErrors": true
                    },
                    "mapper": {
                        "url": "{{first(map(1.headers; \"value\"; \"name\"; \"location\"))}}",
                        "serializeUrl": false,
                        "method": "post",
                        "headers": [],
                        "qs": [],
                        "bodyType": "raw",
                        "parseResponse": true,
                        "timeout": "",
                        "shareCookies": false,
                        "ca": "",
                        "rejectUnauthorized": true,
                        "followRedirect": true,
                        "useQuerystring": false,
                        "gzip": true,
                        "useMtls": false,
                        "contentType": "application/json",
                        "data": "{\n  \"resize\": {\n    \"method\": \"cover\",\n    \"width\": 120,\n    \"height\": 120\n  }\n}",
                        "followAllRedirects": false
                    },
                    "metadata": {
                        "designer": {
                            "x": 185,
                            "y": 179,
                            "name": "Tinify Resize"
                        },
                        "restore": {
                            "parameters": {
                                "auth": {
                                    "label": "tinify.com API Key"
                                }
                            },
                            "expect": {
                                "method": {
                                    "mode": "chose",
                                    "label": "POST"
                                },
                                "headers": {
                                    "mode": "chose"
                                },
                                "qs": {
                                    "mode": "chose"
                                },
                                "bodyType": {
                                    "label": "Raw"
                                },
                                "contentType": {
                                    "label": "JSON (application/json)"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "auth",
                                "type": "keychain:apikeyauth",
                                "label": "Credentials",
                                "required": true
                            },
                            {
                                "name": "handleErrors",
                                "type": "boolean",
                                "label": "Evaluate all states as errors (except for 2xx and 3xx )",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "url",
                                "type": "url",
                                "label": "URL",
                                "required": true
                            },
                            {
                                "name": "serializeUrl",
                                "type": "boolean",
                                "label": "Serialize URL",
                                "required": true
                            },
                            {
                                "name": "method",
                                "type": "select",
                                "label": "Method",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "get",
                                        "head",
                                        "post",
                                        "put",
                                        "patch",
                                        "delete",
                                        "options"
                                    ]
                                }
                            },
                            {
                                "name": "headers",
                                "type": "array",
                                "label": "Headers",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Value",
                                        "type": "text"
                                    }
                                ]
                            },
                            {
                                "name": "qs",
                                "type": "array",
                                "label": "Query String",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Value",
                                        "type": "text"
                                    }
                                ]
                            },
                            {
                                "name": "bodyType",
                                "type": "select",
                                "label": "Body type",
                                "validate": {
                                    "enum": [
                                        "raw",
                                        "x_www_form_urlencoded",
                                        "multipart_form_data"
                                    ]
                                }
                            },
                            {
                                "name": "parseResponse",
                                "type": "boolean",
                                "label": "Parse response",
                                "required": true
                            },
                            {
                                "name": "timeout",
                                "type": "uinteger",
                                "label": "Timeout",
                                "validate": {
                                    "max": 300,
                                    "min": 1
                                }
                            },
                            {
                                "name": "shareCookies",
                                "type": "boolean",
                                "label": "Share cookies with other HTTP modules",
                                "required": true
                            },
                            {
                                "name": "ca",
                                "type": "cert",
                                "label": "Self-signed certificate"
                            },
                            {
                                "name": "rejectUnauthorized",
                                "type": "boolean",
                                "label": "Reject connections that are using unverified (self-signed) certificates",
                                "required": true
                            },
                            {
                                "name": "followRedirect",
                                "type": "boolean",
                                "label": "Follow redirect",
                                "required": true
                            },
                            {
                                "name": "useQuerystring",
                                "type": "boolean",
                                "label": "Disable serialization of multiple same query string keys as arrays",
                                "required": true
                            },
                            {
                                "name": "gzip",
                                "type": "boolean",
                                "label": "Request compressed content",
                                "required": true
                            },
                            {
                                "name": "useMtls",
                                "type": "boolean",
                                "label": "Use Mutual TLS",
                                "required": true
                            },
                            {
                                "name": "contentType",
                                "type": "select",
                                "label": "Content type",
                                "validate": {
                                    "enum": [
                                        "text/plain",
                                        "application/json",
                                        "application/xml",
                                        "text/xml",
                                        "text/html",
                                        "custom"
                                    ]
                                }
                            },
                            {
                                "name": "data",
                                "type": "buffer",
                                "label": "Request content"
                            },
                            {
                                "name": "followAllRedirects",
                                "type": "boolean",
                                "label": "Follow all redirect",
                                "required": true
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}

samliewrequest private consultation

Join the unofficial Make Discord server to chat with other makers!

1 Like

Thanks! Appreciate it :slight_smile:

1 Like

No problem, always happy to help!

Don’t forget to like and bookmark this topic so you can get back to it easily in future!

samliewrequest private consultation

Join the unofficial Make Discord server to chat with other makers!

2 Likes

Hey there. Using the blueprint provided I’m getting an error that the credentials are not valid? But the API key is working just fine when I paste it directly into an HTTP module.

Any ideas how to troubleshoot this?