Python Forum

Full Version: Flask rest api How to retrieve json request
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am new to Python. I have a flask rest api. I am trying to call another rest api inside of my method. I would like to know if there is a way to get json request data when my method is called?

Here is my code portion:
# POST /purchase_initiation
@app.route('/purchase_initiation', methods=['POST'])
def initiation():
    try:
        # if request.is_json:
            # getting request data
            request_data = request.json()
            print request_data
On the Print I am getting 'NoneType' object is not callable error. By the way I am sending POST request from POSTMAN.

Thanks in advance.
Best Regards.
I think it is something about postman.
Can you provide your Postman request as a curl? I imagine this is because either you're not sending JSON, or you're not specifying the content type as JSON.
I understand the question, you were definitely set the content type as JSON instead of sending JSON. Try to send JSON and also provide the postman request.
This solved my problem;
# POST /purchase_initiation
@app.route('/purchase_initiation', methods=['POST'])
def initiation():
    try:
        # getting request data
        request_data = request.form.to_dict()