i’m developing a jira service management app using connect and i’m trying to fetch the knowledge base articles, and it gives { ctx: {} } Authentication verification error (401): Could not find authentication data on request
eventhough with postman you can see that is working .
this is the route:
app.get('/hello-world', addon.authenticate(), async(req, res) => {
// Rendering a template is easy; the render method takes two params: the name of the component or template file, and its props.
// Handlebars and jsx are both supported, but please note that jsx changes require `npm run watch-jsx` in order to be picked up by the server.
try {
const httpClient = addon.httpClient(req); // Use provided httpClient
const { body } = await httpClient.get('/rest/servicedeskapi/knowledgebase/article?query="test"&highlight=true');
const articles = body.values;
res.json(articles);
console.log(articles);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Failed to fetch articles' });
}
res.render(
'hello-world.jsx', // change this to 'hello-world.jsx' to use the Atlaskit & React version
{
title: 'Atlassian Connect'
//, issueId: req.query['issueId']
//, browserOnly: true // you can set this to disable server-side rendering for react views
}
);
});
and this is the jsx
import SectionMessage, { SectionMessageAction } from '@atlaskit/section-message';
import React from 'react';
import { useState, useEffect } from 'react';
import axios from 'axios';
export default function HelloWorld() {
const [excitementLevel, setExcitementLevel] = React.useState(0);
const [articles, setArticles] = useState([]);
useEffect(() => {
const fetchArticles = async () => {
try {
const response = await axios.get('/get-articles');
setArticles(response.data);
} catch (error) {
// Handle errors appropriately
}
};
fetchArticles();
}, []);
return <SectionMessage
title={` Hello najah this is for test, ${excitementLevel ? new Array(excitementLevel).fill('!').join('') : '.'}`}
actions={
<>
<SectionMessageAction key="1" href="https://atlassian.design/components/">
Browse more components to add to your app
</SectionMessageAction>
<SectionMessageAction key="2" onClick={() => setExcitementLevel(excitementLevel + 1)}>
Get excited!
</SectionMessageAction>
</>
}
>
<p>
Congratulations! You have successfully created an Atlassian Connect app using the <a href={'https://bitbucket.org/atlassian/atlassian-connect-express'}>atlassian-connect-express</a> client library.
</p>
<p>
Congratulations on creating your app!
{articles.length > 0 ? (
<React.Fragment>
<h2>Knowledge Base Articles</h2>
<ul>
{articles.map(article => (
<li key={article.title}>{article.excerpt}</li>
))}
</ul>
</React.Fragment>
) : (
<p>No articles found.</p>
)}
</p>
</SectionMessage>;
}
and the atlassian connect json
{
"key": "my-app",
"name": "My app",
"description": "My very first app",
"baseUrl": "{{localBaseUrl}}",
"authentication": {
"type": "jwt"
},
"lifecycle": {
"installed": "/installed"
},
"scopes": [
"READ","WRITE"
],
"apiMigrations": {
"signed-install": true
},
"modules": {
"serviceDeskPortalHeaders": [
{
"key": "hello-world-sd-portal-header",
"url": "/hello-world"
}
]
}
}