Wikipedia API not working

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.

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']}

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.