Unable to send sms on whatapp throguht route

Question:

bascially i am making a route in which i have connect my api of whatapp when i send a number in my json response thought software this route should send me a whatapp message on that number

@app.route('/v1.1/userRegistor', methods=['POST','GET'])
def get_user():
    data = request.get_json()
    numbers=data['numbers']
    api_url = ('https://app.simplywhatsapp.com/api/send.php?number=numbers&type=text&message=test%20message&instance_id=634CF8BECCB26&access_token=78495efca3672167f9ed88cb93acd2e1')
    r = requests.get(api_url)
    return r.json()

this is my request body:
{

"numbers":"923142985338"

}

Asked By: Anoosha Soahil

||

Answers:

You aren’t formatting your API request URL. The variables can’t be passed directly in the string, as they can’t be distinguished from words. You need to use a format string.

api_url = f'https://app.simplywhatsapp.com/api/send.php?number={numbers}&type={text}&message=test%20message&instance_id=634CF8BECCB26&access_token=78495efca3672167f9ed88cb93acd2e1'

Read more about it here: https://www.pythoncheatsheet.org/cheatsheet/string-formatting

Answered By: Arihant Bansal
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.