Help sending date parameters on api/card/:card-id/csv


I'm using the API latest version v0.41 with Python and I want to export data from cards as CSV. I've followed this thread

but I dont seem to have any success sending the date parameters in the request. I've tried sending the date parameters as:

parameters = """{"parameters": [{"type": "category",
                          "value": "11-01-2021",
                          "target": ["variable", ["template-tag", "start_date"]]},
                         {"type": "category",
                          "value": "11-11-2021",
                          "target": ["variable", ["template-tag", "end_date"]]}

parametros = {"parameters":"%5B%7B%22type%22%3A%22category%22%2C%22value%22%3A%2211-01-2021%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22start_date%22%5D%5D%7D%2C%7B%22type%22%3A%22category%22%2C%22value%22%3A%2211-11-2021%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22end_date%22%5D%5D%7D%5D"}

param = """{"ignore_cache":true,"parameters":[{"type":"category","value":"1-11-2021","target":["variable",["template-tag","start_date"]]},{"type":"category","value":"3-11-2021","target":["variable",["template-tag","end_date"]]}]}"""

pam = "%5B%7B%22type%22%3A%22category%22%2C%22value%22%3A%2211-01-2021%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22start_date%22%5D%5D%7D%2C%7B%22type%22%3A%22category%22%2C%22value%22%3A%2211-11-2021%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22end_date%22%5D%5D%7D%5D"

pm = """parameters"=[{"target":["variable",["template-tag","t1"]],"type":"date/single","value":"2020-05-01"},{"target":["variable",["template-tag","t2"]],"type":"date/single","value":"2020-05-10"}]"""

Using this request:

    req = + '/api/card/1443/query/csv',
                    headers={'Content-Type': 'application/x-www-form-urlencoded',
                             'X-Metabase-Session': TOKEN,
                             'CF-Access-Client-Id': Client_ID,
                             'CF-Access-Client-Secret': Client_Secret},

What am I doing wrong? any help would be greatly appreciated it.Thanks

Hi @regularuser
Your topic title refers to one endpoint, but your code is referring to a different endpoint.
Try using your browser and copy the cURL/Fetch command from the request in the Network-tab, and then compare to what you have generated.
Where are you seeing that you need to use application/x-www-form-urlencoded ?

Hi @flamber thanks for responding!

first of all sorry about the confusing post title, that was my bad. I'm trying to use the endpoint I'm using in my request /api/card/:cardid/query/dataformat

As I've read on other threads I've tried using the developers tools and look at the request that's being sent, however, I don't seem to be able to send the date parameters right. I've copied and tried all of the formats I posted above.

As for the 'Content-Type': 'application/x-www-form-urlencoded' I saw it like that on the developers tool on the request I'm seding when trying to download a specific card's data

This is the error that I keep getting with any of the format for the date parameters that I've tried so far

@regularuser Okay, it makes more sense now.
Try using cURL to test, then you'll know if the request works - and then you'll have to change your code to match that.
If you look in your browser Network-tab, you'll see that the request sends the parameters in the body like so if you copy the Fetch:

"headers": { ... },
"body": "parameters=%5B%7B%22type%22%3A%22category%22%2C%22value%22%3A%2211-01-2021%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22start_date%22%5D%5D%7D%2C%7B%22type%22%3A%22category%22%2C%22value%22%3A%2211-11-2021%22%2C%22target%22%3A%5B%22variable%22%2C%5B%22template-tag%22%2C%22end_date%22%5D%5D%7D%5D",

@flamber thanks! copying the request as cURL and arranging my code around that ended up working for me

@regularuser Then it would be much appreciated if you would post your working code, so others can learn from it.

Sure no problem @flamber this is my request for downloading a JSON file from a specific card

    req = + f'/api/card/{card_id}/query/json',
                    headers={'Content-Type': 'application/x-www-form-urlencoded',
                             'X-Metabase-Session': TOKEN,
                             'CF-Access-Client-Id': Client_ID,
                             'CF-Access-Client-Secret': Client_Secret},
                    data={'parameters': '[{"type":"category","value":"11/14/2021","target":["variable",'

Thanks for all the help!

1 Like