Symptoms
Having difficulty getting K2Services JSON calls to work
Diagnoses
I am trying to write an ajax call to get a lit of worklist items and am using the same piece of sample code that seems to be everywhere.
function GetWorklistItems() {
$.ajax({
url: "https://bne-k2-test.mcr.au/k2services/REST.svc/Worklist/Items?$format=JSON",
method: "GET",
dataType: "JSON",
cache: false,
crossDomain: false,
success: function (data) {
tasks = data
alert("Success!")
BuildWorklist()
},
error: function (data, error, status) {
alert("Error: " status)
alert("Error: probably authentication.")
}
})
}
However, it's always failing with an error (no error description returned).
Leaving Javascript behind for the moment, if I browse to the web service on our test server: https://bne-k2-test.mcr.au/K2Services/REST.svc/Task/Items?$format=json, I get nothing.
However, if I change the format to XML: https://bne-k2-test.mcr.au/K2Services/REST.svc/Task/Items?$format=xml, I get a result.
THEN, if I change the format back to json: https://bne-k2-test.mcr.au/K2Services/REST.svc/Task/Items?$format=json, I get a JSON file (as I should have done in the first place).
Are we looking at an authentication issue specifically with json requests?
Resolution
The pre-authenticate workaround has one limitation when working with AJAX - From what I can tell it only really works through Basic Authentication. When using integrated authentication, the browser should negotiate the redirects to and from IIS to do the authentication and that is where the bug is lying currently that must be fixed - It is returning a 502 error instead of 401 and thus the negotiation can't be done as it should.
I've attached an example of the workaround for pre-authentication using Basic Auth.
I have focused on using javascript as that was the example the client was requesting... There is a possibility of getting the pre-auth to work with C_, but not sure if this will be suitable . Let me know if I should assist with that.
There is another alternative - The k2Api (also known as WebApi) doesn't have the same problem the REST.svc endpoint has, and it should have all the methods necessary for worklist retrieval that you require - I have attached an example for this. The only problem with the K2Api is that there is no documentation about it - It is in the pipeline though.