Thanks for your reply
I’m using this automation, It works very well, as long as the link doesn’t exceed 100 characters. If it does, it returns as non-existent, even though there is a topic with that link.
async def search_discourse_topic(session, link):
headers = {"Api-Key": USER_API_KEY, "Api-Username": USER_ID}
cleaned_link = clean_url(link) # Limpa o URL fornecido para garantir consistência
try:
log(f"Searching for topic with link: {cleaned_link}") # Log quando inicia a pesquisa
async with session.get(f"{DISCOURSE_API_URL}/search.json", headers=headers, params={"q": cleaned_link}) as response:
search_results = await response.json()
topics = search_results.get("topics", [])
if not topics:
log(f"No topics found for link: {cleaned_link}") # Log se não encontrar resultados
for topic in topics:
if cleaned_link in topic.get("blurb", ""): # Checa se o link aparece na descrição do tópico
log(f"Found existing topic with link: {cleaned_link}") # Log se um tópico correspondente for encontrado
return topic["id"]
except Exception as e:
log(f"Error searching for topic with link: {e}")
return None