What value should "raw-params" take in the Table API's "replace-csv" endpoint

Hi legends,

I'm testing the Metabase API and I'm eager to use the POST /api/table/:id/replace-csv endpoint. I would love some help understanding what is meant by raw-params in the API docs for that endpoint

I'll add my questions below and please also feel free to point me to any existing resources or links on this topic - I couldn't find any in my own searches in the Discourse community or in the GitHub issue tracker. The most relevant link I could find is the Pull Request that originally created the endpoint: Basic version of CSV replacement, with only basic testing by crisptrutski · Pull Request #40363 · metabase/metabase · GitHub

Questions:

  1. Are there any code samples/examples available for using this endpoint?
  2. Based on the PR linked above, it appears the raw-params relates to a request body that looks something like the below, but I can't get it to work. What's the correct structure for the raw-params argument?
    {
        "raw-params": {
            "file": "...contents of csv file...",
        }
    }
    
  3. Are the file contents supposed to be a literal CSV structure containing the full data as a string (i.e. no base64 encoding or anything), something like the below?
    {
        "file": "id,first_name,email\n1,Jo,jo@example.com\n2,Mary,mary@example.com",
    }
    

Thanks in advance for any help you can offer and please let me know if there is any extra clarity I can add!

hey I haven't used this endpoint (yet), but have you seen how the browser does the calls to the backend to try to understand what's going on?

1 Like

@coreym

In case this helps anyone else.
It's a multi-part/form POST call so you can try something like the following:

curl -X POST http://yourmetabaseapp.com/api/card/from-csv
-H "X-API-KEY: YOUR_API_KEY"
-F "file=@/path/to/your/file.csv"
-F "collection_id=4" ← whatever collection ID you want to use

If that works, you should be able to adapt it to whatever ecosystem/language.

I have been wrestling with this issue for a couple of months now, it's driving me insane.
Trying to make this endpoint work in Microsoft Power Automate's HTTP connector. I am still having conversation with the support team for almost three weeks now.

Screenshot 2025-01-29 083056
Everytime I thought it would work, I got hit with error code 413. This particular error is from trialing your first argument @coreym

{
    "uri": "metabase",
    "method": "POST",
    "headers": {
        "x-api-key": "Key",
        "Content-type": "multipart/form-data"
    },
    "retryPolicy": {
        "type": "None"
    },
    "body": {
        "raw-params": {
            "file": "No,Name,Location\r\n1,Andy,SYD\r\n2,Barry,SYD\r\n3,Christie,MEL\r\n4,Daniel,PER\r\n5,Ezekiel,BRI\r\n6,Fabio,DAR\r\n7,Gertrude,CAN\r\n8,Harry,CAN\r\n9,Ian,MEL\r\n10,Jordan,ADE\r\n"
        }
    }
}
{
	"info": {
		"_postman_id": "0b3e62e0-17ee-4b5e-8dc4-2ed4de0d42cf",
		"name": "Metabase CSV",
		"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
		"_exporter_id": "32404562"
	},
	"item": [
		{
			"name": "append csv",
			"protocolProfileBehavior": {
				"disabledSystemHeaders": {
					"accept-encoding": true,
					"accept": true
				}
			},
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Content-Type",
						"value": "multipart/form-data",
						"type": "text",
						"disabled": true
					}
				],
				"body": {
					"mode": "formdata",
					"formdata": [
						{
							"key": "file",
							"type": "file",
							"src": "/C:/Users/**"
						},
						{
							"key": "Content-Type",
							"value": "text/csv",
							"type": "text",
							"disabled": true
						}
					]
				},
				"url": "{{url}}/api/table/36/append-csv"
			},
			"response": []
		},
		{
			"name": "replace-csv",
			"protocolProfileBehavior": {
				"disabledSystemHeaders": {
					"accept-encoding": true,
					"accept": true
				}
			},
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Accept",
						"value": "application/json",
						"type": "text",
						"disabled": true
					},
					{
						"key": "Content-Type",
						"value": "multipart/form-data",
						"type": "text",
						"disabled": true
					}
				],
				"body": {
					"mode": "formdata",
					"formdata": [
						{
							"key": "file",
							"type": "file",
							"src": "/C:/Users/**"
						}
					]
				},
				"url": "{{url}}/api/table/36/replace-csv"
			},
			"response": []
		}
	],
	"auth": {
		"type": "apikey",
		"apikey": {
			"value": "{{apiKey}}",
			"key": "x-api-key"
		}
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"packages": {},
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"packages": {},
				"exec": [
					""
				]
			}
		}
	]
}

I forgot to attach this JSON of working Postman collection I received from the support desk.
I cannot transform this into proper "raw-params" for a web request.
@coreym

Hi @coreym

image

{
    "uri": "{{uri}}/api/table/133/replace-csv",
    "method": "POST",
    "headers": {
        "x-api-key": "{{apikey}}"
    },
    "retryPolicy": {
        "type": "None"
    },
    "body": {
        "$content-type": "multipart/form-data",
        "$multipart": [
            {
                "headers": {
                    "Content-Disposition": "form-data; name=\"file\"; filename=\"file.csv\""
                },
                "body": "No,Name,Location\n1,Andy,SYD\n2,Barry,SYD\n3,Christie,MEL\n4,Daniel,PER\n5,Ezekiel,BRI\n6,Ferry,ADE\n7,Gary,SYD\n8,Harry,SYD\n9,Ian,MEL\n10,Joko,PER\n11,Kallum,PER\n12,Liam,PER\n13,Manuel,MEL\n14,Noah,SYD\n15,Oren,SYD\n16,LOLNOWAY,BRI"
            }
        ]
    }
}

Above is the raw input of the HTTP web request

here is just the body

{
        "$content-type": "multipart/form-data",
        "$multipart": [
            {
                "headers": {
                    "Content-Disposition": "form-data; name=\"file\"; filename=\"file.csv\""
                },
                "body": "No,Name,Location\n1,Andy,SYD\n2,Barry,SYD\n3,Christie,MEL\n4,Daniel,PER\n5,Ezekiel,BRI\n6,Ferry,ADE\n7,Gary,SYD\n8,Harry,SYD\n9,Ian,MEL\n10,Joko,PER\n11,Kallum,PER\n12,Liam,PER\n13,Manuel,MEL\n14,Noah,SYD\n15,Oren,SYD\n16,LOLNOWAY,BRI"
            }
        ]
    }

I hope this helps you and others in the same path :grin: