Forum Discussion

ajoshi84's avatar
ajoshi84
Contributor
13 years ago

REST API Question - Using Java Client

Hello All, 

I am using JAVA client to get connected. I am using the follwing code 

 

 

URL categoryUrl = newURL("http://forums.mycompany.com/.../restapi/vc/categories/nested");
	BASE64Encoder encoder = new BASE64Encoder();
        String encodedCredential = encoder.encode( (userId + ":" + password).getBytes() );
        httpUrlConnection.setRequestProperty("Authorization", "BASIC " + encodedCredential);

 

I am able to hit the URL correctly but the response i get is 


 

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<response status="error">
  <error code="303">
    <message>UserRef[id=-1] does not have access to RequiredPermissions[(allow_restapi_call_read)] on CommunityByDisplayIdRef[nodeType=StandardNodeType[nodeClass=interface lithium.coreapi.community.ICommunity,entityTypeKey=EntityTypeKey[community],entityTypeUid=4,nodeTypeUid=1,hashCode=-390137648],displayId=stx]</message>
  </error>
</response>

 

Any Idea what am I missing here.

 

 


  • AdamN's avatar
    AdamN
    Khoros Oracle

    Hi ajoshi84,

     

    Each request to the REST API is made either as an anonymous user or as a registered user, and as such the request is subject to the permissions granted to that particular user. Judging by the response you received, it appears that the request was made as an anonymous user ("UserRef[id=-1]"), and it also appears that the anonymous user does not have permission to make REST API calls with read access in the community ("does not have access to RequiredPermissions[(allow_restapi_call_read)]")

     

    You have a couple of options:

    1. You can alter the default community permission for "Make REST API calls with read access" to grant. The permissions for the anonymous user are essentially the default permissions you've set in the community, so granting this permission allows anonymous users (or any user for that matter) to make REST API calls with read access. 
    2. You can authenticate as a user that has been explicitly granted the permission "Make REST API calls with read access". Check out the "AuthenticationManager" class in the javadocs for more information on how to login via the REST API. You'll need to make sure you keep the session key that is returned when you login and then pass it to the subsequent requests via the "restapi.session_key" query string parameter. If you go this route, I'd suggest registering an account specifically dedicated to making REST API requests.

     

    Personally, I'm more a fan of option #2 because it only grants access to the accounts that need it, but I also understand that different communities have different needs. 

     

    I hope this helps!

  • RobbL's avatar
    RobbL
    Lithium Alumni (Retired)

    Hi,

     

    The best place for these technical questions is the Developer board. It is currently called Lithium Developers. You can also get access if you click the Develop tab towards the top of this page.