0

The currentPage().getParameters() can read GET pagams, and also reads POST body only if the header Content-Type = application/x-www-form-urlencoded

However, when the Content-Type changes to application/json, I cannot read incoming JSON, nothing in the keySet(). Here is the code I use to read

Map<string, string> requestText = (Map<string, string>)ApexPages.currentPage().getParameters();

The external application uses application/json in header and there is no way to influence that. Also, no way to do Oauth with that app.

I'm grateful for your ideas

  • 5
    Are you aiming to build a headless API that is exposed to the unauthenticated internet? – David Reed Jul 25 at 11:41
  • I want the webhook of KanbanFlow.com to update records on salesforce. i haven't completely figured out their security yet.. out of my depth to be honest.. now i am not certain what the kanban server sends (above observations were tested through POSTman, as I was unable to read any data from the server, my class does register the request, but that's it - no body) I'll do a bit more reading.. just wanted some pointers.. – Vladimir Mironov Jul 25 at 12:50
  • 2
    Security - From KanbanFlow interface doc Each webhook has an associated secret you can use to verify that the request came from KanbanFlow. The request made to your URL endpoint will contain a special header called X-KanbanFlow-Signature. The signature is a HMAC-SHA256 hex digest of the payload using the secret as the key. Exactly how to verify the signature depends on your platform . You can code this verification into your Apex class with @RestResource – identigral Jul 25 at 17:01
1

Visualforce does not support reading other types of payloads. Instead, you can write an Apex class that uses @RestResource, then expose that class by adding it to the Guest profile for your Site. See Quick Tip – Public RESTful Web Services on Force.com Sites for more information on how this works.

  • and i was hoping it's going to be as easy as reading GET params.. Thanks, I'll give it a read. Still early days of rest, finding my footing.. If it's too complicated, I may just make an intermediate json server to convert JSON to url params, as i only need 2 values. – Vladimir Mironov Jul 25 at 12:54
  • @VladimirMironov It's really easy, just a few lines of code. The blog post has everything you need, and it's only about a five minute read or so. – sfdcfox Jul 25 at 13:07
  • It worked! Beautiful JSON in the end. Thank you Brian! – Vladimir Mironov Jul 25 at 15:52

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.