//native
type Shutterstock = {
token: string;
};
/**
* Search editorial images
* This endpoint searches for editorial images. If you specify more than one search parameter, the API uses an AND condition. For example, if you set the `category` parameter to "Alone,Performing" and also specify a `query` parameter, the results include only images that match the query and are in both the Alone and Performing categories. You can also filter search terms out in the `query` parameter by prefixing the term with NOT.
*/
export async function main(
auth: Shutterstock,
query: string | undefined,
sort: "relevant" | "newest" | "oldest" | undefined,
category: string | undefined,
country: string | undefined,
supplier_code: string | undefined,
date_start: string | undefined,
date_end: string | undefined,
per_page: string | undefined,
cursor: string | undefined,
) {
const url = new URL(
`https://api.shutterstock.com/v2/editorial/images/search`,
);
for (const [k, v] of [
["query", query],
["sort", sort],
["category", category],
["country", country],
["supplier_code", supplier_code],
["date_start", date_start],
["date_end", date_end],
["per_page", per_page],
["cursor", cursor],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago