Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating JIRA projects using REST API via CONFI- Forms

Chitra Koneti June 11, 2019

Hi, 

I created a confluence form with the respective fields that are required by the rest API for creating a project and used the Confi-form IFTTT macro to hit the Jira rest API. 

But the API is returning me the following error. Which I am unable to trace the error out.

Any help appreciated.

Error- Requested to https://jira.xxx.xxx.xxxx/rest/api/2/project/ has resulted in error. Response code = 400. Response contents: {"errorMessages":["Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@5a7effa0; line: 1, column: 2]"]}

When there is no body in the IFTTT macro (ie the JSON ) the error still persist.. 

2 answers

1 accepted

1 vote
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2019

Hi @Chitra Koneti ,

 

Can you kindly confirm you are following the instructions from Creating JIRA issue from Confluence with ConfiForms or  provide  more details in case you are doing something else?

 

Also, in case you are following the given documentation page, can you provide a screenshot showing the form configuration like, e.g., the last one from the above documentation page:

jira-form-def4

 

 

Cheers,
Dario

Chitra Koneti June 13, 2019

Hi Dario,

Thank you for your reply.   here is my form set up( for project creation in Jira)

I now have a new error as opposed to the previous one.

NOTE=  in the URL I am using my company's  url instead of Atlassian.com

ERROR : Response code = 400. Response contents: {"errorMessages":["Unrecognized field \"properties\" (Class com.atlassian.jira.rest.v2.issue.project.ProjectInputBean), not marked as ignorable\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1691071; line: 2, column: 20] (through reference chain: com.atlassian.jira.rest.v2.issue.project.ProjectInputBean[\"properties\"])"]}

snip 1.PNGsnip2.pngThis is my form. 

Thank you. 

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2019

Hi @Chitra Koneti ,

The project field does not exist for the rest/api/2/project endpoint and this is indeed what the returned error message is saying:

Unrecognized field \"properties\" 

 

For the list of the fields available for the endpoint please refer to the REST API documentation (below I am providing the link to the one for Jira Server 8.2.2 since it is the latest but you might be using a different version):

 

As you can see in the example in above page, the REST request body to create a project is:

{
    "key": "EX",
    "name": "Example",
    "projectTypeKey": "business",
    "projectTemplateKey": "com.atlassian.jira-core-project-templates:jira-core-project-management",
    "description": "Example Project description",
    "lead": "Charlie",
    "url": "http://atlassian.com",
    "assigneeType": "PROJECT_LEAD",
    "avatarId": 10200,
    "issueSecurityScheme": 10001,
    "permissionScheme": 10011,
    "notificationScheme": 10021,
    "categoryId": 10120
}

 

Please remove the properties field from your request body (and the related curly brackets) and let us know if this works.

 

Cheers,
Dario

Chitra Koneti June 14, 2019

Hi Dario,

Yes, It did work thank you :)

I am able to create projects in JIRA

I also wanted a suggestion the new project key that user's enter for creating projects needs to be validated with the existing keys in Jira and then only allow the user's to create the project. We currently have two instances of Jira and the new key that users are entering needs to be validated with both these instances. Any approach on how this can be achieved in the Confi-form field( I know there is Jira Rest API called projectvalidate that does validate the keys in Jira). How can I hit two instances with a single API call?

 

Regards,

Chitra.K

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2019

Hi @Chitra Koneti ,

I can help on REST API related topics but, to be honest, I have never used this app and I am not sure if/how this can be achieved.

 

Maybe @Alex Medved _ConfiForms_  can help here (I don't know him personally but I see him answering the most of the Confi-Form questions in here).

 

Another option is to create a support request with Confi-Form vendor and ask this question to them: https://wiki.vertuna.com/x/S4GW

 

Have a nice weekend! 

Dario

Alex Medved _ConfiForms_
Community Champion
June 14, 2019

Consider the following example that checks the project by key and if exists then validation fails on form submit

<ac:structured-macro ac:macro-id="8a0b8799-0bc6-4951-8b01-f8b1b82f039f" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">f</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="4b5126e6-9e1a-4056-acb3-be0a9186bf2c" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:parameter ac:name="registrationMessage">all good, thanks</ac:parameter>
<ac:parameter ac:name="embedded">true</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p>
<ac:structured-macro ac:macro-id="b03b9b34-c309-43b4-81fc-786cba15af29" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">projectkey</ac:parameter>
<ac:parameter ac:name="fieldLabel">project key</ac:parameter>
<ac:parameter ac:name="type">text</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="4af34e00-5211-4e73-9781-72bd516def68" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">existingProject</ac:parameter>
<ac:parameter ac:name="fieldLabel">Existing project</ac:parameter>
<ac:parameter ac:name="type">hidden</ac:parameter>
</ac:structured-macro>
</p>
<p>
<br/>
</p>
<p>
<ac:structured-macro ac:macro-id="f0723296-1f1f-4977-a65a-b392ef39fd2f" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="fieldName">existingProject</ac:parameter>
<ac:parameter ac:name="action">Reset value</ac:parameter>
<ac:parameter ac:name="actionFieldName">projectkey</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="4d1674a6-bb7e-4299-a875-963f6b2db61d" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">!projectkey:[empty]</ac:parameter>
<ac:parameter ac:name="fieldName">existingProject=[entry.key]</ac:parameter>
<ac:parameter ac:name="noPropagation">true</ac:parameter>
<ac:parameter ac:name="values">/rest/api/2/project/[entry.projectkey]</ac:parameter>
<ac:parameter ac:name="action">Lookup and set WS value</ac:parameter>
<ac:parameter ac:name="actionFieldName">projectkey</ac:parameter>
<ac:parameter ac:name="values2">4bb4c41a51f289a07507d50a1b841a4d</ac:parameter>
</ac:structured-macro>
</p>
<p>
<br/>
</p>
<p>
<ac:structured-macro ac:macro-id="ca0a4063-bdf2-4714-a69c-a0e30a9a7adb" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">!existingProject:[empty]</ac:parameter>
<ac:parameter ac:name="fieldName">Project with given key already exists</ac:parameter>
<ac:parameter ac:name="action">Validation rule</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
Like # people like this
Chitra Koneti June 16, 2019

@Dario B  Thank you for the responses. Appreciate them

@Alex Medved _ConfiForms_ 

Hi Alex,

Thank you for reaching out.

As far as I see( correct me if I am wrong ) this validate the project keys in a single instance of JIRA.

Our project has two instances of Jira( business users and developers) and we were looking for a way wherein the new projects that are being created have to be validated with both these instances so that we do not have key duplication in these instances. Do you think if this achievable in a confluence field?

 

Regards,

Chitra.K

Alex Medved _ConfiForms_
Community Champion
June 17, 2019

Well, the example shows how to do what you want, and you can extend it to cover additional requirements, right?

Just make another rule that does a similar lookup against the other jira and that shall do the trick.

Chitra Koneti June 17, 2019

@Alex Medved _ConfiForms_ 

Awesome. I'll give it a go.

Thank you for reaching out.

 

Regards,

Chitra.K

Chitra Koneti June 25, 2019

@Alex Medved _ConfiForms_ 

I had another question regarding the following. Just like the project key is there any way can we validate the project name with the existing project name's?. Because the API throws an error when you enter an existing project name when creating a project. Any API that you could suggest because I didn't seem to find one?

Chitra Koneti June 26, 2019

@Alex Medved _ConfiForms_ Okay. so do you think just using a similar approach like validating the project key with the above API  you showed able to do the work?

Alex Medved _ConfiForms_
Community Champion
July 1, 2019

Well, yes, I do - I think it should work and why it should not!? However, you shall understand that the user who makes the request must have enough permissions to search across ALL the projects.

 

Have you tried to implement this API call? 

Chitra Koneti July 1, 2019

@Alex Medved _ConfiForms_ 

Yes, I did, But it isn't working for me. I'm not sure if I am doing something because I'm pretty new to confluence. This is my code 

<ac:structured-macro ac:macro-id="8a0b8799-0bc6-4951-8b01-f8b1b82f039f" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">project name</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:macro-id="4b5126e6-9e1a-4056-acb3-be0a9186bf2c" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:parameter ac:name="registrationMessage">Project Name Available</ac:parameter>
<ac:parameter ac:name="embedded">true</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
<p>
<ac:structured-macro ac:macro-id="0d9eef86-2355-455f-be7f-8b4e2fb451dd" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">projectname</ac:parameter>
<ac:parameter ac:name="fieldLabel">project name</ac:parameter>
<ac:parameter ac:name="type">text</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="edc11d5e-d612-4d19-93c0-66bd020b0be3" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">existingProject</ac:parameter>
<ac:parameter ac:name="fieldLabel">Existing project</ac:parameter>
<ac:parameter ac:name="type">hidden</ac:parameter>
</ac:structured-macro>
</p>
<p>
<br/>
</p>
<p>
<ac:structured-macro ac:macro-id="c2b3d97c-5c9b-4bdc-a6f6-423a6c7ca0cc" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="fieldName">existingProject</ac:parameter>
<ac:parameter ac:name="action">Reset value</ac:parameter>
<ac:parameter ac:name="actionFieldName">projectname</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="3e744b18-694c-4a62-ac4f-0651f8225c1f" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">!projectname:[empty]</ac:parameter>
<ac:parameter ac:name="fieldName">existingProject=[entry.total]</ac:parameter>
<ac:parameter ac:name="noPropagation">true</ac:parameter>
<ac:parameter ac:name="values">/rest/api/2/search?jql=project="entry.projectname]"</ac:parameter>
<ac:parameter ac:name="action">Lookup and set WS value</ac:parameter>
<ac:parameter ac:name="actionFieldName">projectname</ac:parameter>
<ac:parameter ac:name="values2">428bc26f2dfde0f62fb131dc284e7aca</ac:parameter>
</ac:structured-macro>
</p>
<p>
<br/>
</p>
<p>
<ac:structured-macro ac:macro-id="9a708571-5563-4128-856d-a5898c5164d4" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">!existingProject:[empty]</ac:parameter>
<ac:parameter ac:name="fieldName">Project with given name already exists</ac:parameter>
<ac:parameter ac:name="action">Validation rule</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>

 

I tried to set existingProject = total as my WS value just like you set to key value from the API response assuming it to be that. 

Search API response: 

{ "expand": "names,schema", "startAt": 0, "maxResults": 50, "total": 1, "issues": [ { "expand": "", "id": "10001", "self": "http://www.example.com/jira/rest/api/2/issue/10001", "key": "HSP-1" } ] }

 I'm still unsure if this is the API I need to use because this API Searches for issues using JQL. 

Thank you for reaching out. 

Alex Medved _ConfiForms_
Community Champion
July 2, 2019

What does not work for you? I don't understand... If you search for a "non existing" project then you will not get back the same structure, and which is perfectly fine.

As, as long as you get a value in total field then you can make a conclusion that the project exists.

0 votes
Chitra Koneti June 14, 2019

The above solution did work 

 

Regards,

Chitra.K

Suggest an answer

Log in or Sign up to answer