Quantcast
Channel: User bavaza - Stack Overflow
Viewing all articles
Browse latest Browse all 45

Answer by bavaza for python dynamic value in api payload

$
0
0

You should escape the curly braces in the formatted string, like so:

f'[{{"code": "orderno", "value":"{valuetarget}"}}]'

But why not let requests format the string for you?

import requestsurl = "https://www.stie.com/api/conversations/KJQ-CZHNR-985/fields"valuetarget = "123"# 'customfields' is now a list of dictionariespayload = {'apikey': 'zbyc88srdi333d3dpq5lye48pgg1tfo1pnjvj65ld','customfields': [{"code": "orderno", "value": valuetarget}]}files = []headers = {}response = requests.request("POST", url, headers=headers, data=payload, files=files)print(response.text)

Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>