//native
type Shutterstock = {
token: string;
};
/**
* Run multiple image searches
* This endpoint runs up to 5 image searches in a single request and returns up to 20 results per search. You can provide global search parameters in the query parameters and override them for each search in the body parameter. The query and body parameters are the same as in the `GET /v2/images/search` endpoint.
*/
export async function main(
auth: Shutterstock,
added_date: string | undefined,
added_date_start: string | undefined,
aspect_ratio_min: string | undefined,
aspect_ratio_max: string | undefined,
aspect_ratio: string | undefined,
added_date_end: string | undefined,
category: string | undefined,
color: string | undefined,
contributor: string | undefined,
contributor_country: string | undefined,
fields: string | undefined,
height: string | undefined,
height_from: string | undefined,
height_to: string | undefined,
image_type: string | undefined,
keyword_safe_search: string | undefined,
language:
| "ar"
| "bg"
| "bn"
| "cs"
| "da"
| "de"
| "el"
| "en"
| "es"
| "fi"
| "fr"
| "gu"
| "he"
| "hi"
| "hr"
| "hu"
| "id"
| "it"
| "ja"
| "kn"
| "ko"
| "ml"
| "mr"
| "nb"
| "nl"
| "or"
| "pl"
| "pt"
| "ro"
| "ru"
| "sk"
| "sl"
| "sv"
| "ta"
| "te"
| "th"
| "tr"
| "uk"
| "ur"
| "vi"
| "zh"
| "zh-Hant"
| undefined,
license: string | undefined,
model: string | undefined,
orientation: "horizontal" | "vertical" | undefined,
page: string | undefined,
per_page: string | undefined,
people_model_released: string | undefined,
people_age:
| "infants"
| "children"
| "teenagers"
| "20s"
| "30s"
| "40s"
| "50s"
| "60s"
| "older"
| undefined,
people_ethnicity: string | undefined,
people_gender: "male" | "female" | "both" | undefined,
people_number: string | undefined,
region: string | undefined,
safe: string | undefined,
sort: "newest" | "popular" | "relevance" | "random" | undefined,
spellcheck_query: string | undefined,
view: "minimal" | "full" | undefined,
width: string | undefined,
width_from: string | undefined,
width_to: string | undefined,
body: {
added_date?: string;
added_date_start?: string;
aspect_ratio_min?: number;
aspect_ratio_max?: number;
aspect_ratio?: number;
added_date_end?: string;
authentic?: false | true;
category?: string;
color?: string;
contributor?: string[];
contributor_country?: string[];
fields?: string;
height?: number;
height_from?: number;
height_to?: number;
image_type?: "photo" | "illustration" | "vector"[];
keyword_safe_search?: false | true;
language?:
| "ar"
| "bg"
| "bn"
| "cs"
| "da"
| "de"
| "el"
| "en"
| "es"
| "fi"
| "fr"
| "gu"
| "he"
| "hi"
| "hr"
| "hu"
| "id"
| "it"
| "ja"
| "kn"
| "ko"
| "ml"
| "mr"
| "nb"
| "nl"
| "or"
| "pl"
| "pt"
| "ro"
| "ru"
| "sk"
| "sl"
| "sv"
| "ta"
| "te"
| "th"
| "tr"
| "uk"
| "ur"
| "vi"
| "zh"
| "zh-Hant";
license?: "commercial" | "editorial" | "enhanced"[];
model?: string[];
orientation?: "horizontal" | "vertical";
page?: number;
per_page?: number;
people_model_released?: false | true;
people_age?:
| "infants"
| "children"
| "teenagers"
| "20s"
| "30s"
| "40s"
| "50s"
| "60s"
| "older";
people_ethnicity?:
| "african"
| "african_american"
| "black"
| "brazilian"
| "chinese"
| "caucasian"
| "east_asian"
| "hispanic"
| "japanese"
| "middle_eastern"
| "native_american"
| "pacific_islander"
| "south_asian"
| "southeast_asian"
| "other"
| "NOT african"
| "NOT african_american"
| "NOT black"
| "NOT brazilian"
| "NOT chinese"
| "NOT caucasian"
| "NOT east_asian"
| "NOT hispanic"
| "NOT japanese"
| "NOT middle_eastern"
| "NOT native_american"
| "NOT pacific_islander"
| "NOT south_asian"
| "NOT southeast_asian"
| "NOT other"[];
people_gender?: "male" | "female" | "both";
people_number?: number;
query?: string;
region?: string;
safe?: false | true;
sort?: "newest" | "popular" | "relevance" | "random";
spellcheck_query?: false | true;
view?: "minimal" | "full";
width?: number;
width_from?: number;
width_to?: number;
}[],
) {
const url = new URL(`https://api.shutterstock.com/v2/bulk_search/images`);
for (const [k, v] of [
["added_date", added_date],
["added_date_start", added_date_start],
["aspect_ratio_min", aspect_ratio_min],
["aspect_ratio_max", aspect_ratio_max],
["aspect_ratio", aspect_ratio],
["added_date_end", added_date_end],
["category", category],
["color", color],
["contributor", contributor],
["contributor_country", contributor_country],
["fields", fields],
["height", height],
["height_from", height_from],
["height_to", height_to],
["image_type", image_type],
["keyword_safe_search", keyword_safe_search],
["language", language],
["license", license],
["model", model],
["orientation", orientation],
["page", page],
["per_page", per_page],
["people_model_released", people_model_released],
["people_age", people_age],
["people_ethnicity", people_ethnicity],
["people_gender", people_gender],
["people_number", people_number],
["region", region],
["safe", safe],
["sort", sort],
["spellcheck_query", spellcheck_query],
["view", view],
["width", width],
["width_from", width_from],
["width_to", width_to],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago