Expand my Community achievements bar.

SOLVED

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

Avatar

Level 1

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!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 1

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!

 

View solution in original post

4 Replies

Avatar

Level 10

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

Avatar

Level 1

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?

Avatar

Level 10

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

Avatar

Correct answer by
Level 1

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!