How to Create an Issue and send all the data to a custom Form using the API | Community
Skip to main content
f3rch0
November 6, 2023
Solved

How to Create an Issue and send all the data to a custom Form using the API

  • November 6, 2023
  • 1 reply
  • 1310 views

I would like to send all the data to an Issue in a project but this issue has a custom form. I need to fill in all the fields with the data that I am sending through the API. THANK YOU FOR ANY HELP!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by f3rch0

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!

 

1 reply

lgaertner
Level 9
November 6, 2023

Hi f3rch0,

 

You need to do a POST request to the endpoint OPTASK/<issueID> and put the field names and their values into the payload.

 

payload: { 'DE:firstFieldName': 'firstFieldValue', 'DE:secondFieldName': 'secondFieldValue', }

 

Regards

Lars

f3rch0
f3rch0Author
November 6, 2023

Thank you for your answer @lgaertner, but what i am trying to do is to create a new issue, select the custom form, and send all the values to fill the field of the custom form. Is it possible?, or do I have to create the issue and select the custom form first? and after that, do i have to create another request to send the values for the custom form?

f3rch0
f3rch0AuthorAccepted solution
November 7, 2023

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!