Perhaps this Default Http Request Headers is expecting the value in the following format:
{
"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader[], SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null",
"$values":[
{
"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null",
"Name":"Authorization",
"Value":"Bearer Y249emFsaTAzLG91PXVzZXJzLG89ZGF0YTpQQDU1d29yZA=="
}
]
}
Without line-breaks:
{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader[], SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","$values":[{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","Name":"Authorization","Value":"Bearer Y249emFsaTAzLG91PXVzZXJzLG89ZGF0YTpQQDU1d29yZA=="}]}
This is an array of HTTP Headers with one for the Authorization Header.
I believe the System Type will also have an 'HTTPHeader' Service Object/SmartObject that can be used to build the string format above; if an array of HTTP Headers are needed.
Based on this post:
http://community.k2.com/t5/K2-blackpearl/unable-to-deserialize-value-httpheader/td-p/97787
Thank You Tin,
Formatting was the issue as i was using the sample token format provided at the below link
https://help.k2.com/onlinehelp/k2blackpearl/userguide/4.7/default.htm#ServiceBrokers/EndPoints/REST_Endpoint.htm
I updated the token as per the format you have given and it worked like a charm...
Thanks Again,
Afternoon everyone. We have a business need as well to utilize the K2 REST service to call an external cloud based system (SnapLogic) API. We have been able to successfully call/run the SnapLogic API using RESTUnited and Postman pasing in the bearer token, etc. From RESTUnited we created the swagger file and successfully created the REST service and SMO in K2 using the proper format as discussed previously in this thread. However when we run the SMO we get a 401 unauthorized error. Can anyone help me understand why I might be getting this error and what to look into to determine how to address it?
Thanks,
Steve
You will need to edit the REST service instance, and pass in the Bearer token in the XML structure below to the "Default HTTP Request Headers":
{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader[], SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","$values":[{"$type":"SourceCode.SmartObjects.Services.Endpoints.Common.HttpHeader, SourceCode.SmartObjects.Services.Endpoints.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null","Name":"Authorization","Value":"Bearer Y249emFsaTAzLG91PXVzZXJzLG89ZGF0YTpQQDU1d29yZA=="}]}
* of course replacing the placeholder bearer token in the example
Thank you so much for the response. However, we had done exactly what you are suggesting but it is still giving the 401 error. Thoughts?
Are you able to invoke the same web service successfully via Postman or SOAPUI? Perhaps this will provide more details as to what else may be needed.
Perhaps the web service is expecting multiple headers and not just the Authorization header.
CORS may play a role in web service requests.
Perhaps Fiddler or logs on the web service side of thing can determine what is missing in a SmartObject request vs a successful request via custom code/postman/soapui.
Thanks Tin for the response. It does successfully work using PostMan and RESTUnited. I have a K2 support anlayst who is working on it with me (I hope). I had a working session with them the other day and we were just seeing some weird behavior with the http response codes, initially it was a 401, then a 404 then it started coming back with 0. We did run a fiddler trace and he is reviewing it now as well as following up with some colleagues to try and figure out what might be going in. I will keep this post informed once I find out.
By the way, what is COR?
Thanks,
Steve
Cross-Origin Resource Sharing (CORS)
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
However if the same web service call is successful from PostMan/RESTUnited; then it is *likely* not CORS.
Hello Everyone. I wanted to follow up on this thread to make sure I let everyone know the issue I was running into in case someone else runs into this. So, besides the format of the "Default HTTP Request Headers" field being properly formatted (no carriage returns/line feeds, all one string) per the original post, the issue I was running into was having spaces in my endpoint URL. So for example I had an endpoint that look like the following:
https://my.endpoint.com:999/api/1/rest/slsched/feed/ECDev/projects/Canvas%20Term%20Pipeline%20Task
I kept receiving Response codes of 401, 404 and 0 when executing the smartobjects based on this Service.. This indicated something wrong with the Endpoint or how K2 was accessing the Endpoint. The issue is actually related to having Spaces in the Endpoint. K2 tries to encode these spaces, but the URL has already been encoded with space characters being "%20". K2 Picks up the % sign and encodes it again to be %25. The work-around was to make sure our naming conventions had no spaces and then K2 was able to parse it properly. I submitted this as an idea for fixing per K2 support request.