Download a user's posting history via Discourse API?

As Jay noted, an authenticated Post request to /export_csv/export_entity.json can be used to generate the archive. To do this, you need to use an All Users Global API key. Set the request’s API Username to the username of the user you want to create the archive for. You need to supply an entity parameter with the request. The entity parameter should be set to user_archive. With this approach, a notification will be generated for the user. For most users, this will also send them an email that contains a download link, but I don’t think that can be relied on - it’s dependant on how the user has configured their email preferences.

An example curl request to generate the archive. I’ve substituted $api_key for a Global All Users API key in the request:

curl -X POST "http://localhost:3000/export_csv/export_entity.json" -H "Api-Username: Ben" -H "Api-Key: $api_key" -F "entity=user_archive"

I’m unsure if there is any way you can generate the archive in a way that allows you to share it without the user having to access the notification and click its download link. Possibly a Data Explorer query could be developed that returns the information. You could then run the Data Explorer query via the API. The downside of this approach is that if there are more than 10 000 rows of data returned by the query, you would need to make multiple requests to get the data. For more details about the Data Explorer approach, see: How to run Data Explorer queries with the Discourse API.

3 Likes