//native
type Shutterstock = {
token: string;
};
/**
* Search catalogs for assets
* This endpoint searches for assets in the account's catalog. If you specify more than one search parameter, the API uses an AND condition. Array parameters can be specified multiple times; in this case, the API uses an AND or an OR condition with those values, depending on the parameter. You can also filter search terms out in the `query` parameter by prefixing the term with NOT.
*/
export async function main(
auth: Shutterstock,
sort: "newest" | "oldest" | undefined,
page: string | undefined,
per_page: string | undefined,
query: string | undefined,
collection_id: string | undefined,
asset_type: string | undefined,
) {
const url = new URL(`https://api.shutterstock.com/v2/catalog/search`);
for (const [k, v] of [
["sort", sort],
["page", page],
["per_page", per_page],
["query", query],
["collection_id", collection_id],
["asset_type", asset_type],
]) {
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