Fetch active AD groups in site collection using PnP powershell for SP 2013

The requirement is to fetch all active AD groups in a site collection using pnp powerhsell in SP 2013. We have tried querying the User Info list and also web.siteusers but have noticed that this fetches all users and AD groups including historical ones which are now deleted. These are not needed.

Is there any other way to achieve this?

javascript – A simple wrapper around fetch

I am writing a simple wrapper around fetch.

async function apiCall(
  endpoint: string,
  {
    data,
    headers: customHeaders,
    ...customConfig
  }: { data?: Object; headers?: Object } = {}
) {
  const config = {
    method: data ? 'POST' : 'GET',
    body: data ? JSON.stringify(data) : undefined,
    headers: {
      'content-type': data ? 'application/json' : undefined,
      ...customHeaders,
    },
    ...customConfig,
  }

  return fetch(endpoint, config as any).then(async (response) => {
    if (response.ok) {
      const json = await response.json() // 🤔
      return json
    } else {
    // 👇 🚨 what if `response` contains error messages in json format?
      return Promise.reject(new Error('Unknown Error'))
    }
  })
}

it works fine. The problem is with this snippet

 return fetch(endpoint, config as any).then(async (response) => {
    if (response.ok) {
      const json = await response.json()
      return json
    } else {
    // 👇 🚨 what if `response` contains error messages in json format?
      return Promise.reject(new Error('Unknown Error'))
    }
  })

if response is not ok, it rejects with a generic Error. This is because by default, window.fetch will only reject a promise if the actual network request failed. But the issue is that, even if response is not ok, it might still be able to have error messages in json format. This depends on the backend implementation details but sometimes you are able to get the error messages in the response body by response.json(). Now this use case is not covered in the wrapper I built.

So I wonder how I am going to be able to account for that? I guess you can do something like

fetch(endpoint, config as any).then(async (response) => {
      if (response.ok) {
        const json = await response.json()
        return json
      } else {
          try {
            const json = await response.json()
            return Promise.reject(json)
          } catch {
            return Promise.reject(new Error('Unknown Error'))
          }
      }
    })

but I wonder if there is some more elegant way to do that?

Lastly, I am very aware of libraries like Axios. I built this partly to satisfy my intellectual curiosity.

Btw, a lightly unrelated question but I wonder if these two are equivalent

 if (response.ok) {
        const json = await response.json()
        return json
      }
 if (response.ok) {
        return response.json()
      }

json – JavaScript: I am writing a simple wrapper around fetch

I am writing a simple wrapper around fetch.

async function apiCall(
  endpoint: string,
  {
    data,
    headers: customHeaders,
    ...customConfig
  }: { data?: Object; headers?: Object } = {}
) {
  const config = {
    method: data ? 'POST' : 'GET',
    body: data ? JSON.stringify(data) : undefined,
    headers: {
      'content-type': data ? 'application/json' : undefined,
      ...customHeaders,
    },
    ...customConfig,
  }

  return fetch(endpoint, config as any).then(async (response) => {
    if (response.ok) {
      const json = await response.json() // 🤔
      return json
    } else {
    // 👇 🚨 what if `response` contains error messages in json format?
      return Promise.reject(new Error('Unknown Error'))
    }
  })
}

it works fine. The problem is with this snippet

 return fetch(endpoint, config as any).then(async (response) => {
    if (response.ok) {
      const json = await response.json()
      return json
    } else {
    // 👇 🚨 what if `response` contains error messages in json format?
      return Promise.reject(new Error('Unknown Error'))
    }
  })

if response is not ok, it rejects with a generic Error. This is because by default, window.fetch will only reject a promise if the actual network request failed. But the issue is that, even if response is not ok, it might still be able to have error messages in json format. This depends on the backend implementation details but sometimes you are able to get the error messages in the response body by response.json(). Now this use case is not covered in the wrapper I built.

So I wonder how I am going to be able to account for that? I guess you can do something like

fetch(endpoint, config as any).then(async (response) => {
      if (response.ok) {
        const json = await response.json()
        return json
      } else {
          try {
            const json = await response.json()
            return Promise.reject(json)
          } catch {
            return Promise.reject(new Error('Unknown Error'))
          }
      }
    })

but I wonder if there is some more elegant way to do that?

Lastly, I am very aware of libraries like Axios. I built this partly to satisfy my intellectual curiosity.

Btw, a lightly unrelated question but I wonder if these two are equivalent

 if (response.ok) {
        const json = await response.json()
        return json
      }
 if (response.ok) {
        return response.json()
      }

REST API to fetch block by height

I am trying to incorporate bitcoin in one of the applications and want to integrate the REST API which exposes all the public information.

I tried using https://chain.api.btc.com/v3/block/3 but upon multiple requests, it starts to error out with message “Do not abuse the api”.

Kindly provide the reference to API which I can use

Note: Tried https://testnet.blockexplorer.com/api as well but doesnt work. Even the link on https://github.com/blockchain/api-v1-client-python#request-limits-and-api-keys leads to error page on web

entities – How do I fetch a referenced entity value in hook_node_presave()?

I have two content types: Author and Stories. Author has an entity referenced field for Stories nodes. When I create an Author node, I need to get the story title, the creation date, etc in hook_node_presave() or hook_node_insert().

How do I achieve this?

Fetch an image in a specific folder in OneDrive/SharePoint via PowerShell or Azure Logicapp

I have a Microsoft Form that can be filled with an attachment before sending:

enter image description here

During testing I realized uploaded content was always sent to the same folder inside the receiver’s personal OneDrive.

Knowing OneDrive and SharePoint are basically the same I attempted to use the SharePoint PS Module for testing to see if I could fetch the most recent image, but nothing worked.

I need to be able to retrieve the most recent image in a static folder in OneDrive and save it so I can forward it in the same snippet of code via a POST request. Is that possible? My idea would be to somehow use logicapps to access the folder and retrieve the image if through PS that isn’t possible.

Thank you!