Live CSV endpoint

A useful feature in Google Sheets is the ability to publish to csv which then allows you to live link to the csv version of a sheet. I have had issues with this lately though due to changes that Goolge seem to have made in relation to CORS.

In Grist I can copy the ‘Download as csv’ link and this seems to work in terms of being able to link to a csv version of a live sheet. Is it ok to use that approach and are there likely to be any CORS issues that I come up against? Also would be useful to just have an option to ‘share csv’ etc so that it doesn’t feel so hacky :slight_smile:

3 Likes

Thanks for the feedback @oddballs. A live csv link does seem useful. The ‘Download as csv’ link could break, it contains some transient ids. If there were a regular api endpoint like GET /docs/{docId}/tables/{tableId}/csv would that work for you?

2 Likes

Thanks for your reply. Yes - that would work.

Would be nice though if it could be achieved without the API. Would also make sharing the csv a lot easier - i.e. by sending a link to someone as opposed to having to download a snapshot of the file and sending that.

4 Likes

I agree with @oddballs on this request. For example, this would make it very easy to share the .csv with an accountant without having several steps in between.

1 Like

That’s an interesting use-case @Chris_Scott, thanks for adding it. If sharing with an accountant, would you want them to log on to see it, or would you want the .csv link to be accessible without log-in?

@paul-grist It would be easier to have it accessible without logging in, that way they could just download the file and once they grabbed it deactivate the link.

2 Likes

I’ve only just got around to trying this out using /docs/{docId}/download/csv but am getting the response: ‘There was an unexpected error while generating a csv file.’

I can successfully GET the xlsx version but not the csv. Is there a known issue with this?

Hmm sorry about that @habitualshaker, that’s not a very helpful error message. Have you specified a the table to download with tableId? Something like:
https://public.getgrist.com/api/docs/3boQPJrgFmFi/download/csv?tableId=Objects
(That’s for a document with a table called Objects). If you can GET the xlsx version, sounds like you’ve got authorization sorted out. The main difference between the two endpoints is that the csv one is for a single table. See the query parameter documentation for this endpoint here: https://public.getgrist.com/api/docs/3boQPJrgFmFi/download/csv?tableId=Objects

Hi - yes am passing in the tableId parameter. The table name shouldn’t affect things? Mine has a dash in it.

Ah, a dash would become an underscore. The tableId is a “sanitized” version of the table name that is safe to use in Python. You can find it in a few ways; one way is to look at the “Code View” in the Tools section in the lower left of the page, there should be a class with the sanitized name (tableId) of your table.

1 Like

Yes - that sorted it! Thanks

1 Like

Great! I’ve filed an issue to improve the error messages so this kind of problem will become clearer in future.

2 Likes