Python Forum

Full Version: need help in passing url as variable in payload
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Team,

I need help in code to post variable( which has url) in the body of post api call. Here is code.

stashurl = 'https://<someurl>_{}/{}'.format(quote(app), quote(querystring))
payload = "{\"inputParameters\": [{\"name\": \"url\",\"value\": \"stashurl\"t}]}"

How to pass the stashurl variable in payload to post it to another api.
Thanks for the reply, I was able to concatenate the string, but how to use that string variable in body of rest api
I don't understand exactly what you are doing, so I cannot help you.
This is all I could think of:
https://stackoverflow.com/questions/4542...le_rich_qa
(Apr-20-2018, 01:42 AM)vkvasu25 Wrote: [ -> ]Thanks for the reply, I was able to concatenate the string, but how to use that string variable in body of rest api
You use Requests and send it as post with payload,based on what API accept.
Example here i use httpbin which can do test against.
>>> import requests
>>> 
>>> headers = {'Content-type': 'application/json'}
>>> payload = {"device_name": 'Super-Pc', 'DevicePort': 666}
>>> r = requests.post('http://httpbin.org/post', headers=headers, json=payload)
>>> r.status_code
200
>>> r.json()
{'args': {},
 'data': '{"device_name": "Super-Pc", "DevicePort": 666}',
 'files': {},
 'form': {},
 'headers': {'Accept': '*/*',
             'Accept-Encoding': 'gzip, deflate',
             'Connection': 'close',
             'Content-Length': '46',
             'Content-Type': 'application/json',
             'Host': 'httpbin.org',
             'User-Agent': 'python-requests/2.18.4'},
 'json': {'DevicePort': 666, 'device_name': 'Super-Pc'},
 'origin': '85.165.158.220',
 'url': 'http://httpbin.org/post'}
>>> r.json()['json'][ 'device_name']
'Super-Pc'
I want to pass url as input to body of post Ali call

I want to pass url as input to body of post Api call as shown in my code , I Want to pass that data to rest api

To define simply, I Wanto pass exactly same data as shown in payload,
payload = "{\"inputParameters\": [{\"name\": \"url\",\"value\": \"someurl\"t}]}"
But it is throwing error as <link
To define simply, I Wanto pass exactly same data as shown in payload,
payload = "{\"inputParameters\": [{\"name\": \"url\",\"value\": \"someurl\"t}]}"
But it is throwing error as <link

Also the url in the payload has multiple endpoints