Trying to write a custom code to fetch the knowledge base articles from our JSM

Trrying to write a custom code to fetch the knowledge base articles from our JSM . We tried using details at https://developer.atlassian.com/cloud/jira/service-desk/rest/api-group-knowledgebase/#api-rest-servicedeskapi-knowledgebase-article-get but it is not working for us . WE keep on getting {
“error”: “Failed to parse Connect Session Auth Token”
}

Hi @kompalsithta. Welcome to the developer community.

How are you calling the API? (ex: from a Forge app, a Connect app, or maybe just from a REST client like Postman)

Hi @nmansilla ,

I am using the REST call and using python for the same.

This is my code:

import requests
import json

url = "https://id.atlassian.net/rest/servicedeskapi/knowledgebase/article?query='test'"


headers = {
  "X-ExperimentalApi": "opt-in",
  "Accept": "application/json",
  "Authorization": "Bearer XXXXXXXXX"
}

response = requests.request(
   "GET",
   url,
   headers=headers
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

@kompalsithta,

Unfortunately, the REST API reference docs “lie” about how to authenticate. To be precise, the docs do not adequately represent the multiple ways which code might need to authenticate. If you are using Python, I assume you’ll want to pair that with an API token and use Basic authentication.

For Python requests, the following snippet replaces the current headers and response statements:

headers = {
  "X-ExperimentalApi": "opt-in",
  "Accept": "application/json",
}
basic = HTTPBasicAuth(USER_EMAIL, USER_API_TOKEN)
response = requests.request(
   "GET",
   url,
   headers=headers,
   auth=basic,
)

Note: The Bearer header is not correct for this method of auth; hence, removed. And the USER_EMAIL and USER_API_TOKEN variables must be initialized in prior statements.

1 Like