Your username is your User ID and your password is your API Key. Both of these are available from the dashboard. The JavaScript code sample demonstrates how to authenticate your request.
You can sign up for a free API key to get started.
This JavaScript code example sends an HTTP POST to the https://hcti.io/v1/image API to convert your HTML/CSS to an image.
Looking for the official npm client? See the Official npm client section on the TypeScript example page.
This example uses the Request client. Install with npm install request.
constrequest=require('request')// Define your HTML/CSSconstdata={html:"<div class='box'>JavaScript ✅</div>",css:".box { border: 4px solid #03B875; padding: 20px; font-family: 'Roboto'; }",google_fonts:"Roboto"}// Create an image by sending a POST to the API.// Retrieve your api_id and api_key from the Dashboard. https://htmlcsstoimage.com/dashboardrequest.post({url:'https://hcti.io/v1/image',form:data}).auth(API_ID,API_KEY).on('data',function(data){console.log(JSON.parse(data))})// {"url": "https://hcti.io/v1/image/1113184e-419f-49f1-b231-2069942a186f"}
We recommend only using the API server-side. This is important because it keeps your API key secret. If you expose them in the browser, they can be used by anyone.
JavaScript example - async/await
If your code supports async/await, we recommend using the following.
This example uses the axios package. Install with npm install axios.