I’m trying to build a simple API with FastAPI that takes and receives data from the Shopify API. I’m currently trying to write an endpoint for a POST request made from Shopify.
The Shopify API includes a header that can be used to verify the request actually came from Shopify. Their documentation however uses Flask, whereas I’m trying to use FastAPI.
https://shopify.dev/apps/webhooks/configuration/https
I need to retrieve the request data as a bytestring and a header from the request. I was able to retrieve the header eventually (very new to all this). But so far am not sure how to get the bytestring.
This is what they use in the documentation
data = request.get_data()
https://tedboy.github.io/flask/generated/generated/flask.Request.get_data.html
I haven’t found an equivalent in FastAPI. Is there any? Or is there a way to take the data from the request and convert it to a bytestring to use in Shopify’s verification example?
Any help is appreciated. Please let me know if I need to include more information.
Thanks for reading!
2
Answers
i think you can use .json method from FastAPI
For shopify devs, use
data = await request.body()
This is the byte result.