We need to create a text file and upload it to a document library using REST API. The contents of text file will be created dynamically by reading information from multiple lists. The operation needs to be performed using REST API and file is not to be saved in user's machine. Is this possible?

1 Answer 1


Yes, its possible.

Try and modify the below code. Fill the content with data from your lists:

var content = "Hello, this text is inside the file created with REST API";
var digest = $("#__REQUESTDIGEST").val();
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('/sites/test/Shared Documents')/Files/add(overwrite=true, url='test.txt')";
    url: url,
    type: "POST",
    data: content,
    headers: {        
        "accept": "application/json;odata=verbose", 
        "X-RequestDigest": digest       
    success: function(data){
    error: function(data){
  • Didn't realize it was that simple...! Thanks.
    – Naveen
    Jan 15, 2018 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.