Learn how to integrate Bolt.new AI with the Shutterstock API using our step‑by‑step guide for seamless creative automation and enhanced workflow.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
shutterstock.ts
.shutterstock.ts
:
/ Replace 'YOURSHUTTERSTOCKAPIKEY' and 'YOURSHUTTERSTOCKAPISECRET' with your actual credentials /
const APIKEY = 'YOURSHUTTERSTOCKAPIKEY';
const APISECRET = 'YOURSHUTTERSTOCKAPISECRET';
/**
- Function to search for images using the Shutterstock API.
- @param query - The search term.
- @returns Promise resolving to the JSON response.
*/
export async function searchShutterstockImages(query: string): Promise {
const endpoint = https://api.shutterstock.com/v2/images/search?query=${encodeURIComponent(query)};
// Create a Basic authentication header
const credentials = btoa(${API_KEY}:${API_SECRET});
const headers = {
'Authorization': 'Basic ' + credentials,
'Content-Type': 'application/json'
};
const response = await fetch(endpoint, { headers });
if (!response.ok) {
throw new Error('Shutterstock API request failed with status ' + response.status);
}
return await response.json();
}
/**
- Example usage:
- (async () => {
- try {
- const results = await searchShutterstockImages('nature');
- console.log(results);
- } catch (error) {
- console.error(error);
- }
- })();
*/
index.ts
or your primary TypeScript file) where you want to use Shutterstock API functionality.searchShutterstockImages
function by adding the following import statement at the top of the file:
import { searchShutterstockImages } from './shutterstock';
async function handleImageSearch(query: string) {
try {
const results = await searchShutterstockImages(query);
console.log('Search results:', results);
// Process and display the results in your Bolt.new AI project UI as required.
} catch (error) {
console.error('Error fetching images from Shutterstock:', error);
}
}
// Example trigger for the function, for demonstration:
handleImageSearch('landscape');
import
statements if they are available as modules.fetch
API is used, which is supported in modern environments. If you experience compatibility issues, consider adding a polyfill by including its script in your project’s HTML file.
handleImageSearch
function logs the Shutterstock API search results.When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.