Use Public DSS API in a JavaScript WebApp

florianbriand
florianbriand Registered Posts: 12 ✭✭✭✭

In a Dataiku WebApp, I want to put a link to "export" a dataset in CSV.

This is covered by the "dataset / get data" entrypoint in the public API ( https://doc.dataiku.com/dss/api/6.0/rest/#datasets-dataset-data-get ).

But if I just put a link `<a href="https://mydataikuinstance/public/...">` the browser ask for credentials when I click on the link.

How could I proceed ? Is it possible to handle this entrypoint with the JavaScript dataiku library, as it is possible in Python with the dataikuapi library ?

Tagged:

Best Answer

Answers

  • florianbriand
    florianbriand Registered Posts: 12 ✭✭✭✭
    edited July 17

    Hi !

    Thanks for your answer ! I've used the python backend, by more or less doing the same thing as explained in the link you provided.

    from datetime import datetime
    import dataiku
    import pandas as pd
    from flask import request, send_file, redirect, url_for
    
    @app.route('/<studyId>/users/export')
    def export_study_users(studyId):
        # ... Prepare the dataset according to studyId, with variables, jobs ...
        now = datetime.now()
        now = now.strftime("%Y%m%d_%H%M%S")
        filename = f'users_{studyId}_{now}.xlsx'
        return redirect(url_for('export_study_users_file', studyId=studyId, filename=filename))
    
    @app.route('/<studyId>/users/export/<filename>')
    def export_study_users_file(studyId, filename):
        consumers = dataiku.Dataset(`{studyId}_consumers`)
        response = send_file(
            consumers.raw_formatted_data(format="excel"),
            attachment_filename=filename,
            as_attachment=True,
            cache_timeout=-1,
        )
        response.headers["x-filename"] = filename
        response.headers["x-suggested-filename"] = filename
        response.headers["Access-Control-Expose-Headers"] = 'x-filename'
        return response


    But the `x-filename`headers seems blocked by the Flask configuration, so I'm not able to handle "properly" the download client-side ; I have to cheat

Setup Info
    Tags
      Help me…