Skip to main content

Hi, i try to add a existing allready TAG to a item (Sticky Note)
But i get only the error:

 

enrico@Enricos-MacBook-Pro CPARTJIRA % python test.py
Making POST request to: https://api.miro.com/v2/boards/uXjVLOuSJng=/sticky_notes
Headers: {'Authorization': 'Bearer ********', 'Content-Type': 'application/json'}
Payload: {'data': {'content': 'TEST', 'shape': 'square'}, 'style': {'fillColor': 'light_yellow'}, 'geometry': {'width': 300}, 'position': {'x': 0, 'y': 0}}
Response status code: 201
Response JSON: Created successfully!
Sticky note created successfully with ID: 3458764604900078756
Making POST request to create tag: https://api.miro.com/v2/boards/uXjVLOuSJng=/tags
Headers: {'Authorization': 'Bearer ********', 'Content-Type': 'application/json'}
Payload: {'data': {'title': 'hallo', 'fillColor': 'blue'}}
Response status code: 400
Response JSON: {'type': 'error', 'code': '2.0703', 'context': {'fields': {'field': 'title', 'message': 'Field title] of type String] is required'}]}, 'message': 'Invalid parameters', 'status': 400}
Error creating tag: 400 {'type': 'error', 'code': '2.0703', 'context': {'fields': {'field': 'title', 'message': 'Field title] of type String] is required'}]}, 'message': 'Invalid parameters', 'status': 400}

Here the code of the testscript. The script add the Stickynote successfully, but not the TAG

 

import requests

# Miro API Token and Board ID
API_TOKEN = "TOP SECRET :-)"
BOARD_ID = "uXjVLOuSJng="
BASE_URL = f"https://api.miro.com/v2/boards/{BOARD_ID}"
HEADERS = {"Authorization": f"Bearer {API_TOKEN}", "Content-Type": "application/json"}

# Function to create a sticky note with debugging information
def create_sticky():
sticky_data = {
"data": {"content": "TEST", "shape": "square"},
"style": {"fillColor": "light_yellow"},
"geometry": {"width": 300},
"position": {"x": 0, "y": 0}
}
url = f"{BASE_URL}/sticky_notes"
print(f"Making POST request to: {url}")
print("Headers:", {"Authorization": "Bearer ********", "Content-Type": "application/json"})
print("Payload:", sticky_data)

response = requests.post(url, headers=HEADERS, json=sticky_data)
print("Response status code:", response.status_code)
print("Response JSON:", response.json() if response.status_code != 201 else "Created successfully!")

if response.status_code == 201:
sticky_id = response.json()("id"]
print("Sticky note created successfully with ID:", sticky_id)
return sticky_id
else:
print("Error creating sticky note:", response.status_code, response.json())
return None

# Function to create a tag and attach it to the sticky note with debugging
def create_and_attach_tag(sticky_id):
tag_data = {"data": {"title": "hallo", "fillColor": "blue"}}
tag_url = f"{BASE_URL}/tags"
print(f"Making POST request to create tag: {tag_url}")
print("Headers:", {"Authorization": "Bearer ********", "Content-Type": "application/json"})
print("Payload:", tag_data)

tag_response = requests.post(tag_url, headers=HEADERS, json=tag_data)
print("Response status code:", tag_response.status_code)
print("Response JSON:", tag_response.json() if tag_response.status_code != 201 else "Created successfully!")

if tag_response.status_code == 201:
tag_id = tag_response.json()("id"]
print("Tag created successfully with ID:", tag_id)

# Attach the tag to the sticky note
attach_url = f"{BASE_URL}/items/{sticky_id}/tags/{tag_id}"
print(f"Making POST request to attach tag to sticky note: {attach_url}")

attach_response = requests.post(attach_url, headers=HEADERS)
print("Response status code:", attach_response.status_code)
print("Response JSON:", attach_response.json() if attach_response.status_code != 204 else "Tag attached successfully!")
else:
print("Error creating tag:", tag_response.status_code, tag_response.json())

if __name__ == "__main__":
sticky_id = create_sticky()
if sticky_id:
create_and_attach_tag(sticky_id)

any idea how i can add a TAG to a exsisting item? I need that as i want to import automaticly a lot of cards or notes and add TAGS according to contect of the Item.

Hi - I’ve just tested this on my own and was able to do so just fine. I used a cURL command, but also just converted it to this Python code. Could you try this code and see if it works?

Note you will need to add in the boardId, itemId, tagId, and bearer token. 

 

import requests

url = "https://api.miro.com/v2/boards/<add-your-board-id>/items/<add-your-item-id>?tag_id=<add-your-tag-id>"

headers = {
"accept": "application/json",
"authorization": "Bearer <add-your-barer-token>"
}

response = requests.post(url, headers=headers)

print(response.text)


Hope this helps!


Yep its looks good and works. The thx a lot
 

I dont know why it was nit working  before, now i need to adapt that a bit to check before  if the TAG exsists and if not to create the TaG. My goal is to have in the end a fu ction with parameter BOARDID, ITEMID, TAGNAME (not TAG ID id possible which handle all that. 

lets see if i can manage that on my own somehow.


Reply