Wikipedia API not working

Asked Sep 1, 2020·1 reply·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hi, I was testing this command listed on the UrlFetch page
!commands add !wiki Wikipedia Article: $(eval const api = $(urlfetch json https://en.wikipedia.org/w/api.php?format=json&action=opensearch&search=$(querystring)); api.error || !api[1][0] ? 'Please add a query to the search' : ${api[1][0]} - ${api[3][0]})
But when I test it, the bot replies "Wikipedia Article: Unexpected token '{' "

Also, when I try using this command
!commands add !sismo Ultimo Sismo: $(eval const api = $(urlfetch json https://api.xor.cl/sismo/) ${api[0][magnitudes][0][magnitud]} - ${api[0][magnitudes][geoReferencia]})

The bot replies "Ultimo Sismo: Unexpected identifier"

How can I fix this? Thank you.

1 reply

Hiya, for the Wikipedia command:

!commands add !wiki Wikipedia Article: $(eval const api = $(urlfetch json https://en.wikipedia.org/w/api.php?format=json&action=opensearch&search=$(querystring)); api.error || !api[1][0] ? 'Please add a query to the search' : `${api[1][0]} - ${api[3][0]}`)

Only change is the backquotes at the end to output the response, but these are not visible at the docs page due to the markup.

For the second one, make sure the keys exist, for example this one does not:
${api[0]['magnitudes']['geoReferencia']}