You need to sign in to do that
Don't have an account?
cipto cipto
How to get@HTTPPOST to work
Hi there,
I'm exposing an apex class as REST.
The HTTP Get query works just fine
But when doing the POST, I don't know why always return
METHOD NOT ALLOWED "GET" Please use POST
Any body have an idea why it's happening?
am I missing a configuration or something?
this is pointing to a sandbox lightning.
I'm exposing an apex class as REST.
@RestResource(urlMapping='/Opportunity/*') global with sharing class OpportunityResource { @HttpGet global static Opportunity doGet() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; String opportunityId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Opportunity result = [select Id, Account.Id, Account.Name, Account.Phone, Account.Fax, Account.Website, Account.Type, Account.NumberOfEmployees, Account.BillingCountry, Account.BillingStreet, Account.BillingCity, Account.BillingState, Account.BillingPostalCode, Account.Service_Rep_Email__c, Account.Industry, Account.Special_Contract_Terms__c, Account.Billing_Terms__c, Account.PEPY__c, Number_of_Employees__c, Number_of_Sessions__c, Product__c, Brand__c, Benefit_Tier__c, Effective_Date__c, Number_of_Training_Visits__c, Number_of_Trauma_Responses__c, Premium_Per_Employee__c from Opportunity where Id = :opportunityId limit 1]; return result; } @HttpPost global static String doPost(String name,String description) { Opportunity opportunity = new Opportunity(); opportunity.Name = Name; opportunity.Description = Description; insert opportunity; return opportunity.Id; } }
The HTTP Get query works just fine
curl -X GET \ https://xxx.lightning.force.com/services/apexrest/Opportunity/0065C0000050OLGQA2 \ -H 'authorization: Bearer xxx' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 7ba978b9-f2e8-fd39-b52f-039e5c3d194b' \
But when doing the POST, I don't know why always return
METHOD NOT ALLOWED "GET" Please use POST
curl -X POST \ https://xxx.force.com/services/apexrest/Opportunity/ \ -H 'authorization: Bearer xxx' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 885fbd88-3171-d7cf-2dfa-7a782a3e5df8' \ -d '{ "name":"PT ABAL ABAL", "description":"PT Abal" } '
Any body have an idea why it's happening?
am I missing a configuration or something?
this is pointing to a sandbox lightning.