Pulling geolocation coordinates into a web map using javascript via the API key

Please help! In my Kobo database I have “_geolocation” coordinates. I want to use these coordinates to dynamically populate a map on my webpage using javascript. Can someone please give me the javascript syntax for applying my api key for the follow data.

When I am logged into my account on my browser window this link will supply me with all of my json data. However. If I switch to another browser window I get the following
“detail”: “Not found”
If I follow the instructions on the follow page
and use postman and set up the authorization with my api-key I get the same message.

If I open a new browser window and use this https://kf.kobotoolbox.org/api/v2/assets/aTXd76EbgyXjVJiB4JPpLQ/data.json?Authorization:Token=with my api key
I get the same message.

I realize that I can’t call the information from the client side because I get CORS errors. I am trying to use server-side programming through node.js to set up a variable on the client side to call the key from the server.

This is a project to create an open source forum for a community to document local archeological and anthropological finds and share with other community members and researchers via the web. I am using WIX for the final site. It was suggested that I not make my database public but I am at my wits end trying to get the coordinates pulled into my javascript so I can populate my map. I am an instructional designer and developer so most of my coding experience is in html, css and javascript.

If you need any more additional information let me know.

Hi @dariengap2021, if you have access to the data then it’s more likely that you are configuring the header incorrectly in Postman. Can you please try this in your terminal and see if it works (replacing your-secret-token with your API token)?

curl -X GET https://kf.kobotoolbox.org/api/v2/assets/aTXd76EbgyXjVJiB4JPpLQ/data.json \
  -H "Authorization: Token your-secret-token"

If you are still getting the message of {"detail": "Not found"} then please ensure your token and asset UID is correct and that you have sufficient permission to view the data with that token. If it works, you can use a tool like this to convert the curl command to Javascript/AJAX.

Note that Authorization:Token=*with my api key* is not a parameter included in the URL but rather a header sent with the request — so unfortunately this won’t work.

1 Like