Open API for TrapNZ would be very useful

Could an open API be made available for TrapNZ, so that request could be made with a key. XML or JSON would be fine.

That would enable other uses to be made of trapping data. For example, I would like to be able to use the API to get trap data for my project and use it with other applications.

2 Likes

Hi @mikepeters

This post has some info on getting data ins as XML and other formats. An ā€œAll trap recordsā€ layer has been added. It uses basic auth rather than a key, however.

There will be an API for public map feeds, and we plan to switch to using that for private feeds like the ones above. Weā€™ll make an announcement when this becomes available.

Please could you clarify the way that the url needs to be entered for basic auth on something like Arcgis online?
Would it be in the form:
https://username:password@trap.nz/wms/features/000000
Iā€™m attempting this simply in a web browser and i get redirected to https://trap.nz/wms/features/0000000
and it returns:
<result>Access denied for user anonymous</result>

Hi @root
Many thanks - an open API with a key would enable other non GIS uses that people might think of. For example - Connecting trap data to google calendar. Connecting with project management systems etc. The key would be additional to projectID. Each key would be unique to a user.

Xero has great documentation and examples of how their API works as does Google. So far there are 20,000 other open APIā€™s available and growing daily

No mind. The username/password prefix doesnā€™t seem to work, you need a client that can send basic authentication like QGIS (which is free vs Arcgis)
An API key as @mikepeters mentions would be handy too.

Thanks Mike - we do have an open API and will document the feeds as they become available.

Cheers David - yes modern browsers donā€™t let you do the username/password prefix any more!

Hello, Iā€™m working for a client that would like to display trap information on their website. Iā€™ve seen the methods for using https://trap.nz/wms/features/, but Iā€™m not sure how to obtain a username/password to use this service. Are there any updates on the availability of an open API for trap data? Is a paid one available? Thanks!

Hello,
I have done something with https://www.pestfreeporirua.org.nz/
See each suburb in the project directory.
This consumes the project summary data which is available as a json feed. Iā€™m using Wordpress for the website and a table plugin to render the data into a table.

You have to enable ā€œShare Summary Dataā€ on the project page in trap.nz and the you can use a URL including the project id to get the data in json form.

You donā€™t get any choice about what data is returned.
See this for the information on how to build the URL to obtain the data.

https://api.trap.nz/docs/trapnz-data-feeds

(The rest of the API is about logging data to the site from sensors on traps and not for extra into data)

David thatā€™s excellent - It looks very doable. Iā€™ll set up something similar for the Mt Chocolate website once we start catching anything.
Mike

Hi there, for the username and password you just use your usual credentials for the website. You need to be at least a read-only member for each project you will be getting the wms data from.
There are some threads I started regarding getting data out of Trap.nz to make gis reports using qgis which have some information on providing credentials- one thing that you might get stuck on is that the website lets you login with your email address as your username, but the api only lets you use your username.

Hi @david.alderman sorry to bring up such an old post but the URL that you posted no longer works and i canā€™t find anyway to extract a json file. Are you still doing this?

Iā€™m trying to display total counts for a project for each species? (ie 20 Rat, 50 Mice) etc

We didnā€™t fund hosting a website so my example map wonā€™t show. I still have the source code for the html page that loaded the hexmap and that would still work offline in a browser.
I opened it up just now and it looks like it no longer functions.
I can see if its an easy fix, I basically adapted the same javascript code that is used on the home page of trap.nz for the hexmap there but focused on the projects in my area rather than for the whole country.

Itā€™s not for the map that iā€™m after, iā€™m more looking to extract the records in a ā€˜totalā€™ format, and have this sitting in a CSV file. Kind of like these stats, but so i can display them on our trapping website:
image

Itā€™s all changed since I did my hexmap so it doesnt look like it will be a quick fix.
You might want to take a look at these docs and see if you can figure it out.
https://help.trap.nz/books/trapnz-comprehensive-user-guide/chapter/map-feeds

There is a feed that downloads individual trap records for a project, but you would need to summarise it somehow to get the totals like you have.

This outputs CSV

https://io.trap.nz/geo/trapnz-projects/wfs/YourAPiKey/YourProjectID?service=WFS&version=2.0.0&request=GetFeature&typeName=trapnz-projects:default-project-trap-records&outputFormat=csv

Or change the outputFormat to json like this:
outputFormat=application/json

Just updating this thread to note that there are a couple of options currently.

You can get a map which you can embed in your own website that summarises catches with a hexagon heat map. Make sure your project has Share summary data ticked, then you can access the summary map at
https://trap.nz/static/hexmap/?projects=[123]
where 123 is your project ID.

It looks like we havenā€™t documented this in the help yet, Iā€™ve just made a task to get that updated.

Unofficially you can access the raw feed for this map using:
https://trap.nz/project/trap-killcount.json?projects=123

A variety of map feeds are available from our geoserver as documented here:
https://help.trap.nz/books/trapnz-comprehensive-user-guide/page/accessing-map-feeds

We are currently working on a dedicated authenticated API to get data into and out of trap.nz which the app is transitioning over to using as we flesh it out. Eventually once the feature set is stable we will open that up to the public to enable integration with third party apps and integrations.

We also intend to continue to refine our authenticated and public reporting to enable a host of use cases from public consumer based reporting which can be used with a minimum of technical fuss and embedded in third party websites and shared on social media (like the project hex map above), Geoserver-based feeds for GIS applications (expanding on our current feed list above), and opening up authenticated JSON-based data feeds (initially read-only, but likely eventually with write capability).

Hope that helps!

Scott Whittaker
Trap.nz

1 Like