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
bingi crm 7bingi 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;
    }
}
Trail Head 33Trail Head 33
Hi Bingi Crm,
Check the debug of response and tell me what is getting?
Thanks ,
karthik