//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Search for articles
* You can search for articles by making a GET request to `https://api.intercom.io/articles/search`.
*/
export async function main(
auth: Intercom,
phrase: string | undefined,
state: string | undefined,
help_center_id: string | undefined,
highlight: string | undefined
) {
const url = new URL(`https://api.intercom.io/articles/search`)
for (const [k, v] of [
['phrase', phrase],
['state', state],
['help_center_id', help_center_id],
['highlight', highlight]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
'Intercom-Version': auth.apiVersion,
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 537 days ago