Hello all,
I am struggling with a weird issue on the backend of my UI kit global page module application. My goal is to create a new project with the kanban template, then change the statuses of the project to a custom status list of my own choosing. I want to make a button that creates the new project and then edits the project using jira REST API calls. But my invocation is behaving as follows:
- if there is a bad request, the function is called only 1 time
- if request is good, it is called 2 times in succession, causing the second invocation to throw a conflicting task (error code 500) error
- Even though one of the 2 requests to make a project works, I get {size: 0, timeout: 0} when i log the output. Almost seems like the await function is not actually waiting for the function to complete, which in turn is causing my create statuses function to fail as well
The issue is not my useState hooks causing a re-render. I checked this and can confirm nothing is being re-rendered in this case.
Why is my invocation being called twice, and why am I getting an empty json response even for successful API calls?
Frontend function
const fetchData = async () => {
const project = await invoke('project');
console.log(project);//always returns {size: 0, timeout: 0}
console.log(project.id);//always returns undefined
};
Frontend button component
<Button shouldFitContainer onClick={async() => { //tried calling synchronously as well.
await fetchData()
}}>make new project</Button>
Resolver function
resolver.define('makeProject', async ({ payload }) => {
var bodyData = `{
"key": "ECV",
"leadAccountId": "557058:0867a421-a9ee-4659-801a-bc0ee4a4487e",
"name": "Engineering Test23",
"projectTemplateKey": "com.atlassian.jira-core-project-templates:jira-core-simplified-project-management",
"projectTypeKey": "business"
}`;
try {
console.log('inside the resolver')
const response = await api.asUser().requestJira(route`/rest/api/3/project`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
});
if (response.ok) {
console.log('Project created successfully.');
} else {
const errorData = await response.json();
console.error(`Failed to create project: ${response.status} ${response.statusText}`, errorData);
}
return response
} catch (error) {
console.error('Error creating project:', error);
return null
}
})