BookmarkSubscribeRSS Feed
kerrmc36
Fluorite | Level 6

I'm trying to perform a rest API POST request to upload an attachment to a Share Point List

 

I've successfully managed it with Postman via the file link on the Body /Binary tab of PostMan

(with URL https://mysharepointsite/_api/Web/Lists(guid'mylistguid')/items(7406)/AttachmentFiles/ add(FileName='myfile.xlsx')

but I can't work out how to code the binary data part in SAS Proc HTTP

The curl snippet for the binary content is 

--data-binary '@/Y:/API_Project/SharePoint/OutPut/myfile.xlsx'

This is my last attempt
proc http
url= "https://mysharepointsite/_api/Web/Lists(guid'mylistguid')/Items(7406)/AttachmentFiles/ add(FileName='myfile.xlsx')"
method = "POST"
OAUTH_BEARER= &token.
IN= '@/Y:/API_Project/SharePoint/OutPut/myfile.xlsx'
headerout = Atthead
HEADEROUT_OVERWRITE
clear_cache;
headers "X-RequestDigest"="&FDV." "Accept"="application/json";
run;
3 REPLIES 3
JosvanderVelden
SAS Super FREQ
Have you seen @ ChrisHemedinger solution in this post: https://communities.sas.com/t5/SAS-Programming/How-to-make-a-PROC-HTTP-Post-request-by-passing-a-JSO...
I believe that has an example that will work for you.
kerrmc36
Fluorite | Level 6

Many thanks for quick reply - I'll try creating a JSON file to read in put I'm still unclear how I should reference the file path in the JSON.  What key should I use to reference ?

ChrisHemedinger
Community Manager

I have not tried methods to add attachments -- only to upload files into a SharePoint collection. I've got that code in some macros in this GitHub project: https://github.com/sascommunities/sas-microsoft-graph-api/

 

That method uses the Upload Session API that allows for large files. It seems like this attachment approach is different, but maybe you can glean some hints from it.

 

 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 167 views
  • 1 like
  • 3 in conversation