Sunday, 24 November 2019

Getting "415 Unsupported Media Type" when trying to create Hpalm defect using rest api

I'm trying to create a defect using hpalm rest api but I always get "415 Unsupported Media Type"

Here is what I have tried so far:

var postOptions = {
    jar: cookies, // <-- contains all recieved cookies from authentification
    accept: 'application/json',
    'Content-Type': 'application/xml',
    url: almHost + '/rest/domains/' + domain + '/projects/' + project + '/defects',
    body: data
};

request.post(postOptions, function (error, response, body) {
    if(error) return reject(error);
    else resolve(response);
});

Here is the data I'm sending through body:

var data = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'
+ '<Entity Type="defect">'
    + '<Fields>'
        + '<Field Name="user-06">'
        +     '<Value>MD-4493LS</Value>'
        + '</Field>'
        + '<Field Name="name">'
        +     '<Value>Test with reference 2021</Value>'
        + '</Field>'
        + '<Field Name="description">'
        +     '<Value>description</Value>'
        + '</Field>'
        + '<Field Name="priority">'
        +     '<Value>Medium</Value>'
        + '</Field>'
        + '<Field Name="severity">'
        +     '<Value>Critical</Value>'
        + '</Field>'
    + '</Fields>'
+ '</Entity>';

I don't know what's wrong with this code. The authentifiction works fine because I'm able to fetch Alm defects.

Can anyone help me please ?



from Getting "415 Unsupported Media Type" when trying to create Hpalm defect using rest api

No comments:

Post a Comment