Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!
Please check out the Docs to see if your question is already addressed there. This will help us ensure our documentation covers the most frequent questions.
Please specify what version of the library you are using: [+ @pnp/[email protected]
Hi, I am trying to do this in Lambda Nodejs and I placed the setup code before and now inside the exports.handler. No matter what I do I get: TypeError: sp.setup is not a function
This is my code:
'use strict';
var request = require('request');
var sp = require('@pnp/sp');
var SPFetchClient = require('@pnp/nodejs');
var getList = function(){
sp.web.select("WorkflowList").get().then(w => {
console.log(`Web Title: ${w.Title}`);
});
}
exports.handler = function (event, context, callback) {
sp.setup({
sp: {
fetchClientFactory: () => {
return new SPFetchClient("https://mycompany.sharepoint.com/sites/dev", "client id", "key");
},
},
});
getList();
};
The code looks fine. I don't know much about AWS Lamda but I did find this article on using packages within AWS - perhaps these steps can help? My guess would be that the library isn't present and sp is maybe null? You could check that with a console.log of the sp object.
Hi @patrick-rodgers thanks for your response!
I rechecked and reuploaded my code to lambda and am doing the console.log on sp and it's not null... but still no luck with sp.setup.
This is what console.log(sp) gives me:
2019-12-09T15:08:15.477Z 9f7110df-ab5f-43d9-b56f-25f126eafd9b INFO { ControlMode:
{ '1': 'Display',
'2': 'Edit',
'3': 'New',
Display: 1,
Edit: 2,
New: 3 },
FieldTypes:
{ '0': 'Invalid',
'1': 'Integer',
'2': 'Text',
'3': 'Note',
'4': 'DateTime',
'5': 'Counter',
'6': 'Choice',
'7': 'Lookup',
'8': 'Boolean',
'9': 'Number',
'10': 'Currency',
'11': 'URL',
'12': 'Computed',
'13': 'Threading',
'14': 'Guid',
'15': 'MultiChoice',
'16': 'GridChoice',
'17': 'Calculated',
'18': 'File',
'19': 'Attachments',
'20': 'User',
'21': 'Recurrence',
'22': 'CrossProjectLink',
'23': 'ModStat',
'24': 'Error',
'25': 'ContentTypeId',
'26': 'PageSeparator',
'27': 'ThreadIndex',
'28': 'WorkflowStatus',
'29': 'AllDayEvent',
'30': 'WorkflowEventType',
Invalid: 0,
Integer: 1,
Text: 2,
Note: 3,
DateTime: 4,
Counter: 5,
Choice: 6,
Lookup: 7,
Boolean: 8,
Number: 9,
Currency: 10,
URL: 11,
Computed: 12,
Threading: 13,
Guid: 14,
MultiChoice: 15,
GridChoice: 16,
Calculated: 17,
File: 18,
Attachments: 19,
User: 20,
Recurrence: 21,
CrossProjectLink: 22,
ModStat: 23,
Error: 24,
ContentTypeId: 25,
PageSeparator: 26,
ThreadIndex: 27,
WorkflowStatus: 28,
AllDayEvent: 29,
WorkflowEventType: 30 },
DateTimeFieldFormatType:
{ '0': 'DateOnly', '1': 'DateTime', DateOnly: 0, DateTime: 1 },
DateTimeFieldFriendlyFormatType:
{ '0': 'Unspecified',
'1': 'Disabled',
'2': 'Relative',
Unspecified: 0,
Disabled: 1,
Relative: 2 },
AddFieldOptions:
{ '0': 'DefaultValue',
'1': 'AddToDefaultContentType',
'2': 'AddToNoContentType',
'4': 'AddToAllContentTypes',
'8': 'AddFieldInternalNameHint',
'16': 'AddFieldToDefaultView',
'32': 'AddFieldCheckDisplayName',
DefaultValue: 0,
AddToDefaultContentType: 1,
AddToNoContentType: 2,
AddToAllContentTypes: 4,
AddFieldInternalNameHint: 8,
AddFieldToDefaultView: 16,
AddFieldCheckDisplayName: 32 },
CalendarType:
{ '1': 'Gregorian',
'3': 'Japan',
'4': 'Taiwan',
'5': 'Korea',
'6': 'Hijri',
'7': 'Thai',
'8': 'Hebrew',
'9': 'GregorianMEFrench',
'10': 'GregorianArabic',
'11': 'GregorianXLITEnglish',
'12': 'GregorianXLITFrench',
'14': 'KoreaJapanLunar',
'15': 'ChineseLunar',
'16': 'SakaEra',
'23': 'UmAlQura',
Gregorian: 1,
Japan: 3,
Taiwan: 4,
Korea: 5,
Hijri: 6,
Thai: 7,
Hebrew: 8,
GregorianMEFrench: 9,
GregorianArabic: 10,
GregorianXLITEnglish: 11,
GregorianXLITFrench: 12,
KoreaJapanLunar: 14,
ChineseLunar: 15,
SakaEra: 16,
UmAlQura: 23 },
UrlFieldFormatType: { '0': 'Hyperlink', '1': 'Image', Hyperlink: 0, Image: 1 },
PermissionKind:
{ '0': 'EmptyMask',
'1': 'ViewListItems',
'2': 'AddListItems',
'3': 'EditListItems',
'4': 'DeleteListItems',
'5': 'ApproveItems',
'6': 'OpenItems',
'7': 'ViewVersions',
'8': 'DeleteVersions',
'9': 'CancelCheckout',
'10': 'ManagePersonalViews',
'12': 'ManageLists',
'13': 'ViewFormPages',
'14': 'AnonymousSearchAccessList',
'17': 'Open',
'18': 'ViewPages',
'19': 'AddAndCustomizePages',
'20': 'ApplyThemeAndBorder',
'21': 'ApplyStyleSheets',
'22': 'ViewUsageData',
'23': 'CreateSSCSite',
'24': 'ManageSubwebs',
'25': 'CreateGroups',
'26': 'ManagePermissions',
'27': 'BrowseDirectories',
'28': 'BrowseUserInfo',
'29': 'AddDelPrivateWebParts',
'30': 'UpdatePersonalWebParts',
'31': 'ManageWeb',
'32': 'AnonymousSearchAccessWebLists',
'37': 'UseClientIntegration',
'38': 'UseRemoteAPIs',
'39': 'ManageAlerts',
'40': 'CreateAlerts',
'41': 'EditMyUserInfo',
'63': 'EnumeratePermissions',
'65': 'FullMask',
EmptyMask: 0,
ViewListItems: 1,
AddListItems: 2,
EditListItems: 3,
DeleteListItems: 4,
ApproveItems: 5,
OpenItems: 6,
ViewVersions: 7,
DeleteVersions: 8,
CancelCheckout: 9,
ManagePersonalViews: 10,
ManageLists: 12,
ViewFormPages: 13,
AnonymousSearchAccessList: 14,
Open: 17,
ViewPages: 18,
AddAndCustomizePages: 19,
ApplyThemeAndBorder: 20,
ApplyStyleSheets: 21,
ViewUsageData: 22,
CreateSSCSite: 23,
ManageSubwebs: 24,
CreateGroups: 25,
ManagePermissions: 26,
BrowseDirectories: 27,
BrowseUserInfo: 28,
AddDelPrivateWebParts: 29,
UpdatePersonalWebParts: 30,
ManageWeb: 31,
AnonymousSearchAccessWebLists: 32,
UseClientIntegration: 37,
UseRemoteAPIs: 38,
ManageAlerts: 39,
CreateAlerts: 40,
EditMyUserInfo: 41,
EnumeratePermissions: 63,
FullMask: 65 },
PrincipalType:
{ '0': 'None',
'1': 'User',
'2': 'DistributionList',
'4': 'SecurityGroup',
'8': 'SharePointGroup',
'15': 'All',
None: 0,
User: 1,
DistributionList: 2,
SecurityGroup: 4,
SharePointGroup: 8,
All: 15 },
PrincipalSource:
{ '0': 'None',
'1': 'UserInfoList',
'2': 'Windows',
'4': 'MembershipProvider',
'8': 'RoleProvider',
'15': 'All',
None: 0,
UserInfoList: 1,
Windows: 2,
MembershipProvider: 4,
RoleProvider: 8,
All: 15 },
RoleType:
{ '0': 'None',
'1': 'Guest',
'2': 'Reader',
'3': 'Contributor',
'4': 'WebDesigner',
'5': 'Administrator',
None: 0,
Guest: 1,
Reader: 2,
Contributor: 3,
WebDesigner: 4,
Administrator: 5 },
PageType:
{ '0': 'DefaultView',
'1': 'NormalView',
'2': 'DialogView',
'3': 'View',
'4': 'DisplayForm',
'5': 'DisplayFormDialog',
'6': 'EditForm',
'7': 'EditFormDialog',
'8': 'NewForm',
'9': 'NewFormDialog',
'10': 'SolutionForm',
'11': 'PAGE_MAXITEMS',
Invalid: -1,
'-1': 'Invalid',
DefaultView: 0,
NormalView: 1,
DialogView: 2,
View: 3,
DisplayForm: 4,
DisplayFormDialog: 5,
EditForm: 6,
EditFormDialog: 7,
NewForm: 8,
NewFormDialog: 9,
SolutionForm: 10,
PAGE_MAXITEMS: 11 },
SharingLinkKind:
{ '0': 'Uninitialized',
'1': 'Direct',
'2': 'OrganizationView',
'3': 'OrganizationEdit',
'4': 'AnonymousView',
'5': 'AnonymousEdit',
'6': 'Flexible',
Uninitialized: 0,
Direct: 1,
OrganizationView: 2,
OrganizationEdit: 3,
AnonymousView: 4,
AnonymousEdit: 5,
Flexible: 6 },
SharingRole:
{ '0': 'None',
'1': 'View',
'2': 'Edit',
'3': 'Owner',
None: 0,
View: 1,
Edit: 2,
Owner: 3 },
SharingOperationStatusCode:
{ '0': 'CompletedSuccessfully',
'1': 'AccessRequestsQueued',
CompletedSuccessfully: 0,
AccessRequestsQueued: 1,
NoResolvedUsers: -1,
'-1': 'NoResolvedUsers',
AccessDenied: -2,
'-2': 'AccessDenied',
CrossSiteRequestNotSupported: -3,
'-3': 'CrossSiteRequestNotSupported',
UnknowError: -4,
'-4': 'UnknowError',
EmailBodyTooLong: -5,
'-5': 'EmailBodyTooLong',
ListUniqueScopesExceeded: -6,
'-6': 'ListUniqueScopesExceeded',
CapabilityDisabled: -7,
'-7': 'CapabilityDisabled',
ObjectNotSupported: -8,
'-8': 'ObjectNotSupported',
NestedGroupsNotSupported: -9,
'-9': 'NestedGroupsNotSupported' },
SPSharedObjectType:
{ '0': 'Unknown',
'1': 'File',
'2': 'Folder',
'3': 'Item',
'4': 'List',
'5': 'Web',
'6': 'Max',
Unknown: 0,
File: 1,
Folder: 2,
Item: 3,
List: 4,
Web: 5,
Max: 6 },
SharingDomainRestrictionMode:
{ '0': 'None',
'1': 'AllowList',
'2': 'BlockList',
None: 0,
AllowList: 1,
BlockList: 2 },
RenderListDataOptions:
{ '0': 'None',
'1': 'ContextInfo',
'2': 'ListData',
'4': 'ListSchema',
'8': 'MenuView',
'16': 'ListContentType',
'32': 'FileSystemItemId',
'64': 'ClientFormSchema',
'128': 'QuickLaunch',
'256': 'Spotlight',
'512': 'Visualization',
'1024': 'ViewMetadata',
'2048': 'DisableAutoHyperlink',
'4096': 'EnableMediaTAUrls',
'8192': 'ParentInfo',
'16384': 'PageContextInfo',
'32768': 'ClientSideComponentManifest',
None: 0,
ContextInfo: 1,
ListData: 2,
ListSchema: 4,
MenuView: 8,
ListContentType: 16,
FileSystemItemId: 32,
ClientFormSchema: 64,
QuickLaunch: 128,
Spotlight: 256,
Visualization: 512,
ViewMetadata: 1024,
DisableAutoHyperlink: 2048,
EnableMediaTAUrls: 4096,
ParentInfo: 8192,
PageContextInfo: 16384,
ClientSideComponentManifest: 32768 },
FieldUserSelectionMode:
{ '0': 'PeopleOnly',
'1': 'PeopleAndGroups',
PeopleAndGroups: 1,
PeopleOnly: 0 },
ChoiceFieldFormatType:
{ '0': 'Dropdown',
'1': 'RadioButtons',
Dropdown: 0,
RadioButtons: 1 },
UrlZone:
{ '0': 'DefaultZone',
'1': 'Intranet',
'2': 'Internet',
'3': 'Custom',
'4': 'Extranet',
DefaultZone: 0,
Intranet: 1,
Internet: 2,
Custom: 3,
Extranet: 4 },
CheckinType:
{ '0': 'Minor',
'1': 'Major',
'2': 'Overwrite',
Minor: 0,
Major: 1,
Overwrite: 2 },
WebPartsPersonalizationScope: { '0': 'User', '1': 'Shared', User: 0, Shared: 1 },
MoveOperations:
{ '1': 'Overwrite',
'8': 'AllowBrokenThickets',
Overwrite: 1,
AllowBrokenThickets: 8 },
TemplateFileType:
{ '0': 'StandardPage',
'1': 'WikiPage',
'2': 'FormPage',
'3': 'ClientSidePage',
StandardPage: 0,
WikiPage: 1,
FormPage: 2,
ClientSidePage: 3 },
PromotedState:
{ '0': 'NotPromoted',
'1': 'PromoteOnPublish',
'2': 'Promoted',
NotPromoted: 0,
PromoteOnPublish: 1,
Promoted: 2 },
SortDirection:
{ '0': 'Ascending',
'1': 'Descending',
'2': 'FQLFormula',
Ascending: 0,
Descending: 1,
FQLFormula: 2 },
ReorderingRuleMatchType:
{ '0': 'ResultContainsKeyword',
'1': 'TitleContainsKeyword',
'2': 'TitleMatchesKeyword',
'3': 'UrlStartsWith',
'4': 'UrlExactlyMatches',
'5': 'ContentTypeIs',
'6': 'FileExtensionMatches',
'7': 'ResultHasTag',
'8': 'ManualCondition',
ResultContainsKeyword: 0,
TitleContainsKeyword: 1,
TitleMatchesKeyword: 2,
UrlStartsWith: 3,
UrlExactlyMatches: 4,
ContentTypeIs: 5,
FileExtensionMatches: 6,
ResultHasTag: 7,
ManualCondition: 8 },
QueryPropertyValueType:
{ '0': 'None',
'1': 'StringType',
'2': 'Int32Type',
'3': 'BooleanType',
'4': 'StringArrayType',
'5': 'UnSupportedType',
None: 0,
StringType: 1,
Int32Type: 2,
BooleanType: 3,
StringArrayType: 4,
UnSupportedType: 5 },
SocialActorType:
{ '0': 'User',
'1': 'Document',
'2': 'Site',
'3': 'Tag',
User: 0,
Document: 1,
Site: 2,
Tag: 3 },
SocialActorTypes:
{ '0': 'None',
'1': 'User',
'2': 'Document',
'4': 'Site',
'8': 'Tag',
'268435456': 'ExcludeContentWithoutFeeds',
'536870912': 'IncludeGroupsSites',
'1073741824': 'WithinLast24Hours',
None: 0,
User: 1,
Document: 2,
Site: 4,
Tag: 8,
ExcludeContentWithoutFeeds: 268435456,
IncludeGroupsSites: 536870912,
WithinLast24Hours: 1073741824 },
SocialFollowResult:
{ '0': 'Ok',
'1': 'AlreadyFollowing',
'2': 'LimitReached',
'3': 'InternalError',
Ok: 0,
AlreadyFollowing: 1,
LimitReached: 2,
InternalError: 3 },
SocialStatusCode:
{ '0': 'OK',
'1': 'InvalidRequest',
'2': 'AccessDenied',
'3': 'ItemNotFound',
'4': 'InvalidOperation',
'5': 'ItemNotModified',
'6': 'InternalError',
'7': 'CacheReadError',
'8': 'CacheUpdateError',
'9': 'PersonalSiteNotFound',
'10': 'FailedToCreatePersonalSite',
'11': 'NotAuthorizedToCreatePersonalSite',
'12': 'CannotCreatePersonalSite',
'13': 'LimitReached',
'14': 'AttachmentError',
'15': 'PartialData',
'16': 'FeatureDisabled',
'17': 'StorageQuotaExceeded',
'18': 'DatabaseError',
OK: 0,
InvalidRequest: 1,
AccessDenied: 2,
ItemNotFound: 3,
InvalidOperation: 4,
ItemNotModified: 5,
InternalError: 6,
CacheReadError: 7,
CacheUpdateError: 8,
PersonalSiteNotFound: 9,
FailedToCreatePersonalSite: 10,
NotAuthorizedToCreatePersonalSite: 11,
CannotCreatePersonalSite: 12,
LimitReached: 13,
AttachmentError: 14,
PartialData: 15,
FeatureDisabled: 16,
StorageQuotaExceeded: 17,
DatabaseError: 18 },
odataUrlFrom: [Function: odataUrlFrom],
spODataEntity: [Function: spODataEntity],
spODataEntityArray: [Function: spODataEntityArray],
SharePointQueryable: [Function: SharePointQueryable],
SharePointQueryableInstance: [Function: SharePointQueryableInstance],
SharePointQueryableCollection: [Function: SharePointQueryableCollection],
SharePointQueryableSecurable: [Function: SharePointQueryableSecurable],
FileFolderShared: [Function: FileFolderShared],
SharePointQueryableShareable: [Function: SharePointQueryableShareable],
SharePointQueryableShareableFile: [Function: SharePointQueryableShareableFile],
SharePointQueryableShareableFolder: [Function: SharePointQueryableShareableFolder],
SharePointQueryableShareableItem: [Function: SharePointQueryableShareableItem],
SharePointQueryableShareableWeb: [Function: SharePointQueryableShareableWeb],
AppCatalog: [Function: AppCatalog],
App: [Function: App],
SPBatch: { [Function: SPBatch] ParseResponse: [Function] },
ContentType: [Function: ContentType],
ContentTypes: [Function: class_1],
FieldLink: [Function: FieldLink],
FieldLinks: [Function: class_1],
Field: [Function: Field],
Fields: [Function: class_1],
File: [Function: File],
Files: [Function: class_1],
Folder: [Function: Folder],
Folders: [Function: class_1],
SPHttpClient: [Function: SPHttpClient],
Item: [Function: Item],
Items: [Function: class_1],
ItemVersion: [Function: ItemVersion],
ItemVersions: [Function: class_1],
PagedItemCollection: [Function: PagedItemCollection],
NavigationNodes: [Function: NavigationNodes],
NavigationNode: [Function: NavigationNode],
NavigationService: [Function: NavigationService],
List: [Function: List],
Lists: [Function: class_1],
RegionalSettings: [Function: class_1],
InstalledLanguages: [Function: class_1],
TimeZone: [Function: class_1],
TimeZones: [Function: class_1],
sp: SPRest { _options: {}, _baseUrl: '' },
SPRest: [Function: SPRest],
RoleDefinitionBindings: [Function: class_1],
Search: [Function: class_1],
SearchQueryBuilder: [Function: SearchQueryBuilder],
SearchResults: [Function: SearchResults],
SearchBuiltInSourceId:
{ [Function: SearchBuiltInSourceId]
Documents: 'e7ec8cee-ded8-43c9-beb5-436b54b31e84',
ItemsMatchingContentType: '5dc9f503-801e-4ced-8a2c-5d1237132419',
ItemsMatchingTag: 'e1327b9c-2b8c-4b23-99c9-3730cb29c3f7',
ItemsRelatedToCurrentUser: '48fec42e-4a92-48ce-8363-c2703a40e67d',
ItemsWithSameKeywordAsThisItem: '5c069288-1d17-454a-8ac6-9c642a065f48',
LocalPeopleResults: 'b09a7990-05ea-4af9-81ef-edfab16c4e31',
LocalReportsAndDataResults: '203fba36-2763-4060-9931-911ac8c0583b',
LocalSharePointResults: '8413cd39-2156-4e00-b54d-11efd9abdb89',
LocalVideoResults: '78b793ce-7956-4669-aa3b-451fc5defebf',
Pages: '5e34578e-4d08-4edc-8bf3-002acf3cdbcc',
Pictures: '38403c8c-3975-41a8-826e-717f2d41568a',
Popular: '97c71db1-58ce-4891-8b64-585bc2326c12',
RecentlyChangedItems: 'ba63bbae-fa9c-42c0-b027-9a878f16557c',
RecommendedItems: 'ec675252-14fa-4fbe-84dd-8d098ed74181',
Wiki: '9479bf85-e257-4318-b5a8-81a180f5faa1' },
SearchSuggest: [Function: class_1],
Site: [Function: class_1],
UserProfileQuery: [Function: UserProfileQuery],
toAbsoluteUrl: [Function: toAbsoluteUrl],
extractWebUrl: [Function: extractWebUrl],
UtilityMethod:
{ [Function: UtilityMethod]
getBaseUrl: [Function],
InvalidFileFolderNameCharsOnlineRegex: /["*:<>?\/\\|\x00-\x1f\x7f-\x9f]/g,
InvalidFileFolderNameCharsOnPremiseRegex: /["#%*:<>?\/\\|\x00-\x1f\x7f-\x9f]/g },
View: [Function: View],
Views: [Function: class_1],
ViewFields: [Function: class_1],
WebPartDefinitions: [Function: WebPartDefinitions],
WebPartDefinition: [Function: WebPartDefinition],
WebPart: [Function: class_1],
Web: [Function: class_1],
SiteScripts: { [Function: SiteScripts] getBaseUrl: [Function] },
SiteDesigns: { [Function: SiteDesigns] getBaseUrl: [Function] },
HubSite: [Function: HubSite],
HubSites: [Function: class_1],
ClientSidePage:
{ [Function: ClientSidePage]
create: [Function],
fromFile: [Function],
getDefaultLayoutPart: [Function],
initFrom: [Function] },
CanvasSection: [Function: CanvasSection],
CanvasColumn:
{ [Function: CanvasColumn]
Default:
{ controlType: 0,
displayMode: 2,
emphasis: {},
position: [Object] } },
ColumnControl: [Function: ColumnControl],
ClientSideText:
{ [Function: ClientSideText]
Default:
{ addedFromPersistedData: false,
anchorComponentId: '',
controlType: 4,
displayMode: 2,
editorType: 'CKEditor',
emphasis: {},
id: '',
innerHTML: '',
position: [Object] } },
ClientSideWebpart:
{ [Function: ClientSideWebpart]
fromComponentDef: [Function],
Default:
{ addedFromPersistedData: false,
controlType: 3,
displayMode: 2,
emphasis: {},
id: null,
position: [Object],
reservedHeight: 500,
reservedWidth: 500,
webPartData: null,
webPartId: null } },
Comments: [Function: class_1],
Comment: [Function: Comment],
Replies: [Function: class_1],
SocialQuery: [Function: class_1],
MySocialQuery: [Function: class_1] }
@luismanez, looks as some dependencies are missed. Can you try it locally, will it be the same result? What if to add @pnp/pnpjs (bundle package)?
It looks as well like you are getting sp as the entire exports of the library - which makes sense if you are using the require syntax. Can you try this:
var pnp = require("@pnp/sp");
pnp.sp.setup(...)
If that works you will just need to prepend the "pnp." part to your code before the sp. Alternatively you can try:
var sp = require("@pnp/sp").sp;
@patrick-rodgers brilliant! Thank you for seeing this and for the help! It worked :)
Solved the issue using the requires:
var sp = require('@pnp/sp').sp;
var SPFetchClient = require('@pnp/nodejs').SPFetchClient;
Great! Glad you're able to proceed. If you want to write up a small doc entry for v2 around how to use it within AWS lambda that would be helpful for folks for sure. Thanks for checking out the library!