0

Hello there hope you are doing well!

I'm tring to fetch some data from the db but for some reason the request goes through in postman but when I try it with axios is gives me:

400 bad request Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)

Here is my code:

    useEffect(() => {
        const fetchItems = async () => {
            try {
                const response = await axios.get('http://127.0.0.1:5000/orderhis',
                    {data: {"user_id":87}}
                );
                setData(response.data)
            } catch(err) {
                if (err.response) {
                    console.log(err.response.data);
                    console.log(err.response.status);
                    console.log(err.response.headers);
                }
                else{
                    console.log(`Error: ${err.message}`);
                }
            }
        }
        fetchItems();
    }, []);

In Postman:

Postman example

But in the Browser:

enter image description here

PS Here is the route code in case it helps:

def order_history():
    if request.method == 'GET':
        user_id = request.json['user_id']
        is_user = BaseUser().getUserID(request.json)
        if is_user[1] == 404:
            return is_user
        return OrderController().get_order_history(user_id)
    return jsonify(Error='Method not allowed'), 405

Thanks and have a great day!

1 Answer 1

0

You're setting params like this: {data: {"user_id":87}}, but in axios you need to set params with: {params: {"user_id":87}}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.