Hi f3rch0,
I hope I do understand you right, but I am quite sure, that you have to do the whole thing in 3 steps as three endpoints are called.
1. Create a new issue (POST request to endpoint OPTASK)
2. Attach the custom form (PUT request to endpoint CATEGORY) using the following body:
{
"objID": "<issueID>",
"objCode": "OPTASK",
"categoryIDs": [
"<customFormID>"
]
}
3. fill custom fields (POST request to endpoint OPTASK/<issueID>)
Regards
Lars
Thank you @lgaertner .
What i did was:
const url = 'https://xxx.my.workfront.com/attask/api/v17.0';
const apiKey = 'xxx';
// Options
const optionsPost = {
method: 'POST',
headers: {
'Authorization': `Basic ${apiKey}`,
'Content-Type': 'application/json',
'username' : 'xxx@xxx.com',
'password' : 'xxx',
'apiKey' : `${apiKey}`,
},
body: JSON.stringify(
formObjectPost
),
};
const optionsPut = {
method: 'PUT',
headers: {
'Authorization': `Basic ${apiKey}`,
'Content-Type': 'application/json',
'username' : 'xxx@xxx.com',
'password' : 'xxx',
'apiKey' : `${apiKey}`,
},
body: JSON.stringify(
formObjectPut
),
};
const formObjectPost = {
'name': `Issue Name`,
'projectID' : 'xxx',
// CATEGORY ID = Form Id
"categoryID": "xxx",
'description': `${inputConfig.task}`,
'status': 'PLN',
'plannedStartDate': `${inputConfig.plannedStartDate}`,
'plannedCompletionDate': `${inputConfig.plannedCompletionDate}`,
'url': `${ inputConfig.brandURL }`,
}
const formObjectPut = {
// DEFAULT CUSTOM FORM SECTION
'DE:ExampleFieldName': `Example`
}
// POST Method
fetch(`${url}/optask/`, optionsPost)
.then(response => response.json())
.then(data => {
console.log('Task Created: ID' + data.data.ID);
// PUT Method Custom Form
fetch(`${url}/issue/${data.data.ID}`, optionsPut)
.then(response => response.json())
.then(updatedData => {
console.log('Task Updated: ', updatedData);
})
.catch(error => {
console.error('Error:', error);
});
})
.catch(error => {
console.error('Error:', error);
});
It is working correctly, but instead of having 3 steps, now I have 2. Thank you again!