-1

Would anyone be able to give me a tip on how to use this api with postman written with Flask in Python?

@app.route('/read', methods=['POST'])
def do_read():
    try:
        device_id = request.get_json().get('device_id')
        object_id = request.get_json().get('object_id')
        object_type = request.get_json().get('object_type')
        prop = request.get_json().get('prop')
    except:
        err_msg = "Read request was missing a required parameter. Required: [device_id, object_id, object_type]"
        logging.warning(err_msg + " Exception: " + str(sys.exc_info()))
        return jsonify({"status_code": 500, "description": err_msg})

So if I am posting to route /read in postman I am still getting a http code 500 returned. Any tips to try? enter image description here

bbartling
  • 3,288
  • 9
  • 43
  • 88

1 Answers1

1

You are not sending a json but rather form data. This could be the potential issue.

Try selecting raw radio button and change to JSON in the dropdown and write the data as a json. Example

PureVodka
  • 131
  • 7
  • Thanks for the post. Out of curiosity, do rest API's always have this format of raw json? Or can they also do data as form? For example if I wanted to post to the `/read` flask url, could the API be modified to just use data as form for the API requests? OR do rest API always need some raw JSON format? Sorry still learning this stuff and what the best practices are! – bbartling Dec 17 '20 at 14:02
  • I too am just learning however I think it is legitimate to have form data in your REST API. It just comes down to how easy it will be to create the request for some application later hoping to consume the API - in which case I think json will be easier. Although someone with more knowledge should answer that one. – PureVodka Dec 17 '20 at 14:14