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.