function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
yashagarwalyashagarwal 

Trying to call chatter rest from a visual force page on the same org - HTTP response 302

Hi,

 

I am trying to call the chatter rest api from a visual force page from the same org. While my code works if I put it in the developer console - however , from the Visual force page I get the Http response 302 - not sure what is happening. Here is my apex code :

String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();
        String url =  salesforceHost + '/services/data/v27.0/chatter/feeds/record/' + oTaskDetail.sato.Id + '/feed-items';
        HttpRequest req = new HttpRequest();
        req.setMethod('POST');
        req.setEndpoint(url);
        req.setHeader('Content-type', 'application/json');
        req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
        String UserId = String.ValueOf(UserInfo.getuserId());
        String ChatterPostText = CreateChatterPost();
        req.setBody('{ "body" : { "messageSegments" : [ { "type": "mention", "id" : "' + UserId + '" }, { "type": "text",  "text" : "' + ' ' + ChatterPostText +  '" } ] } }');
        Http http = new Http();
        HTTPResponse res = http.send(req);

any help on this would be greatly appreciated. Thanks

Thomas DvornikThomas Dvornik
You could try and get a heap dump by executing it from a VF page and the developer console to compare values and see if any are different. I would be curious if the URL is different.