From form data to postman

I have created a simple website wherein i have a form. Upon entering the form data my code creates a dictionary with the key value pairs.
i have printed the dictionary out successfully in pycharm, but my confusion is how to send this data over to postman as a post request.

the basic syntax i am using is:

response=requests.post(add_url, json=data)

however, it doesn’t seem to be playing ball!
in postman the post request key values are “x-www-form-urlencoded”.
This is the first time i’ve worked independently with postman, so excuse me if i’m not explaining myself very clearly.

thanks

Welcome to the community @photonbeem :wave:

Where are you getting stuck? Are you able to show us a screenshot of Postman and what isn’t working for you?

Thanks!

thanks for the swift response!

i have created this app route…

I know for a fact that the data is being collated from the form (as it prints out), and also i am able to retrieve data from the api… just can’t add it!

cheers
the code is pasted below, hope it’s clear…


@app.route(“/add”, methods=[‘GET’, ‘POST’])
def add_cafe():
add_form=AddCafeForm()

if add_form.validate_on_submit():

    name = add_form.name.data
    map_url = add_form.map_url.data
    img_url = add_form.img_url.data
    location = add_form.location.data
    has_sockets = add_form.has_sockets.data
    has_toilets = add_form.has_toilets.data
    has_wifi = add_form.has_wifi.data
    can_take_calls = add_form.can_take_calls.data
    seats = add_form.seats.data
    coffee_price = add_form.coffee_price.data
    name=name.title()
    location=location.title()
    if has_sockets=="Yes":
        has_sockets=True
    else:
        has_sockets=False
    if has_toilets=="Yes":
        has_toilet=True
    else:
        has_toilet=False
    if has_wifi=="Yes":
        has_wifi=True
    else:
        has_wifi=False
    if can_take_calls=="Yes":
        can_take_calls=True
    else:
        can_take_calls=False
    coffee_price="£"+coffee_price

    add_url=ADD_CAFES_API
    data={
        "name": name,
        "map_url": map_url,
        "img_url": img_url,
        "location":location,
        "has_sockets":has_sockets,
        "has_toilet":has_toilet,
        "has_wifi":has_wifi,
        "can_take_calls":can_take_calls,
        "seats":seats,
        "coffee_price":coffee_price

    }
    print(data)

 response=requests.post(add_url, json=data)

oh, if i manually add date to the postman app it works fine…

So is that what you were missing? Is there anything else you need help with?

i just need to know why postman isn’t receiving the data from the form in the website (data is being collected AND the postman works when i enter data to it on the windows app). i just can’t seem to post the the requests from the website to postman. really frustrating.

Are you expecting Postman to collect the data from your website automatically? I’m afraid it doesn’t work that way :grimacing:

no… all i want to do is send postman new data so that updates the api.
ie… every time i enter new data in the form on the website, it should send the post request. i might be missing the point here, i’ll hold my hands up and admit defeat if i am, but what’s the point in a restful api if you can’t send request posts to it?
excuse any misunderstandings i have… it’s a whole new world to me!
cheers

Your website isn’t going to talk to Postman directly. I think you’re thinking it’s going to do something like this?

Your web form → Postman → API

Is that right?

In reality, they site side by side and Postman is not part of the flow from your website.