-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing json payload of a webhook #15
Comments
@SimonLab , can you try Map.get(payload, "action") ? |
It looks the the payload still contains a string, is this right? I thought Phoenix could automatically parse a stringify json with Poison |
Don't you need to explicitly decode it with Poison? |
@jruts Thanks a lot it worked! I try to see how I can add the decode function into the api pipeline to parse automatically the payload on each requests:
|
@SimonLab you will indeed need a plug parser for that. more specifically: https://hexdocs.pm/plug/Plug.Parsers.JSON.html#content |
@SimonLab a more detailed example: http://absinthe-graphql.org/guides/plug-phoenix/ Scroll over to the Phoenix section (ignore the absynthe bit) |
Sorry for the ramble, I am pretty sure you can figure it out pretty easily by yourself! Good stuff :) |
Thanks for all the links 👍 I'll read through the doc and try to understand the details of the parsers |
@SimonLab a last tip: https://engineering.appcues.com/2016/02/02/too-many-dicts.html Read 2 and 5 carefully. You will want to use a struct, not just decode the json string into a map. Have fun :) |
At the moment I parse the stringify payload with |
@SimonLab here is an example of a similar plug: https://dockyard.com/blog/2015/08/05/building-json-api-endpoints-with-phoenix |
@jruts Thanks for all the input! 😍 |
Thanks for all the links!! My main issue when parsing the payload was in fact a mistake from my part when I created the webhooks on Githbub, see #19 . Phoenix automatically parse the json payload to a map 🎉 |
The server is now able to catch the payload sent by Github:
and my controller has the following create action:
I manage to print the payload but I fail to extract the "action" property with payload.action:
I've also try to use a pattern match on the action with
but get also an error
@Shouston3 @jackcarlisle do you have any suggestions on how to access the values of a json payload?
The text was updated successfully, but these errors were encountered: