I have created a REST Endpoint (exposed on force.com site) to allow Webhook messages.
The third party service will POST data to the webhook that looks like this:
Body:
{ "channel": "server", "email": "[email protected]", "messageId": "test-message-37q7z9", "projectId": "oYOQY8rnYw", "replay": true, "timestamp": "2018-12-04T16:22:37.195Z", "traits": { "trait1": 1, "trait2": "test", "trait3": true }, "type": "identify", "userId": "test-user-x1nyrr" } How can I read the attributes in the traits object? (i.e. trait1, trait2). I should note the attributes in the traits object may increase/decrease in size so this needs to be somewhat dynamic.
This is what I have so far but I'm not sure how to parse the payload.
@RestResource(urlMapping='/webhook') global class WebhookReq { @HttpPost global static String doPost() { //Blob name = RestContext.request.params.get('name'); String traits = RestContext.request.params.get('traits'); RestRequest req = RestContext.request; String result = JSON.deserialize(req.getBody()); return result; } }