Skip to Content
0

401 Unauthorized unable to post to OData/ContentItems/$value using oAuth 1.0a

Dec 24, 2016 at 01:19 PM

241

avatar image

OAuth 1.0a Implementation

Called Below APIs from Using PHP OAuth Client and Generated Final Access token required to access the OData APIs

https://developer.sapjam.com/oauth/request_token

https://developer.sapjam.com/oauth/access_token

https://jam4.sapjam.com/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}≻ope={SCOPE}&state={STATE}

5)Got access token successfully J

6)We are able to access https://developer.sapjam.com/api/v1/OData/Groups API with this token using GET Method and got proper output.

curl -i -H 'Authorization: OAuth oauth_consumer_key="Vcw3vmcbmkkxDGK0TIAE",oauth_nonce="0e80f1e8ea4f4f99f087aa252b506c80",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1482514858",oauth_version="1.0",oauth_token="0jwXN0YGtPlNfIeh1UFTyRPosq8EuAkUL0m96hzA",oauth_signature="fjWgMqJtaVjyuCmhsITnGmLBNTY%3D"' -H 'Accept: application/json' -H 'Content-Type:application/json' -X GET https://developer.sapjam.com/api/v1/OData/Groups

Got Proper Group Json Output.

7)But when we access https://developer.sapjam.com/api/v1/OData/ContentItems/$value API using POST Method, We get below error message:

curl -i -H 'Authorization: OAuth oauth_consumer_key="Vcw3vmcbmkkxDGK0TIAE",oauth_nonce="103259f87946c582440a60bbb751b138",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1482514268",oauth_version="1.0",oauth_token="0jwXN0YGtPlNfIeh1UFTyRPosq8EuAkUL0m96hzA",oauth_signature="EVGmb90jnet4Z8IajK9b79XKXeY%3D"' -H 'Accept: application/json' -H 'Content-Type:image/png' -H 'Slug:thumbnail.png' -data-binary '@thumbnail.png' -X POST https://developer.sapjam.com/api/v1/OData/ContentItems/$value

Output of command is

P/1.1 401 Unauthorized
Date: Fri, 23 Dec 2016 17:31:11 GMT
Server: Apache
Cache-Control: no-cache
X-Request-Id: 894de4c4-88ad-4e7a-8e07-1614ceed30da
X-Runtime: 0.027372
X-CONTENT-TYPE-OPTIONS: nosniff
Strict-Transport-Security: max-age=63072000; includeSubdomains;
Status: 401 Unauthorized
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Invalid OAuth protected resource access request. OAuth authentication failed.

With Token Generated with SAME method “Group” API is working but “ContentItems” API is not working. We need SAP JAM Support to resolve this issue. We are not getting any help for this.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Adam Stone
Jan 05, 2017 at 06:04 PM
0

There is no POST option for /ContentItems(Id='', ContentItemType='')/$value. If you are first creating a new content item, you would do a POST to /ContentItems or /Group('Id')/ContentItems. If you want to upload a new version of an existing document, you would be calling PATCH on /ContentItems(Id='', ContentItemType='')/$value

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Adam,

I have tried the below given solution for POST and now we are able to POST contentItem. But now we are facing another issue with PATCH method. After posting a ContentItem we are trying to patch Tags with that ContentItem but are unable to patch it. It gives an authentication error given below:

Array

(

[0] => {"d":{"results":{"__metadata":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')","type":"SAPJam.ContentItem","media_src":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/$value","content_type":"text/html;type=blog","edit_media":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/$value"},"Id":"wCWMnKW7aUjyJcaqeB1Jwe","Name":"New Word Story","ContentItemType":"BlogEntry","Description":null,"CreatedAt":"/Date(1483711412000)/","LastModifiedAt":"/Date(1483711412000)/","ViewsCount":0,"Liked":false,"LikesCount":0,"IsFeatured":false,"PermissionType":"undefined","DocumentSize":null,"FileName":null,"ConversionStatus":"not_applicable","IsCheckedOut":false,"FeedCommentsCount":0,"ExternallyCreatedAt":null,"ContentType":"text/html;type=blog","IsMirror":false,"MirrorsCount":0,"Tags":"","FeedEntries":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/FeedEntries"}},"Creator":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/Creator"}},"LastModifier":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/LastModifier"}},"Likers":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/Likers"}},"ParentFolder":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/ParentFolder"}},"Group":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/Group"}},"CheckedOutByMembers":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/CheckedOutByMembers"}},"MirrorSource":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/MirrorSource"}},"Mirrors":{"__deferred":{"uri":"ContentItems(Id='wCWMnKW7aUjyJcaqeB1Jwe',ContentItemType='BlogEntry')/Mirrors"}}}}}

[1] => Invalid OAuth protected resource access request. OAuth authentication failed.

)

We tried the PATCH method with the following cURL command:

curl -H 'Authorization: OAuth oauth_consumer_key="Vcw3vmcbmkkxDGK0TIAE",oauth_signature_method="HMAC-SHA1",oauth_nonce="398e76d68c9505bd44429b50bfe277d1",oauth_version="1.0",oauth_timestamp="1483711442",oauth_token="ftk7nEQRU48r8eGtVzOSLTyUioL8HFXOzozUxBfe",oauth_signature="NT1wr33DO4A2RkWBT4%2B6uBRanyk%3D"' -H 'Accept: application/json' -H 'Content-Type:application/json' -d '{"Tags":"Community"}' -X PATCH https://developer.sapjam.com/api/v1/OData/ContentItems(Id='STNwo3PEa94u1DG4qgnvhY',ContentItemType='BlogEntry')

We have also tried passing URL’s in different methods to PATCH Tags to a particular ContentItem:

https://developer.sapjam.com/api/v1/OData/ContentItems(Id='STNwo3PEa94u1DG4qgnvhY',ContentItemType='BlogEntry')/$value

https://developer.sapjam.com/api/v1/OData/ContentItems?Id='STNwo3PEa94u1DG4qgnvhY'&ContentItemType='BlogEntry'

Since the URL in POST and PATCH methods are different, we are generating the OAuth parameters twice for POST and PATCH curl commands.

Kindly let us know if any modifications are needed in the URL or curl command or we are missing anything in the PATCH method.

0