I have gone through some documents like: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm .

It seems to me that in order to write a post API interface I need to understand what the input string is. But my scenario is the input json string can be dynamic.

Is there a way for me to take the whole post string as the parameter and handle that json string dynamically in my function? Something like:

global static void doPost(String message) 

Not quite sure whether this is possible though.


You can capture the whole request body as the string from Restrequest

 global static void doPost(){
    RestRequest req = RestContext.request;
    string jsonbody =   req.requestBody.toString();
    //Use deserializer via maps here
    Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonbody);


The above can be used and any valid JSON can be passed in the request body .

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.