0

Afternoon,

We have a vendor that is trying to send POST requests to a method in we have hosted using Site Guest User.

Here is our code snippet that we are using to see if the request is even entering the method, but it is not.

@RestResource(urlMapping='/myUrl/*')
global without sharing class myClass {

    @HttpPost
    global static String createSomething(String value) {

    System.Debug(value); 

}

The url format is passing the data in a key value pair format.

/myUrl?Id=123&Name=Test&Age=40

The issue is that we can see in the debug logs that we are getting the requests, but the method will not fire. Any suggestions?

1

The format of the HTTP request needs to correspond to your Apex REST method. If your method is annotated with @HttpPost and the signature of the method has a single String argument named value, your request needs to be a POST with a payload (request body) that looks like this:

{
"value": "..."
}
  • What if it's not coming as JSON, x-www-form-urlencoded ? – thinker Nov 13 at 21:47
  • To be clear we are the ones consuming the post, not sending the post. – thinker Nov 13 at 21:47
  • If it's not coming as JSON or it's coming in as JSON but you want to parse it yourself, you would need a different implementation along these lines – identigral Nov 13 at 21:50
  • The odd thing is that if we take away the parameter in the method, the url will not be hit by the vendor's post request. If we have a parameter, we can see the Post Request and it's key-value pairs sent in the URL, but the method will not fire. It's almost as if the class is being run but the method is not. – thinker Nov 13 at 22:04
  • Both cases have the same root cause - the request doesn't match method signature. – identigral Nov 13 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.