Learn to integrate Lovable with the Getty Images API and access millions of high-quality visuals. Follow our step-by-step guide to get started!
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
gettyConfig.ts
in your project’s source folder (for example, alongside your other TypeScript files).gettyConfig.ts
. This file will store your Getty Images API key. Replace YOURGETTYAPIKEYHERE
with your actual Getty Images API key.
export const GETTYAPIKEY = "YOURGETTYAPIKEYHERE";
gettyApiClient.ts
in the same folder as gettyConfig.ts
.gettyApiClient.ts
. This code defines a function to search for images using the Getty Images API.
import { GETTYAPIKEY } from './gettyConfig';
const BASE_URL = 'https://api.gettyimages.com/v3';
export async function searchGettyImages(query: string, page: number = 1, pageSize: number = 10): Promise {
const url = ${BASE_URL}/search/images?phrase=${encodeURIComponent(query)}&page=${page}&page_size=${pageSize};
const response = await fetch(url, {
headers: {
'Api-Key': GETTYAPIKEY
}
});
if (!response.ok) {
throw new Error(Getty API error: ${response.statusText});
}
return await response.json();
}
app.ts
or a component file).searchGettyImages
function at the top of the file.
import { searchGettyImages } from './gettyApiClient';
// Example function to handle image search
async function handleImageSearch(query: string) {
try {
const data = await searchGettyImages(query);
console.log('Getty Images data:', data);
// Insert additional code here to update your project UI with the image data
} catch (error) {
console.error('Error fetching Getty Images:', error);
}
}
// Example trigger for the search function (e.g., call this function on a button click event)
handleImageSearch("nature");
gettyConfig.ts
and gettyApiClient.ts
) are saved in your project’s file explorer.gettyConfig.ts
accordingly.
handleImageSearch
).When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.