<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python variable in json payload in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443539#M6770</link>
    <description>&lt;P&gt;You'll also need to add at the top:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pl-k"&gt;import&lt;/SPAN&gt; &lt;SPAN class="pl-s1"&gt;json&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Oct 2020 00:25:08 GMT</pubDate>
    <dc:creator>Philip D'Ath</dc:creator>
    <dc:date>2020-10-11T00:25:08Z</dc:date>
    <item>
      <title>Python variable in json payload</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443535#M6766</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am not JSON expert so I am looking for help.&lt;/P&gt;&lt;P&gt;I want to pass on a python variable to payload in JSON format.&lt;/P&gt;&lt;P&gt;I was trying with code below but it doesn't work. I have info that JSON submitted is wrong.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;My code is:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;------------------------------------------------------------------------------------------------------------------------------------&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;import requests&lt;/P&gt;&lt;P&gt;url = "&lt;A href="https://api.meraki.com/api/v1/organizations/XXX/configTemplates" target="_blank" rel="nofollow noopener noreferrer"&gt;https://api.meraki.com/api/v1/organizations/XXX/configTemplates&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;myname&lt;/STRONG&gt; = "TESTNAME"&lt;/P&gt;&lt;P&gt;payload = '''{&lt;BR /&gt;    "name": &lt;STRONG&gt;myname&lt;/STRONG&gt;,&lt;BR /&gt;    "timeZone": "America/Los_Angeles"&lt;BR /&gt;}'''&lt;/P&gt;&lt;P&gt;headers = {&lt;BR /&gt;    "Content-Type": "application/json",&lt;BR /&gt;    "Accept": "application/json",&lt;BR /&gt;    "X-Cisco-Meraki-API-Key": ""&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;response = requests.request('POST', url, headers=headers, data = payload)&lt;/P&gt;&lt;P&gt;print(response.text.encode('utf8'))&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;Of course payload below works perfectly but I need variables to be able to pass them through argv in the future. &lt;/P&gt;&lt;P&gt;payload = '''{&lt;BR /&gt;    "name": "TESTNAME",&lt;BR /&gt;    "timeZone": "America/Los_Angeles"&lt;BR /&gt;}'''&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 19:19:49 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443535#M6766</guid>
      <dc:creator>damgol</dc:creator>
      <dc:date>2020-10-10T19:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Python variable in json payload</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443536#M6767</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;payload = {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;    "name": &lt;/SPAN&gt;&lt;STRONG&gt;myname&lt;/STRONG&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;    "timeZone": "America/Los_Angeles"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 20:07:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443536#M6767</guid>
      <dc:creator>Philip D'Ath</dc:creator>
      <dc:date>2020-10-10T20:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python variable in json payload</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443537#M6768</link>
      <description>&lt;P&gt;&lt;SPAN&gt;payload = {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;    "name": &lt;/SPAN&gt;&lt;STRONG&gt;myname&lt;/STRONG&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;    "timeZone": "America/Los_Angeles"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;It doesn't work:&lt;/P&gt;&lt;P&gt;{"status":400,"error":"Bad request: There was a problem in the JSON you submitted"}&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2020 21:05:03 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443537#M6768</guid>
      <dc:creator>damgol</dc:creator>
      <dc:date>2020-10-10T21:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python variable in json payload</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443538#M6769</link>
      <description>&lt;P&gt;Try changing the request to (and keep the prior payload format I supplied):&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;response = requests.request('POST', url, headers=headers, data = &lt;SPAN class="pl-s1"&gt;json&lt;/SPAN&gt;.&lt;SPAN class="pl-en"&gt;dumps&lt;/SPAN&gt;(payload))&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 00:23:51 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443538#M6769</guid>
      <dc:creator>Philip D'Ath</dc:creator>
      <dc:date>2020-10-11T00:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python variable in json payload</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443539#M6770</link>
      <description>&lt;P&gt;You'll also need to add at the top:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pl-k"&gt;import&lt;/SPAN&gt; &lt;SPAN class="pl-s1"&gt;json&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 00:25:08 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443539#M6770</guid>
      <dc:creator>Philip D'Ath</dc:creator>
      <dc:date>2020-10-11T00:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python variable in json payload</title>
      <link>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443540#M6771</link>
      <description>&lt;P&gt;Yes. It works.&lt;/P&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 08:37:21 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/python-variable-in-json-payload/m-p/5443540#M6771</guid>
      <dc:creator>damgol</dc:creator>
      <dc:date>2020-10-11T08:37:21Z</dc:date>
    </item>
  </channel>
</rss>

