Top Menu

Jump to content
    Modules
      • Projects
      • Activity
      • Work packages
      • Gantt charts
      • Calendars
      • Team planners
      • Boards
      • News
    Home
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Enterprise support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?

      or sign in with your existing account

      OpenProject ID Google

Side Menu

Collapse project menu

  • Overview
  • Activity
    Activity
  • Roadmap
  • Work packages
    Work packages
  • Gantt charts
    Gantt charts
  • Calendars
    Calendars
  • Team planners
    Team planners
  • Boards
    Boards
  • News
  • Forums

Content

Expand project menu
Development
  1. OpenProject Community
  2. OpenProject
  3. Forums
  4. Development
  5. Create work package through API

Create work package through API

Added by M. Glüsenkamp almost 9 years ago

Hi,

I tried to create a work package though the API by using the following link as POST request:

https://openproject.xxx/api/v3/projects/testprojekt/work_packages

I used the following body:

{"subject": "test", "status": „new“, "type": „bug“, "description": {"format": "textile", "raw": "asd"}}

But unfortunately I get the following error:

{
  "_type": "Error",
  "errorIdentifier": "urn:openproject-org:api:v3:errors:MultipleErrors",
  "message": "Einschränkungen für mehrere Felder wurden verletzt.",
  "_embedded": {
    "errors": [
      {
        "_type": "Error",
        "errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",
        "message": "Typ muss ausgefüllt werden.",
        "_embedded": {
          "details": {
            "attribute": "type"
          }
        }
      },
      {
        "_type": "Error",
        "errorIdentifier": "urn:openproject-org:api:v3:errors:PropertyConstraintViolation",
        "message": "Typ ist nicht auf einen erlaubten Wert gesetzt.",
        "_embedded": {
          "details": {
            "attribute": "type"
          }
        }
      }
    ]
  }
}

What’s my fault? I’m very sure that the type is correct.
I’m using OpenProject 6.

Thanks for help!


Replies (2)

RE: Create work package through API - Added by Oliver Günther almost 9 years ago

Hi,

your request is not correct. Please compare with the APIv3 guide: http://opf.github.io/apiv3-doc/#work-packages-work-packages-post

You’ll need to pass the type in the HAL _links section:

{  
  "_links": {
    "type": {
       "href": "/api/v3/types/1" // Change TYPE ID to your Bug type. Check /api/v3/types for available types
     },
     // Other LINKED attributes ... 
  },
  "subject": "Foobar",
   //  Other EMBEDDED attributes ... 
}

Best,
Oliver

RE: Create work package through API - Added by Otmane Azeroual over 8 years ago

Hi Oliver,

I tried to create with this code a work packages:

var xhr2 = new XMLHttpRequest();

var data = ‘{subject subject“,”description“: {”format“: ”textile“, ”raw“: ”My raw textile formatted description. Bye guys!“}, ”_links“: {”type“: {”href“:”/api/v3/types/1“, ”title“: ”Task“}, ”status“:{”href“:”/api/v3/statuses/1“}, ”priority“:{”href“:”/api/v3/priorities/8“, ”title“: ”normal“}, ”assignee“: {”href“: ”/api/v3/users/1"}}}}’;

xhr2.open(‘GET’, ‘mydomain/openproject/api/v3/projects/dsds/work_packages/’);
xhr2.setRequestHeader(‘API_KEY’, ‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx’);
xhr2.setRequestHeader(‘Content-type’, ‘application/json’);

xhr2.onreadystatechange = function() {
if (xhr2.readyState 4 && xhr2.status 200) {
console.log(xhr2.responseText);
}
console.log(xhr2.readyState + “-” + xhr2.status);
};

xhr2.send(data);

Still i only get readyState == 4 and status = 0 in the console. the user admin is existing.

Do you know what the problem is?

Thank you for your help!

Best regards
Otmane

  • (1 - 2/2)
Loading...