<?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: &amp;quot;Payload is not a valid JSON&amp;quot; when bash scripting with cURL in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74088#M4338</link>
    <description>&lt;P&gt;I just checked the API status:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# api status&lt;/P&gt;&lt;P&gt;API Settings:&lt;BR /&gt;---------------------&lt;BR /&gt;Accessibility: Require all granted&lt;BR /&gt;Automatic Start: Enabled&lt;/P&gt;&lt;P&gt;Processes:&lt;/P&gt;&lt;P&gt;Name State PID More Information&lt;BR /&gt;-------------------------------------------------&lt;BR /&gt;API Started 23009&lt;BR /&gt;CPM Started 21940 Check Point Security Management Server is running and ready&lt;BR /&gt;FWM Started 22231&lt;BR /&gt;APACHE Started 5568&lt;/P&gt;&lt;P&gt;Port Details:&lt;BR /&gt;-------------------&lt;BR /&gt;JETTY Internal Port: 50276&lt;BR /&gt;APACHE Gaia Port: 443&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;Overall API Status: Started&lt;BR /&gt;--------------------------------------------&lt;/P&gt;&lt;P&gt;API readiness test SUCCESSFUL. The server is up and ready to receive connections&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;The management-server part is set to "Anyhost" in the GUI.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2020 07:57:37 GMT</pubDate>
    <dc:creator>ias_gc-dk</dc:creator>
    <dc:date>2020-02-04T07:57:37Z</dc:date>
    <item>
      <title>"Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74053#M4334</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to automate deployment of a new VSX firewall and I am having trouble getting the Checkpoint management server to accept my input. The firewall management is version 80.20 and I have no trouble logging in and getting the session-id. I have made it so that awk reads a file (default-host-objects.csv) containing object-names,ip-address and then executes a cURL command:&lt;/P&gt;&lt;P&gt;My test-script look like this:&lt;/P&gt;&lt;P&gt;cp_api_url="&lt;A href="https://mgmt-station.net/web_api" target="_blank"&gt;https://mgmt-station.net/web_api&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;SID=`curl -s -k -H "Content-Type: application/json" -H "Accept: bla" -X POST "$cp_api_url/login" -d "{\"user\":\"admin-user\",\"password\":"\"admin-password"",\"domain\":\"test-domain\"}" | awk -F\" '/sid/ {print $4}'`&lt;/P&gt;&lt;P&gt;awk -F, -v aSID="$SID" -v cpurl="$cp_api_url" '{ system("curl -k -H \"Content-Type: application/json\" -H \"X-chkp-sid: "aSID"\" -X POST -d \"{ \"name\": \""$1"\", \"ip-address\": \""$2"\" }\" "cpurl"/add-host") }' default-host-objects.csv&lt;/P&gt;&lt;P&gt;The result I get is this:&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"code" : "generic_err_invalid_syntax",&lt;BR /&gt;"message" : "Payload is not a valid JSON"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;I also tried manually to create the objects by these commands:&lt;/P&gt;&lt;P&gt;curl -k -H Content-Type: application/json -H X-chkp-sid: &amp;lt;insert sid&amp;gt; -X POST -d { name: testserver1, ip-address: 1.2.3.4 } &lt;A href="https://mgmt-station.net/web_api/add-host" target="_blank"&gt;https://mgmt-station.net/web_api/add-host&lt;/A&gt;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;curl -k -H "Content-Type: application/json" -H "&amp;lt;insert sid&amp;gt;" -X POST -d "{ "name": "testserver1", "ip-address": "1.2.3.4" }" &lt;A href="https://mgmt-station.net/web_api/add-host" target="_blank"&gt;https://mgmt-station.net/web_api/add-host&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Both with the same result:&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"code" : "generic_err_invalid_syntax",&lt;BR /&gt;"message" : "Payload is not a valid JSON"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2020 19:33:54 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74053#M4334</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-03T19:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74083#M4335</link>
      <description>You have to enable API Access first.&lt;BR /&gt;See: &lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/Enabling-web-api/m-p/32641#M2011" target="_blank"&gt;https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/Enabling-web-api/m-p/32641#M2011&lt;/A&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:36:38 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74083#M4335</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2020-02-04T07:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74084#M4336</link>
      <description>&lt;P&gt;API access is already enabled. Otherwise I wouldn't be able to login in and get a session-id, would I?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:37:54 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74084#M4336</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-04T07:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74088#M4338</link>
      <description>&lt;P&gt;I just checked the API status:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# api status&lt;/P&gt;&lt;P&gt;API Settings:&lt;BR /&gt;---------------------&lt;BR /&gt;Accessibility: Require all granted&lt;BR /&gt;Automatic Start: Enabled&lt;/P&gt;&lt;P&gt;Processes:&lt;/P&gt;&lt;P&gt;Name State PID More Information&lt;BR /&gt;-------------------------------------------------&lt;BR /&gt;API Started 23009&lt;BR /&gt;CPM Started 21940 Check Point Security Management Server is running and ready&lt;BR /&gt;FWM Started 22231&lt;BR /&gt;APACHE Started 5568&lt;/P&gt;&lt;P&gt;Port Details:&lt;BR /&gt;-------------------&lt;BR /&gt;JETTY Internal Port: 50276&lt;BR /&gt;APACHE Gaia Port: 443&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;Overall API Status: Started&lt;BR /&gt;--------------------------------------------&lt;/P&gt;&lt;P&gt;API readiness test SUCCESSFUL. The server is up and ready to receive connections&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;----&lt;/P&gt;&lt;P&gt;The management-server part is set to "Anyhost" in the GUI.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:57:37 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74088#M4338</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-04T07:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74118#M4339</link>
      <description>&lt;P&gt;just tried it with the allow all ip addreses set. no difference:&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"code" : "generic_err_invalid_syntax",&lt;BR /&gt;"message" : "Payload is not a valid JSON"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Is there a log somewhere, where I can see more details as to why it thinks the payload is not valid JSON?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 13:55:20 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74118#M4339</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-04T13:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74139#M4340</link>
      <description>&lt;P&gt;Try putting putting your data in single quotes:&lt;/P&gt;
&lt;PRE&gt;# curl -k -H "Content-Type: application/json" -H "X-chkp-sid: ${SID}" \ &lt;BR /&gt;-X POST -d '{"name": "test1", "ip-address": "10.10.10.10"}' https://&lt;EM&gt;mgmt_server&lt;/EM&gt;/web_api/add-host&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt;{&lt;BR /&gt;"uid" : "f0b7bdf9-ac56-46a3-8cf2-9687012afc89",&lt;BR /&gt;"name" : "test1",&lt;BR /&gt;"type" : "host",&lt;BR /&gt;"domain" : {&lt;BR /&gt;"uid" : "41e821a0-3720-11e3-aa6e-0800200c9fde",&lt;BR /&gt;"name" : "SMC User",&lt;BR /&gt;"domain-type" : "domain"&lt;BR /&gt;},&lt;BR /&gt;"ipv4-address" : "10.10.10.10",&lt;BR /&gt;"interfaces" : [ ],&lt;BR /&gt;"nat-settings" : {&lt;BR /&gt;"....&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 17:22:02 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74139#M4340</guid>
      <dc:creator>masher</dc:creator>
      <dc:date>2020-02-04T17:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74211#M4343</link>
      <description>&lt;P&gt;I just tried that, same result.&lt;/P&gt;&lt;P&gt;Then I tried using the jq tool to format the JSON for me and then pass it to awk, to make sure JSON was formatted correctly.&amp;nbsp; Granted I told jq to format it on one line (using -c), but the same result comes up.&lt;/P&gt;&lt;P&gt;Then I went basic, I did a little script that just logs into mgmt-server and then generates what I believe is the correct command so I could manually enter the command one by one: I ended up with this command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;curl -k -H "Content-Type: application/json" -H "X-chkp-sid: gLlxu0y9oG541DCyQmOPc1hPX0UiA_1111111111111" -X POST -d '{"name":"test1","ip-address":"10.10.10.10"}' &lt;A href="https://mgmt_server/web_api/add-host" target="_blank"&gt;https://mgmt_server/web_api/add-host&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As far as I can see, the JSON is formatted correctly, but I still get the usual error-message:&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"code" : "generic_err_invalid_syntax",&lt;BR /&gt;"message" : "Payload is not a valid JSON"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;I am starting to think there is something malfunctioning with the management-servers API, because I have no problems posting to REST-api's on other systems using JSON formatting, e.g. Netbox.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 13:24:31 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74211#M4343</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-05T13:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74217#M4344</link>
      <description>&lt;P&gt;hmm.. seems this was the solution after all.&lt;/P&gt;&lt;P&gt;After trying back and forth, I tried the same command again, just for the h.. of it and it suddenly worked.&lt;/P&gt;&lt;P&gt;I'll see where this takes me, thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 13:44:06 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74217#M4344</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-05T13:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: "Payload is not a valid JSON" when bash scripting with cURL</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74227#M4345</link>
      <description>&lt;P&gt;btw, I found this article on how to quote single-quotes inside a script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings" target="_blank"&gt;https://stackoverflow.com/questions/1250079/how-to-escape-single-quotes-within-single-quoted-strings&lt;/A&gt;&lt;/P&gt;&lt;P&gt;perhaps its useful for others.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 14:30:22 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/quot-Payload-is-not-a-valid-JSON-quot-when-bash-scripting-with/m-p/74227#M4345</guid>
      <dc:creator>ias_gc-dk</dc:creator>
      <dc:date>2020-02-05T14:30:22Z</dc:date>
    </item>
  </channel>
</rss>

