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 Answer 1

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": "..."
}
6
  • What if it's not coming as JSON, x-www-form-urlencoded ?
    – thinker
    Commented Nov 13, 2019 at 21:47
  • To be clear we are the ones consuming the post, not sending the post.
    – thinker
    Commented Nov 13, 2019 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
    Commented Nov 13, 2019 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
    Commented Nov 13, 2019 at 22:04
  • Both cases have the same root cause - the request doesn't match method signature.
    – identigral
    Commented Nov 13, 2019 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .