Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: POST requests with JSON body for MS SharePoint operations

$
0
0
I use REST SDK to work with SharePoint 2013. To make some operations like creating or changing folders I need POST requests. It appears that those which contain JSON body do not work (server always responses HTTP 400 Bad request) while POST-s without body work well.
Can someone confirm whether I form request properly:
http_client_config config;
config.set_credentials(credentials(U("username"), U("password")));
http_client client(U("http://sharepointserver.com/"), config);

http_request request;
request.set_method(methods::POST);
request.headers().add(U("accept"), U("application/json; odata=verbose"));

// sharepoint-related stuff
request.headers().add(U("X-RequestDigest"), my_digest);
request.headers().add(U("X-HTTP-Method"), U("MERGE"));

// this should create folder but it does not - response HTTP 400
request.set_request_uri(web::uri::encode_uri(U("/_api/Web/GetFolderByServerRelativeUrl('/Shared Documents')/Folders")));
request.set_body(U("{ '__metadata':{ 'type': 'SP.Folder' }, 'ServerRelativeUrl':'new folder created' }"), U("application/json; odata=verbose"));
// other requests with request.set_body(... are also responded as HTTP 400
// but this works fine
// request.set_request_uri(web::uri::encode_uri(U("/_api/Web/Folders/add('/Shared Documents/new folder created')")));

client.request(request);
// wait, parse result etc.

Viewing all articles
Browse latest Browse all 4845

Trending Articles