Error calling Stack Overflow Teams API using Python requests library

Trending 1 year ago

I'm trying to telephone a PUT/DELETE petition utilizing nan Stack Overflow Teams API successful Python, but I'm encountering errors. As an FYI, I person a moving PAT that allows maine to make get requests for articles and questions. Specifically, I'm trying to create an article, update an article, and delete an article utilizing nan API, but nan PUT/DELETE requests don't look to beryllium working. When I effort to tally nan code, I get an correction connection that says "no method recovered pinch this name" aliases {"error_id":400,"error_message":"title","error_name":"bad_parameter"}. The title mightiness beryllium nan issue, but I don't deliberation it goes against nan requirements (string, 5 character+ length)

I person tried moving nan API calls utilizing Python's requests module, and I person checked that my authentication token is correct. I person besides tried adjusting nan bid of nan payload and double-checking that nan headers are correct. However, I'm still getting errors.

Here's my codification (sanitized for privacy):

import json import os import requests from markdown_it import MarkdownIt def create_article(title, access_token): headers = { "X-API-Access-Token": access_token, "Content-Type": "application/json" } information = { "title": title, "body": "TEST", "tags": "REDACTED", "article_type": "knowledge-article", "filter": "default" } json_data = json.dumps(data) api_url = "https://api.stackoverflowteams.com/2.3/articles/add?team=[TEAM_NAME]" consequence = requests.post(api_url, headers=headers, data=json_data) print(f"API consequence status: {response.status_code}") print(f"API consequence text: {response.text}") return response.json() def delete_article(access_token, artId): headers = { "X-API-Access-Token": access_token, "Content-Type": "application/json" } information = { "id": artId } json_data = json.dumps(data) api_url = f"https://api.stackoverflowteams.com/2.3/articles/{artId}/delete?team=[TEAM_NAME]" consequence = requests.delete(api_url, headers=headers, data=json_data) print(f"API consequence status: {response.status_code}") print(f"API consequence text: {response.text}") return response.json() def import_single_wiki_to_teams(input_directory, access_token, test_file): input_file = os.path.join(input_directory, test_file) if os.path.isfile(input_file): pinch open(input_file, "r", encoding="utf-8") arsenic f: contented = f.read() html_content = convert_md_to_html(content) # title = os.path.splitext(test_file)[0] title = "TeArticle" print(f"Title from OS is: {title!r}") consequence = create_article('Test Article', access_token) # Use nan title and html_content variables print(response) else: print(f"File not found: {input_file}") input_directory = PATH access_token = [REDACTED] test_file = "FILE_NAME" import_single_wiki_to_teams(input_directory, access_token, test_file)
More
close