Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Ricardo Dias
    @slowdata

    .then((data) => {
    console.log(data);

    const info = $REST.Web(url).Lists("Tiago").getInfo();
    info.headers["Authorization"] = data.headers.Authorization;
    
    
    request({
      method: info.method,
      headers: info.headers,
      uri: info.url,
      json: true,
    })
      .then((res) => console.log("»»» ", JSON.parse(res).d))
      .catch((err) => console.log(">>> ", err));

    });

    I'm don't even now it our sharepoint is ready to use the API. And also the correct endpoints
    Andrew Koltyakov
    @koltyakov
    Don’t know what this rest client. Headers is not the only thing needed for a call with NTLM. Please try sp-request if it can fetch anything in your env without auth issues.
    Ricardo Dias
    @slowdata
    The request is -> const request = require("request-promise");
    Andrew Koltyakov
    @koltyakov
    If it could it’s about options binding into the request.
    Ricardo Dias
    @slowdata
    Ho can i test it with sq-request?
    Andrew Koltyakov
    @koltyakov
    By sending any REST request. E.g. getting a web title so you know that it’s not about auth configuration. http(s)://hostname/sites/site/_api/web?$select=Title
    Ricardo Dias
    @slowdata
    Using the browser?
    Andrew Koltyakov
    @koltyakov
    But using a tool which binds required auth to a call. Like sp-request or pnp-auth.
    In Node of course :)
    If to take a look into what sp-request does, it's not only headers https://github.com/s-KaiNet/sp-request/blob/master/src/core/SPRequest.ts#L56
    That's why NTLM request ends up with 401
    Ricardo Dias
    @slowdata
    I'm getting lost.. sorry.
    Ricardo Dias
    @slowdata
    Do you mean somthing like this:
    spauth .getAuth("http://sharedev.seg-social.pt/sites/rpa/_api/web?$select=Title", { username: "user", password: "passowrd", domain: "segsocial", }) .then((res) => console.log(res));
    Ricardo Dias
    @slowdata
    Andrew, the password must be encripted?
    Andrew Koltyakov
    @koltyakov

    @slowdata I'm suggesting trying something as shown in that https://github.com/s-KaiNet/sp-request#get-list-by-title sample.

    spauth .getAuth("http://sharedev.seg-social.pt/sites/rpa/_api/web?$select=Title", { username: "user", password: "passowrd", domain: "segsocial", }) .then((res) => console.log(res));

    That won't gonna work this way.

    the password must be encripted?

    No, it should not be encrypted when passing to node-sp-auth.

    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