[Solved] Can’t make a request using an ‘user_id’ as parameter on a Flask ApiRest

Elielton Limeira Asks: Can’t make a request using an ‘user_id’ as parameter on a Flask ApiRest
I made this request getting all the data from all the users, and it’s working just fine:

Code:
    @app.route('/account/bank-statement', methods=['GET'])
def get_bank_statement():
    try:
        bank_statement = TransferModel.query.all()
        transfer_schema = TransferSchema(many=True)
        bank_statement = transfer_schema.dump(bank_statement)
        array = np.asarray(bank_statement)
        list = array.tolist()
        return make_response(json.dumps(list), 200)
    except ValidationError as error:
        return make_response(error.messages, 422)

But when i try to get the same data from a specific user_id it returns an empty json:

Code:
@app.route('/account/bank-statement/<user_id>', methods=['GET'])
def get_bank_statement_id(user_id):
    try:
        bank_statement = TransferModel.query.get(user_id)
        transfer_schema = TransferSchema(many=True)
        bank_statement = transfer_schema.dump(bank_statement)
        array_result = np.asarray(bank_statement)
        list = array_result.tolist()
        return make_response(json.dumps(list), 200)
    except ValidationError as error:
        return make_response(error.messages, 422)

What i’m doing wrong?

this is the model for that:

Code:
class TransferModel(db.Model):
    __tablename__ = 'transfers'
    transfer_id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    user_id = db.Column(db.String)
    friend_id = db.Column(db.String)
    value = db.Column(db.Integer)
    card_id = db.Column(db.String)
    date = db.Column(db.String(10))

    def __init__(self, user_id, friend_id, value, card_id, date):
        self.user_id = user_id
        self.friend_id = friend_id
        self.value = value
        self.card_id = card_id
        self.date = date

    def __repr__(self, ):
        return '' % self.user_id

    def remodel(friend_data):
        friend_data['card_id'] = friend_data['billing_card']['card_id']
        friend_data['value'] = friend_data['total_to_transfer']
        friend_data['date'] = date.today().strftime("%d/%m/%Y")
        del friend_data['billing_card']
        del friend_data['total_to_transfer']
        return friend_data

    def save_to_db(self, ):
        db.session.add(self)
        db.session.commit()

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.