Create issue using Enonic API


#1

Enonic version: 6.15
OS: Windows 10

I need create a issue in Enonic inside a Task. To make this, I thought of call the Enonic API service to create an issue. The path to the service is: http://localhost:8080/admin/rest/issue/create
My doubt is if this is possible, because this code not work (return code 403).

var response = libs.httpClientLib.request({
      url: 'http://localhost:8080/admin/rest/issue/create',
      method: 'POST',
      headers: {
        'Authorization': 'Basic ' + Base64.encode('su:password'),
        'Accept': 'application/json'
      },
      contentType: 'application/json',
      body: {
        title: "Issue title",
        description: "Issue description",
        approvers: [systemUser],
        publishRequest: {
          excludeIds: [],
          items: []
        }
      }
    })

#2

I don’t think this should work - you cannot expect to get authorised by just sending a password in a header with API request.

request method of the Http client lib has auth parameter which is specifically designed to be used for basic authentication. Please read the docs here.

Also, even though the docs state that body can be either string or an object, it didn’t work when I used plain object - I had to stringify it. We’ll check why this happens.

Here’s the working example:

var result = httpClient.request({
    url: 'http://localhost:8080/admin/rest/issue/create',
    method: 'POST',
    headers: {
        'Accept': 'application/json'
    },
    auth: {
        user: 'su',
        password: 'password'
    },
    contentType: 'application/json;charset=UTF-8',
    body: JSON.stringify({
        title: "Issue title",
        description: "Issue description",
        approvers: [],
        publishRequest: {
            excludeIds: [],
            items: []
        }
    })
});

#3

Thanks for your answer. I tested add this parameter auth in my request, but the response still is 403. =/


#4

Do you have su user in your system with password ‘password’?


#5

The admin REST API is not documented and intended for use by 3rd party apps. If you need to create issues, use the Java API or a library if there is one.


#6

http://repo.enonic.com/public/com/enonic/xp/docs/6.15.2/docs-6.15.2-javadoc.zip!/com/enonic/xp/issue/package-summary.html


#7

@ase Yes, i have

@Jonas Good ideia. I had not thought to go down this way. Thanks.