<?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: Post to SharePoint 2010 list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432511#M107139</link>
    <description>&lt;P&gt;Wouldn't&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;NOTE: 405 Method Not Allowed&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;mean that&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	method&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"POST"&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is disallowed?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2018 21:14:43 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2018-01-30T21:14:43Z</dc:date>
    <item>
      <title>Post to SharePoint 2010 list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432172#M106998</link>
      <description>&lt;P&gt;I am trying to figure out how to add a new item or update an existing item using SAS PROC HTTP in a SharePoint 2010 list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a javascript/jquery button action that is tied to a temporary list to test posting data form SAS to SharePoint 2010.&amp;nbsp; I've verified that the below code updates the first item's title to "I am a robot" and inserts a new item with the title "I am a robot too"&amp;nbsp; &amp;nbsp;This is javascript that is updating the list item or creating the list item using the SharePoint API (JSON data).&amp;nbsp; The data update in the list is attached as a screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;$('#testerbtn').click(function(event) {
			var beforeSendFunction = function (xhr) {
								   xhr.setRequestHeader("If-Match", "*");
								   // Using MERGE so that the entire entity doesn't need to be sent over the wire.
								   xhr.setRequestHeader("X-HTTP-Method", 'MERGE');
			}
			
			//Update an existing item, Item 1, with I am a robot as the title
	        var d = {};
			d.Title = 'I am a robot';
			var URL = thisbase.toLowerCase() + "/_vti_bin/ListData.svc/Tester2(1)";
			console.log('data: '+JSON.stringify(d));
			console.log(URL);
			var call = $.ajax({ 
		                   type: "POST",
		                   contentType: "application/json; charset=utf-8",
		                   processData: false,
		                   beforeSend: beforeSendFunction,
		                   url: URL,
		                   data: JSON.stringify(d),
		                   dataType: "json"		
			});					                   
			call.done(function (data,textStatus, jqXHR){
				alert('success');			
			});
			call.fail(function (jqXHR,textStatus,errorThrown){ 
				alert('error. see logs');
				console.log("Error in calendar data transmission: " + jqXHR.responseText); 
			}); 
	
	
			//Create a new item with I too am a robot as a title
			var d = {};
			d.Title = 'I too am a robot';
			var URL = thisbase.toLowerCase() + "/_vti_bin/ListData.svc/Tester2";	        
			console.log('data: '+JSON.stringify(d));
			console.log(URL);
			
			var call = $.ajax({ 
						   type: "POST",
		                   contentType: "application/json; charset=utf-8",
		                   processData: false,
		                   headers: {
					            "Accept": "application/json;odata=verbose",
					            "X-RequestDigest": $("#__REQUESTDIGEST").val()
					       },
		                   url: URL,
		                   data: JSON.stringify(d),
		                   dataType: "json"
			});
			call.done(function (data,textStatus, jqXHR){
				alert('success');			
			});
			call.fail(function (jqXHR,textStatus,errorThrown){ 
				alert('error. see logs');
				console.log("Error in calendar data transmission: " + jqXHR.responseText); 
			}); 
	
		event.preventDefault();
	
});&lt;/PRE&gt;
&lt;P&gt;Here is what the data looks like that is submitted to sharepoint:&lt;/P&gt;
&lt;PRE&gt;data: {"Title":"I am a robot"}

data: {"Title":"I too am a robot"}&lt;/PRE&gt;
&lt;P&gt;So I tried to repeat this with SAS PROC HTTP.&amp;nbsp; I think PROC JSON will only output an array, so I tried a string with no luck.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename resp TEMP;
proc json out=resp pretty;
	export work.tester (where=(one='A')) / nosastags;
run;
 
filename topics "C:\temp\tester_resp_json.txt" encoding="UTF-8";

/*		                   type: "POST",
		                   contentType: "application/json; charset=utf-8",
		                   processData: false,
		                   beforeSend: beforeSendFunction,
		                   url: URL,
		                   data: JSON.stringify(d),
		                   dataType: "json"		
*/

proc http url="http://sharepoint.site/subsite/_vti_bin/ListData.svc/Tester2(1)" 
	method="POST" in=resp /*"{'Title':'I am not a robot'}" */
	out=topics AUTH_NEGOTIATE; 
	debug level = 0;
	headers
		"contentType "="application/json;odata=verbose;charset=utf-8"
		"processData"="false"
		"beforeSend"="function (xhr) {xhr.setRequestHeader('If-Match', '*'); xhr.setRequestHeader('X-HTTP-Method', 'MERGE');"
		"Accept"="application/json; charset=utf-8" 
		"dataType"="json";
	
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I look at the output, because I get this error:&lt;/P&gt;
&lt;P&gt;NOTE: PROCEDURE HTTP used (Total process time):&lt;BR /&gt;real time 0.31 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;NOTE: 405 Method Not Allowed&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what the output says&lt;/P&gt;
&lt;PRE&gt;{
"error": {
"code": "", "message": {
"lang": "en-US", "value": "The URI 'http://sharepoint.site/subsite/_vti_bin/ListData.svc/Tester2(1)/' is not valid for POST operation. For POST operations, the URI must refer to a service operation or an entity set."
}
}&lt;/PRE&gt;
&lt;P&gt;Results after using the javascript (no success yet using SAS)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="success post using javacript" style="width: 501px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18185iFAB0187F78B1E7D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="I am a robot.PNG" alt="success post using javacript" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;success post using javacript&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Apr 2018 14:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432172#M106998</guid>
      <dc:creator>dwaynejarman</dc:creator>
      <dc:date>2018-04-08T14:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Post to SharePoint 2010 list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432511#M107139</link>
      <description>&lt;P&gt;Wouldn't&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;NOTE: 405 Method Not Allowed&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;mean that&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	method&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"POST"&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is disallowed?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 21:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432511#M107139</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-01-30T21:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Post to SharePoint 2010 list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432595#M107154</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Made some modification, but now am getting an HTTP error 415.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename topics "C:\temp\tester_resp_json.txt" encoding="UTF-8";
filename submit "C:\temp\submit.txt" encoding="UTF-8";

proc http url="http://sharepoint.site/subsite/_vti_bin/ListData.svc/Tester2(1)" 
	method="POST" in=submit
	out=topics AUTH_NEGOTIATE; 
	headers
		"dataType"="json"
		"contentType"="application/json; charset=utf-8"
		"processData"="false"
		"X-HTTP-Method"="MERGE"
		"If-Match"="*" ;		
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The dataType matches what works using JavaScript.&amp;nbsp; I'm not sure what could be going on as the CT= option has depreciated since 9.4 M3 from the documents.&amp;nbsp;&amp;nbsp; Any thoughts?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Apr 2018 14:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/432595#M107154</guid>
      <dc:creator>dwaynejarman</dc:creator>
      <dc:date>2018-04-08T14:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Post to SharePoint 2010 list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/435266#M108118</link>
      <description>&lt;P&gt;Using the SharePoint api's is on my "bucket list of SAS programs" to try and work out out some day (to be more portable across platforms).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On Windows, what I've been doing for many years is creating a Microsoft Access Database which contains a link to the SharePoint list.&amp;nbsp; Then in SAS, I access the database (team site list) via SAS/Access:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;2    libname teamsite access "D:\Public\SharePoint\Public.accdb";
NOTE: Libref TEAMSITE was successfully assigned as follows:
      Engine:        ACCESS
      Physical Name: D:\Public\SharePoint\Public.accdb
3
4    proc sql noprint;
5    create table work.subset as
6    select * from teamsite.admins;
NOTE: Table WORK.SUBSET created, with 88 rows and 26 columns.

7    quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.36 seconds
      user cpu time       0.04 seconds
      system cpu time     0.04 seconds
      memory              5330.31k
      OS Memory           13796.00k
      Timestamp           02/08/2018 09:22:39 AM
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using proc sql, we can also update/delete/insert rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 14:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/435266#M108118</guid>
      <dc:creator>DaveHorne</dc:creator>
      <dc:date>2018-02-08T14:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Post to SharePoint 2010 list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/452181#M114091</link>
      <description>Thanks DaveHome, that is a good approach. Sharepoint will only allow 5,000 records in one view. So the approach in access will work if you are only working with a small list or want to connect to the data in the default view which is less than 5,000 records.&lt;BR /&gt;&lt;BR /&gt;I built a macro to recursively pull all data available in a sharepoint list into a sas data table. From there I would like to query and update. One of my lists has over 10,000 records and using access as the intermediary would not work. I did some digging and it seems like the http 415 is unsupported media type. From looking at other posts it is possible that my code is pulling in the JSON as an object not as a string which sharepoint expects.&lt;BR /&gt;&lt;BR /&gt;When I get back to work I will try posting a string to the server using the test above, so instead of calling the file I would replace in the code&lt;BR /&gt;&lt;BR /&gt;in='{"cpId": 1}' Taken from&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-using-PROC-HTTP-POST-method/td-p/420514" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Passing-parameters-using-PROC-HTTP-POST-method/td-p/420514&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;So in this case, I would try:&lt;BR /&gt;&lt;BR /&gt;in=‘{"Title": "I am not a robot","One": "A"}’&lt;BR /&gt;&lt;BR /&gt;Again, this is just guessing that the file is being read in as a file or as a JSON object when SharePoint’s api expects a string.&lt;BR /&gt;&lt;BR /&gt;If this works, a macro could be built to loop over data using proc sql and mass update records. It would be something like:&lt;BR /&gt;- query data&lt;BR /&gt;- build macro variables from query&lt;BR /&gt;- build strings to submit, including the data to change&lt;BR /&gt;- iterate through the macro variables to post the update&lt;BR /&gt;&lt;BR /&gt;Again, the primary goal here (not stated above) is to be able to manage sharepoint data in large lists from sas.</description>
      <pubDate>Sat, 07 Apr 2018 11:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/452181#M114091</guid>
      <dc:creator>dwaynejarman</dc:creator>
      <dc:date>2018-04-07T11:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Post to SharePoint 2010 list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/452200#M114097</link>
      <description>Another possibility to try :&lt;BR /&gt;filename submit "C:\temp\submit.txt" encoding="UTF-8";&lt;BR /&gt;data _null_;&lt;BR /&gt;length text $32767;&lt;BR /&gt;retain text '';&lt;BR /&gt;infile msghtml flowover dlmstr='//' end=last;&lt;BR /&gt;input;&lt;BR /&gt;text=cats(text,_infile_);&lt;BR /&gt;if last then call symput('submit',text);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Then on the proc http:&lt;BR /&gt;in=&amp;amp;submit&lt;BR /&gt;&lt;BR /&gt;Modified from &lt;A href="https://blogs.sas.com/content/sasdummy/2016/07/12/how-to-read-the-contents-of-a-file-into-a-sas-macro-variable/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2016/07/12/how-to-read-the-contents-of-a-file-into-a-sas-macro-variable/&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 07 Apr 2018 13:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Post-to-SharePoint-2010-list/m-p/452200#M114097</guid>
      <dc:creator>dwaynejarman</dc:creator>
      <dc:date>2018-04-07T13:54:26Z</dc:date>
    </item>
  </channel>
</rss>

