UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

26 lines 1.17 kB
import { FPS_SPHttpClientConfigurations } from "../../../../../types/@msft/1.4.1/IFPSSPHttpClientConfiguration"; /** * Use this for cases where you need a request digestValue for API calls * * getRequestDigestFromClass REQUIRES the Class, NOT NULL * Was previously named getRequestDigest * * @param classContext * @param absoluteWebUrl * @returns */ export async function getRequestDigestFromContext(classContext, absoluteWebUrl) { let httpPostOptions = { headers: { "accept": "application/json", "content-type": "application/json", } }; // Using this to make it possible to test extension on one site where the extension is not installed const useUrl = absoluteWebUrl ? absoluteWebUrl : classContext.pageContext.web.absoluteUrl; const response = await classContext.spHttpClient.post(`${useUrl}/_api/contextinfo`, FPS_SPHttpClientConfigurations.v1, httpPostOptions); const data = await response.json(); console.log('getRequestDigest FormDigestValue:', data.FormDigestValue); return data.FormDigestValue; } //# sourceMappingURL=getRequestDigestFromContext.js.map