You need to sign in to do that
Don't have an account?
bingi crm 7
I am writing the Rest Api on chatter but there are throwing error HttpResponse . System.CalloutException: Invalid HTTP method: Post Error is in expression '{!postit}'
Visual Force:-
<apex:commandButton value="Postit" action="{!postit}"/>
Class:-
public class ChatterRestApi {
public PageReference postit() {
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://avenger2-dev-ed.my.salesforce.com/services/data/v37.0/chatter/feeds/user-profile/00528000003IL9C/feed-elements');
req.setMethod('Post');
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
req.setHeader('content-type','application/json');
req.setBody('{ "body" : { "messageSegments" : [ { "type" : "Text", "text" : "When should we meet for release planning " }');
HttpResponse res = http.send(req);
System.debug(res);
return null;
}
}
<apex:commandButton value="Postit" action="{!postit}"/>
Class:-
public class ChatterRestApi {
public PageReference postit() {
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://avenger2-dev-ed.my.salesforce.com/services/data/v37.0/chatter/feeds/user-profile/00528000003IL9C/feed-elements');
req.setMethod('Post');
req.setHeader('Authorization', 'OAuth '+UserInfo.getSessionId());
req.setHeader('content-type','application/json');
req.setBody('{ "body" : { "messageSegments" : [ { "type" : "Text", "text" : "When should we meet for release planning " }');
HttpResponse res = http.send(req);
System.debug(res);
return null;
}
}
Check the debug of response and tell me what is getting?
Thanks ,
karthik