0

I am creating a post method that is tested with Postman and I do get the functionality done which is getting a variable from the incoming JSON string then querying a record, then updating the account with that value.

The thing is it works with Postman and workbench but when it comes to the external system that I am dealing with when they test by sending their post request, the jsonString here becomes null, I thought it might be something related to: " x-www-form-urlencoded" but I couldn't just get it to work to bypass this, what could I possibly do and why Postman & workbench work but their system doesn't.

global static string doPost()
        {
            try{
            RestRequest req = RestContext.request;
            system.debug('request incoming '+req);
                //string jsonString=EncodingUtil.urlEncode(req.requestBody.tostring(), 'UTF-8');
                string jsonString=req.requestBody.toString();
                jsonString= EncodingUtil.urlEncode(jsonString,'UTF-8');
                system.debug('json string before wrapping'+jsonString);
                requestWrapper prwrapper = new requestWrapper();            
                if (jsonString != ''){}
2
  • We would need to see what the debug log looks like. You need to debug jsonString for us to see what it looks like (do not URLENCODE until you're sure what the base string looks like). – sfdcfox Apr 7 at 1:33
  • @sfdcfox the jsonString came empty jsonString|String|false|false jsonString|"" httpMethod=POST, params={client_secret=##, grant_type=##, password=##, username=##, {"PartnerResponse":{"PartnerHeaderComplex":{"HeaderID":"PTNR_HEADER","Trx_Feed_Ver":"20210318103","Ptnr_ID":"##","Ptnr_Type":"PTNR","Suborg":"ab","Ptnr_Name1":"testing","Routing_ID":"32;23\r"},"PartnerScreeningResultComplex":{"HeaderID":"PTNR_SCR_RLT","Ptnr_Screening_Results":"22","Ptnr_Status":"21","Ptnr_Suspect_List":rr"}}}=}, remoteAddress=##, requestBody=Blob[0], requestURI=/Account//, resourcePath=/services/apexrest/Account/W – Mohamed AbdelRahman Apr 7 at 10:36
0

If they used Content-Type of application/x-www-form-urlencoded, that would explain this behavior. Salesforce is seeing the body as a parameter with a long key and empty value because of this. Ideally, the developers need to change Content-Type to application/json. If they can't fix this problem, then you'll just need to iterate over the parameters and find the key that starts with { and parse that as JSON.

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.