Update a card via api

Hi there.
I am a new to API, and my question maybe very simple but i’am stuck.
I am experimenting with posting and updating a card. I can post a card, this is the code of it from the Chrome Inspection tab image

Now I want to update its query. I write

url_mb_cards = 'https://metabase-analytics.evotor.ru/api/card/:652'
request = {
  "visualization_settings": {},
  "description value": "A card generated by the API_native",
  "collection_position": None,
  "result_metadata": None,
  "metadata_checksum": None,
  "collection_id": None,
  "name": "API-generated question_native",
  "dataset_query": {
    "database": 2,
    "native": {
      "query": query,
      "template-tags": {}    
    "type": "native"
  "id": 652,
  "display": "table"
response_api_put = requests.put(url_mb_cards, headers=headers, json=request)

and receive <Response [404]>
API endpoint does not exist.

I’m using the id which I see in Chrome, endpoint according to the docs is PUT /api/card/:id. What I’m missing?

Hi @glamps_evo

Every instance of :id (or similar), should be replace with the value without the colon.
So that would be PUT /api/card/652.

I don’t know which scripting language you’re using, but most other languages uses null or nil instead of None. And most of the time, you don’t need to send those parameters, if they are empty.

The best way to learn the API, is to just use Metabase while having your browser developer Network-tab open and looking at the request, and what data is being send/received.
And right-click on the requests to copy them as a Fetch or cURL command.

Just for reference:

Hi, flamber!
Thank you very much for answer and explanations. I thought that smth that should be replaced is put into {}, so didn’t understand this notation. I use Python, and tried nul and null, but only None worked correctly.

Iэму read the documentation and also use the browser developer tool, but maybe you know some materials for those, for whom API is a completely new instance - some good basic materials, where all notations and conventions are explained?

@glamps_evo I would recommend that you search the internet for general help. But you might learn more by looking at existing projects, example: https://github.com/vvaezian/metabase_api_python

I have inspected the network tab and tried to make a PUT request using POSTMAN, however getting a server 500 error. I only want to update the y-axis scale max value, should I be sending the payload only for viz settings or the entire payload as seen in the network tab (and if so, what is the format required.. I am getting this error in the return message:
Input to column-will-change? does not match schema:...
Using the same schema as the browser developer tools shows however - exact same message)

@ChristineChetty You should send everything as the you see in the request done through the UI.
Something must be different if you're getting errors, when you create your own request.
Post what you're sending.

This is what I'm sending:

removed request due to sensitive information.

@ChristineChetty Pretty sure that almost every request uses Content-Type: application/json

Here's a tip. In the browser developer Network-tab, right-click on the requests and it give you an option to copy as cURL or Fetch, which shows exactly what it does.

1 Like

Thanks so much! That worked perfectly. I think it was Content-Type: application/json that needed to be included mostly.