Content
You are here:
Create work package through API
Added by M. Glüsenkamp about 8 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)
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:Best,
Oliver
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