Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Ricardo Dias
    @slowdata
    Andrew, using you example a get the Id: 2a3242d4-f247-4cfe-a232-87fbcfc87aa1
    So it seems ok
    Now I need your help to understand it
    Should I just use -> sp-request
    Andrew Koltyakov
    @koltyakov
    If a number of requests in your automation is moderate. Yes, why not use what works for you.
    If it's a variety of different API actions and a fluent helper is desired, then PnPjs + pnp-auth (auth bindings for PnPjs with node-sp-auth).
    Ricardo Dias
    @slowdata
    And using sp-request how can I send files to a List?
    Can you please help me?
    Andrew Koltyakov
    @koltyakov
    Google search: "SharePoint REST API uploading files". Just wondering, are you going asking each next portion of questions regarding your task? ;)
    As a hint of the direction - https://github.com/s-KaiNet/spsave/blob/master/src/core/FileSaver.ts#L89 - you can take a look how to upload a file with sp-request.
    Or using PnPjs - https://pnp.github.io/pnpjs/sp/files/#adding-files
    Or using large files and streaming - https://github.com/koltyakov/pnp-upload
    I'd encourage to dive into that samples and try it first.
    Ricardo Dias
    @slowdata
    Andrew, I thank you very match. I'm new with this and struggling a lot to accomplish this.
    Andrew Koltyakov
    @koltyakov
    All of the suggestions are based on node-sp-auth so you can easily use spsave as a black box and bind creds into there if diving to a low level and figuring out how SP REST API works is not an option.
    Ricardo Dias
    @slowdata
    My main task is to upload a list of files for a Sharepoint List.
    I need to accomplish this and if I do understand all... then perfect
    Andrew Koltyakov
    @koltyakov
    Document library, not a list. List is a container for items not documents.
    I'd just use spsave then as a black-box function for a purpose for uploading.
    Ricardo Dias
    @slowdata
    My collegue that understands more of sharepoint than I says in list you get Picture field tha u can put there!
    Ricardo Dias
    @slowdata
    It's an attachment!
    Andrew Koltyakov
    @koltyakov
    spsave doesn't upload attachments. See these methods https://pnp.github.io/pnpjs/sp/attachments/#add-an-attachment
    The mechanics for uploading a file or attachments is mostly similar though.
    Ricardo Dias
    @slowdata
    Andrew, once again thkx. I will look to pnp but I'm worry with authentication
    Ricardo Dias
    @slowdata
    My head is exploding... Trying pnpjs and pnp-auth I just can´t pass the problems with Ecma Modules and Common
    Andrew Koltyakov
    @koltyakov
    Ricardo Dias
    @slowdata
    Andrew, trying to follow that README I get an error.
    Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: L:\testes\sp-node\node_modules\@pnp\common\index.js
    require() of ES modules is not supported.
    require() of L:\testes\sp-node\node_modules\@pnp\common\index.js from L:\testes\sp-node\node_modules\pnp-auth\lib\NodeFetchClient.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
    It's NodeFetchClient
    Ricardo Dias
    @slowdata
    @koltyakov Since I made it using sp-request I'm trying to add an Item to the List. I think a get a problem because spr.post it's sending Patch and not a Post. Can I change that?
    "X-HTTP-Method": "POST",
    Ricardo Dias
    @slowdata
    Can someone help how to attach the file? Andrew? I made a new list item and now trying to attach the file.
    Ricardo Dias
    @slowdata
    This is how I'm trying (followinf msft docs)
      const uri = `"https://share.seg-social.pt/sites/iss_dpc/covid19_MedidasExcecionais/_api/lists/GetByTitle('BO_SSD_teste')/items({${id}})/AttachmentFiles/add(FileName='{test.csv}')`;
      const r = await spr.post(uri, {
        body: f,
        headers: {
          "X-RequestDigest": digest,
          "X-HTTP-Method": "POST",
          "IF-MATCH": "*",
          "Content-Length": f.length,
        },
      });
    the file i get it from here: const f = await fs.readFile(path.resolve(__dirname, file));
    * TypeError: Cannot read property 'indexOf' of null
    at isOnPremUrl (L:\testes\sharepoint-node\node_modules\node-sp-auth\lib\src\auth\IAuthOptions.js:6:17)
    Sergei Sergeev
    @s-KaiNet

    @slowdata you have an error in your url -

    const uri = `"https://....

    " is not needed, just

    const uri = `https://...

    also why do you use extra {} in items({${id}})? You should use just tems(${id})
    and for file name just FileName='test.csv')

    Ricardo Dias
    @slowdata
    @s-KaiNet , true. Thkx.
    Still have an error. 400 - {"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"pt-PT","value":"A expressão \"lists/GetByTitle('BO_SSD_teste')/items({35})/AttachmentFiles/add(FileName='{test.csv}')\" não é válida."}}}
    Somthing is not valid
    Sergei Sergeev
    @s-KaiNet
    you haven't fixed items and file name issues, please try fixing them
    Ricardo Dias
    @slowdata
    So the url is invalid you say? ok. Don't now where the problem is...
    Sergei Sergeev
    @s-KaiNet
    items({${id}}) should be items(${id})
    FileName='{test.csv}' should be FileName='test.csv'
    Ricardo Dias
    @slowdata
    REally??
    so dumb..
    thkx Segei
    Ricardo Dias
    @slowdata
    Sergei can you help me with a file problem. I uploaded a csv file and it was ok. Tried with a ZIP file and when i wen't to download it it doesn't open. How can i read the file so it is in the original state.
    So when i download the file it opens nicelly
    Sergei Sergeev
    @s-KaiNet
    it depends how you read a file. Something below should work:
    var file = fs.readFileSync("path to the file")
    spr.post(url, {
     body: file,
    .....
    }
    Ricardo Dias
    @slowdata
    Thats how I made it. My zip is 10k when downloaded is 35k does not open
    const file = await fs.readFile(path.resolve(__dirname, fileName)
    const r = await spr.post(uri, {
    body: file,
    headers: {
    "X-RequestDigest": digest,
    "X-HTTP-Method": "POST",
    "IF-MATCH": "*",
    },
    });
    Sergei Sergeev
    @s-KaiNet
    strange... if you try any other binary file, say image, does it work?
    Ricardo Dias
    @slowdata
    1m.. testing it
    used png file. From 31k whent 105k and it opens with nothins
    Windows 10 image vier says: It looks like we don't support this file format
    Sergei Sergeev
    @s-KaiNet
    you use await fs.readFile - are you sure, that fs.readFile returns a promise?