<?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 How to Post JSON data to a site via API functionality: &amp;quot;Unsupported Media Type&amp;quot; in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-Post-JSON-data-to-a-site-via-API-functionality-quot/m-p/215881#M43117</link>
    <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to perform a POST request to post some JSON data to a server, but unfortunately as of now I keep getting a 415 error. The goal of this script is to upload a JSON formatted file (or something of the like) to the server for other users to download/read. I noticed that there are very few POST examples with JSL, but quite the abundance with GET, which I have no problems with. I was wondering if anyone else has encountered this sort of error/knows the solution to such a problem. Unfortunately, while I can't show some of the details (namely the server name and API Key), I can provide some of the script that I used to generate the request:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Create an Associative Array/Dictionary that can be converted to JSON format
aa=Associative Array();
aa&amp;lt;&amp;lt;Insert("Var1",1);
aa&amp;lt;&amp;lt;Insert("Var2",2);
aa&amp;lt;&amp;lt;Insert("Var3",3);

//Send the POST request, using JSON(aa). This yields a 415 error
url="Some URL that would include where to upload and the API key"
request = New HTTP Request(
       URL( url ), // the restAPI endpoint
       Method( "POST" ),
       JSON(aa);
);      
data=request&amp;lt;&amp;lt;Send();
Write(data);

//Version that first converts the associative array/dictionary to a JSON, then performs the POST request. This too, yields a 415 error
json=As JSON Expr(aa);
url="Some URL that would include where to upload and the API key"
request = New HTTP Request(
       URL( url ), // the restAPI endpoint
       Method( "POST" ),
       JSON(json);
);      
data=request&amp;lt;&amp;lt;Send();
Write(data);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, my attempts have consistently resulted in the following in the log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;HTTP/1.1 415 Unsupported Media Type&lt;BR /&gt;"&amp;lt;!DOCTYPE html PUBLIC \!"-//W3C//DTD XHTML 1.0 Strict//EN\!" \!"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\!"&amp;gt;&lt;BR /&gt;&amp;lt;html xmlns=\!"http://www.w3.org/1999/xhtml\!"&amp;gt;&lt;BR /&gt;&amp;lt;head&amp;gt;&lt;BR /&gt;&amp;lt;title&amp;gt;&lt;BR /&gt;GlassFish Server Open Source Edition 4.1 - Error report&lt;BR /&gt;&amp;lt;/title&amp;gt;&lt;BR /&gt;&amp;lt;style type=\!"text/css\!"&amp;gt;&lt;BR /&gt;&amp;lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--&amp;gt;&lt;BR /&gt;&amp;lt;/style&amp;gt;&lt;BR /&gt; &amp;lt;/head&amp;gt;&lt;BR /&gt;&amp;lt;body&amp;gt;&lt;BR /&gt;&amp;lt;h1&amp;gt;HTTP Status 415 - Unsupported Media Type&amp;lt;/h1&amp;gt;&lt;BR /&gt;&amp;lt;hr/&amp;gt;&lt;BR /&gt;&amp;lt;p&amp;gt;&lt;BR /&gt;&amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt;&lt;BR /&gt; Status report&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;p&amp;gt;&lt;BR /&gt;&amp;lt;b&amp;gt;&lt;BR /&gt;message&lt;BR /&gt;&amp;lt;/b&amp;gt;&lt;BR /&gt;Unsupported Media Type&lt;BR /&gt;&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;p&amp;gt;&lt;BR /&gt;&amp;lt;b&amp;gt;&lt;BR /&gt;description&lt;BR /&gt;&amp;lt;/b&amp;gt;&lt;BR /&gt;The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.&lt;BR /&gt;&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;hr/&amp;gt;&lt;BR /&gt;&amp;lt;h3&amp;gt;&lt;BR /&gt;GlassFish Server Open Source Edition 4.1 &lt;BR /&gt;&amp;lt;/h3&amp;gt;&lt;BR /&gt;&amp;lt;/body&amp;gt;&lt;BR /&gt;&amp;lt;/html&amp;gt;"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Once again, if anyone else has experienced this, or knows the solution to such a problem, any help would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: I should probably clarify that I am trying to Post onto Dataverse, if that is of any help.&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jul 2019 19:45:39 GMT</pubDate>
    <dc:creator>liqinglei419</dc:creator>
    <dc:date>2019-07-08T19:45:39Z</dc:date>
    <item>
      <title>How to Post JSON data to a site via API functionality: "Unsupported Media Type"</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-Post-JSON-data-to-a-site-via-API-functionality-quot/m-p/215881#M43117</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to perform a POST request to post some JSON data to a server, but unfortunately as of now I keep getting a 415 error. The goal of this script is to upload a JSON formatted file (or something of the like) to the server for other users to download/read. I noticed that there are very few POST examples with JSL, but quite the abundance with GET, which I have no problems with. I was wondering if anyone else has encountered this sort of error/knows the solution to such a problem. Unfortunately, while I can't show some of the details (namely the server name and API Key), I can provide some of the script that I used to generate the request:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;//Create an Associative Array/Dictionary that can be converted to JSON format
aa=Associative Array();
aa&amp;lt;&amp;lt;Insert("Var1",1);
aa&amp;lt;&amp;lt;Insert("Var2",2);
aa&amp;lt;&amp;lt;Insert("Var3",3);

//Send the POST request, using JSON(aa). This yields a 415 error
url="Some URL that would include where to upload and the API key"
request = New HTTP Request(
       URL( url ), // the restAPI endpoint
       Method( "POST" ),
       JSON(aa);
);      
data=request&amp;lt;&amp;lt;Send();
Write(data);

//Version that first converts the associative array/dictionary to a JSON, then performs the POST request. This too, yields a 415 error
json=As JSON Expr(aa);
url="Some URL that would include where to upload and the API key"
request = New HTTP Request(
       URL( url ), // the restAPI endpoint
       Method( "POST" ),
       JSON(json);
);      
data=request&amp;lt;&amp;lt;Send();
Write(data);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, my attempts have consistently resulted in the following in the log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;HTTP/1.1 415 Unsupported Media Type&lt;BR /&gt;"&amp;lt;!DOCTYPE html PUBLIC \!"-//W3C//DTD XHTML 1.0 Strict//EN\!" \!"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\!"&amp;gt;&lt;BR /&gt;&amp;lt;html xmlns=\!"http://www.w3.org/1999/xhtml\!"&amp;gt;&lt;BR /&gt;&amp;lt;head&amp;gt;&lt;BR /&gt;&amp;lt;title&amp;gt;&lt;BR /&gt;GlassFish Server Open Source Edition 4.1 - Error report&lt;BR /&gt;&amp;lt;/title&amp;gt;&lt;BR /&gt;&amp;lt;style type=\!"text/css\!"&amp;gt;&lt;BR /&gt;&amp;lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--&amp;gt;&lt;BR /&gt;&amp;lt;/style&amp;gt;&lt;BR /&gt; &amp;lt;/head&amp;gt;&lt;BR /&gt;&amp;lt;body&amp;gt;&lt;BR /&gt;&amp;lt;h1&amp;gt;HTTP Status 415 - Unsupported Media Type&amp;lt;/h1&amp;gt;&lt;BR /&gt;&amp;lt;hr/&amp;gt;&lt;BR /&gt;&amp;lt;p&amp;gt;&lt;BR /&gt;&amp;lt;b&amp;gt;type&amp;lt;/b&amp;gt;&lt;BR /&gt; Status report&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;p&amp;gt;&lt;BR /&gt;&amp;lt;b&amp;gt;&lt;BR /&gt;message&lt;BR /&gt;&amp;lt;/b&amp;gt;&lt;BR /&gt;Unsupported Media Type&lt;BR /&gt;&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;p&amp;gt;&lt;BR /&gt;&amp;lt;b&amp;gt;&lt;BR /&gt;description&lt;BR /&gt;&amp;lt;/b&amp;gt;&lt;BR /&gt;The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.&lt;BR /&gt;&amp;lt;/p&amp;gt;&lt;BR /&gt;&amp;lt;hr/&amp;gt;&lt;BR /&gt;&amp;lt;h3&amp;gt;&lt;BR /&gt;GlassFish Server Open Source Edition 4.1 &lt;BR /&gt;&amp;lt;/h3&amp;gt;&lt;BR /&gt;&amp;lt;/body&amp;gt;&lt;BR /&gt;&amp;lt;/html&amp;gt;"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Once again, if anyone else has experienced this, or knows the solution to such a problem, any help would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: I should probably clarify that I am trying to Post onto Dataverse, if that is of any help.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 19:45:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-Post-JSON-data-to-a-site-via-API-functionality-quot/m-p/215881#M43117</guid>
      <dc:creator>liqinglei419</dc:creator>
      <dc:date>2019-07-08T19:45:39Z</dc:date>
    </item>
  </channel>
</rss>

