msgraphsdkgo

package module
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2022 License: MIT Imports: 115 Imported by: 110

README ¶

Microsoft Graph SDK for Go

PkgGoDev

Get started with the Microsoft Graph SDK for Go by integrating the Microsoft Graph API into your Go application!

Note: this SDK allows you to build applications using the v1.0 of Microsoft Graph. If you want to try the latest Microsoft Graph APIs under beta, use our beta SDK instead.

Note: the Microsoft Graph Go SDK is currently in Community Preview. During this period we're expecting breaking changes to happen to the SDK based on community's feedback. Checkout the known limitations.

1. Installation

go get github.com/microsoftgraph/msgraph-sdk-go
go get github.com/Azure/azure-sdk-for-go/sdk/azidentity
go get github.com/microsoft/kiota-authentication-azure-go

2. Getting started

2.1 Register your application

Register your application by following the steps at Register your app with the Microsoft Identity Platform.

2.2 Create an AuthenticationProvider object

An instance of the GraphRequestAdapter class handles building client. To create a new instance of this class, you need to provide an instance of AuthenticationProvider, which can authenticate requests to Microsoft Graph.

For an example of how to get an authentication provider, see choose a Microsoft Graph authentication provider.

Note: we are working to add the getting started information for Go to our public documentation, in the meantime the following sample should help you getting started.

import (
    azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
    a          "github.com/microsoft/kiota-authentication-azure-go"
    "context"
)

cred, err := azidentity.NewDeviceCodeCredential(&azidentity.DeviceCodeCredentialOptions{
    TenantID: "<the tenant id from your app registration>",
    ClientID: "<the client id from your app registration>",
    UserPrompt: func(ctx context.Context, message azidentity.DeviceCodeMessage) error {
        fmt.Println(message.Message)
        return nil
    },
})

if err != nil {
    fmt.Printf("Error creating credentials: %v\n", err)
}

auth, err := a.NewAzureIdentityAuthenticationProviderWithScopes(cred, []string{"Files.Read"})
if err != nil {
    fmt.Printf("Error authentication provider: %v\n", err)
    return
}
2.3 Get a Graph Service Client Adapter object

You must get a GraphRequestAdapter object to make requests against the service.

import msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"

adapter, err := msgraphsdk.NewGraphRequestAdapter(auth)
if err != nil {
    fmt.Printf("Error creating adapter: %v\n", err)
    return
}
client := msgraphsdk.NewGraphServiceClient(adapter)

3. Make requests against the service

After you have a GraphServiceClient that is authenticated, you can begin making calls against the service. The requests against the service look like our REST API.

3.1 Get the user's drive

To retrieve the user's drive:

result, err := client.Me().Drive().Get(nil)
if err != nil {
    fmt.Printf("Error getting the drive: %v\n", err)
}
fmt.Printf("Found Drive : %v\n", *result.GetId())

4. Getting results that span across multiple pages

Items in a collection response can span across multiple pages. To get the complete set of items in the collection, your application must make additional calls to get the subsequent pages until no more next link is provided in the response.

4.1 Get all the users in an environment

To retrieve the users:

import (
    msgraphcore "github.com/microsoftgraph/msgraph-sdk-go-core"
    "github.com/microsoftgraph/msgraph-sdk-go/users"
    "github.com/microsoftgraph/msgraph-sdk-go/models"
)

result, err := client.Users().Get(nil)
if err != nil {
    fmt.Printf("Error getting users: %v\n", err)
    return err
}

// Use PageIterator to iterate through all users
pageIterator, err := msgraphcore.NewPageIterator(result, adapter, models.CreateUserCollectionResponseFromDiscriminatorValue)

err = pageIterator.Iterate(func(pageItem interface{}) bool {
    user := pageItem.(models.Userable)
    fmt.Printf("%s\n", *user.GetDisplayName())
    // Return true to continue the iteration
    return true
})

5. Documentation

For more detailed documentation, see:

6. Issues

For known issues, see issues.

7. Contributions

The Microsoft Graph SDK is open for contribution. To contribute to this project, see Contributing.

8. License

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license.

9. Third-party notices

Third-party notices

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func GetDefaultClientOptions ¶ added in v0.2.1

func GetDefaultClientOptions() core.GraphClientOptions

GetDefaultClientOptions returns the default client options used by the GraphRequestAdapterBase and the middleware.

Types ¶

type GraphRequestAdapter ¶

type GraphRequestAdapter struct {
	core.GraphRequestAdapterBase
}

GraphRequestAdapter is the core service used by GraphServiceClient to make requests to Microsoft Graph.

func NewGraphRequestAdapter ¶

func NewGraphRequestAdapter(authenticationProvider absauth.AuthenticationProvider) (*GraphRequestAdapter, error)

NewGraphRequestAdapter creates a new GraphRequestAdapter with the given parameters Parameters: authenticationProvider: the provider used to authenticate requests Returns: a new GraphRequestAdapter

func NewGraphRequestAdapterWithParseNodeFactory ¶

func NewGraphRequestAdapterWithParseNodeFactory(authenticationProvider absauth.AuthenticationProvider, parseNodeFactory absser.ParseNodeFactory) (*GraphRequestAdapter, error)

NewGraphRequestAdapterWithParseNodeFactory creates a new GraphRequestAdapter with the given parameters Parameters: authenticationProvider: the provider used to authenticate requests parseNodeFactory: the factory used to create parse nodes Returns: a new GraphRequestAdapter

func NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactory ¶

func NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactory(authenticationProvider absauth.AuthenticationProvider, parseNodeFactory absser.ParseNodeFactory, serializationWriterFactory absser.SerializationWriterFactory) (*GraphRequestAdapter, error)

NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactory creates a new GraphRequestAdapter with the given parameters Parameters: authenticationProvider: the provider used to authenticate requests parseNodeFactory: the factory used to create parse nodes serializationWriterFactory: the factory used to create serialization writers Returns: a new GraphRequestAdapter

func NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient ¶

func NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(authenticationProvider absauth.AuthenticationProvider, parseNodeFactory absser.ParseNodeFactory, serializationWriterFactory absser.SerializationWriterFactory, httpClient *nethttp.Client) (*GraphRequestAdapter, error)

NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient creates a new GraphRequestAdapter with the given parameters Parameters: authenticationProvider: the provider used to authenticate requests parseNodeFactory: the factory used to create parse nodes serializationWriterFactory: the factory used to create serialization writers httpClient: the client used to send requests Returns: a new GraphRequestAdapter

type GraphServiceClient ¶

type GraphServiceClient struct {
	// contains filtered or unexported fields
}

GraphServiceClient the main entry point of the SDK, exposes the configuration and the fluent API.

func NewGraphServiceClient ¶

NewGraphServiceClient instantiates a new GraphServiceClient and sets the default values.

func (*GraphServiceClient) Admin ¶

Admin the admin property

func (*GraphServiceClient) AgreementAcceptances ¶

AgreementAcceptances the agreementAcceptances property

func (*GraphServiceClient) AgreementAcceptancesById ¶

AgreementAcceptancesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.agreementAcceptances.item collection

func (*GraphServiceClient) Agreements ¶

Agreements the agreements property

func (*GraphServiceClient) AgreementsById ¶

AgreementsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.agreements.item collection

func (*GraphServiceClient) AppCatalogs ¶

AppCatalogs the appCatalogs property

func (*GraphServiceClient) ApplicationTemplates ¶

ApplicationTemplates the applicationTemplates property

func (*GraphServiceClient) ApplicationTemplatesById ¶

ApplicationTemplatesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.applicationTemplates.item collection

func (*GraphServiceClient) Applications ¶

Applications the applications property

func (*GraphServiceClient) ApplicationsById ¶

ApplicationsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.applications.item collection

func (*GraphServiceClient) AuditLogs ¶

AuditLogs the auditLogs property

func (*GraphServiceClient) AuthenticationMethodConfigurations ¶

AuthenticationMethodConfigurations the authenticationMethodConfigurations property

func (*GraphServiceClient) AuthenticationMethodConfigurationsById ¶

AuthenticationMethodConfigurationsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.authenticationMethodConfigurations.item collection

func (*GraphServiceClient) AuthenticationMethodsPolicy ¶

AuthenticationMethodsPolicy the authenticationMethodsPolicy property

func (*GraphServiceClient) Branding ¶

Branding the branding property

func (*GraphServiceClient) CertificateBasedAuthConfiguration ¶

CertificateBasedAuthConfiguration the certificateBasedAuthConfiguration property

func (*GraphServiceClient) CertificateBasedAuthConfigurationById ¶

CertificateBasedAuthConfigurationById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.certificateBasedAuthConfiguration.item collection

func (*GraphServiceClient) Chats ¶

Chats the chats property

func (*GraphServiceClient) ChatsById ¶

ChatsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.chats.item collection

func (*GraphServiceClient) Communications ¶

Communications the communications property

func (*GraphServiceClient) Compliance ¶

Compliance the compliance property

func (*GraphServiceClient) Connections ¶

Connections the connections property

func (*GraphServiceClient) ConnectionsById ¶

ConnectionsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.connections.item collection

func (*GraphServiceClient) Contacts ¶

Contacts the contacts property

func (*GraphServiceClient) ContactsById ¶

ContactsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.contacts.item collection

func (*GraphServiceClient) Contracts ¶

Contracts the contracts property

func (*GraphServiceClient) ContractsById ¶

ContractsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.contracts.item collection

func (*GraphServiceClient) DataPolicyOperations ¶

DataPolicyOperations the dataPolicyOperations property

func (*GraphServiceClient) DataPolicyOperationsById ¶

DataPolicyOperationsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.dataPolicyOperations.item collection

func (*GraphServiceClient) DeviceAppManagement ¶

DeviceAppManagement the deviceAppManagement property

func (*GraphServiceClient) DeviceManagement ¶

DeviceManagement the deviceManagement property

func (*GraphServiceClient) Devices ¶

Devices the devices property

func (*GraphServiceClient) DevicesById ¶

DevicesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.devices.item collection

func (*GraphServiceClient) Directory ¶

Directory the directory property

func (*GraphServiceClient) DirectoryObjects ¶

DirectoryObjects the directoryObjects property

func (*GraphServiceClient) DirectoryObjectsById ¶

DirectoryObjectsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.directoryObjects.item collection

func (*GraphServiceClient) DirectoryRoleTemplates ¶

DirectoryRoleTemplates the directoryRoleTemplates property

func (*GraphServiceClient) DirectoryRoleTemplatesById ¶

DirectoryRoleTemplatesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.directoryRoleTemplates.item collection

func (*GraphServiceClient) DirectoryRoles ¶

DirectoryRoles the directoryRoles property

func (*GraphServiceClient) DirectoryRolesById ¶

DirectoryRolesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.directoryRoles.item collection

func (*GraphServiceClient) DomainDnsRecords ¶

DomainDnsRecords the domainDnsRecords property

func (*GraphServiceClient) DomainDnsRecordsById ¶

DomainDnsRecordsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.domainDnsRecords.item collection

func (*GraphServiceClient) Domains ¶

Domains the domains property

func (*GraphServiceClient) DomainsById ¶

DomainsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.domains.item collection

func (*GraphServiceClient) Drive ¶

Drive the drive property

func (*GraphServiceClient) Drives ¶

Drives the drives property

func (*GraphServiceClient) DrivesById ¶

DrivesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.drives.item collection

func (*GraphServiceClient) Education ¶

Education the education property

func (*GraphServiceClient) External ¶

External the external property

func (*GraphServiceClient) GroupLifecyclePolicies ¶

GroupLifecyclePolicies the groupLifecyclePolicies property

func (*GraphServiceClient) GroupLifecyclePoliciesById ¶

GroupLifecyclePoliciesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.groupLifecyclePolicies.item collection

func (*GraphServiceClient) GroupSettingTemplates ¶

GroupSettingTemplates the groupSettingTemplates property

func (*GraphServiceClient) GroupSettingTemplatesById ¶

GroupSettingTemplatesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.groupSettingTemplates.item collection

func (*GraphServiceClient) GroupSettings ¶

GroupSettings the groupSettings property

func (*GraphServiceClient) GroupSettingsById ¶

GroupSettingsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.groupSettings.item collection

func (*GraphServiceClient) Groups ¶

Groups the groups property

func (*GraphServiceClient) GroupsById ¶

GroupsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.groups.item collection

func (*GraphServiceClient) Identity ¶

Identity the identity property

func (*GraphServiceClient) IdentityGovernance ¶

IdentityGovernance the identityGovernance property

func (*GraphServiceClient) IdentityProtection ¶ added in v0.5.0

IdentityProtection the identityProtection property

func (*GraphServiceClient) IdentityProviders ¶

IdentityProviders the identityProviders property

func (*GraphServiceClient) IdentityProvidersById ¶

IdentityProvidersById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.identityProviders.item collection

func (*GraphServiceClient) InformationProtection ¶

InformationProtection the informationProtection property

func (*GraphServiceClient) Invitations ¶

Invitations the invitations property

func (*GraphServiceClient) InvitationsById ¶

InvitationsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.invitations.item collection

func (*GraphServiceClient) Localizations ¶

Localizations the localizations property

func (*GraphServiceClient) LocalizationsById ¶

LocalizationsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.localizations.item collection

func (*GraphServiceClient) Oauth2PermissionGrants ¶

Oauth2PermissionGrants the oauth2PermissionGrants property

func (*GraphServiceClient) Oauth2PermissionGrantsById ¶

Oauth2PermissionGrantsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.oauth2PermissionGrants.item collection

func (*GraphServiceClient) Organization ¶

Organization the organization property

func (*GraphServiceClient) OrganizationById ¶

OrganizationById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.organization.item collection

func (*GraphServiceClient) PermissionGrants ¶

PermissionGrants the permissionGrants property

func (*GraphServiceClient) PermissionGrantsById ¶

PermissionGrantsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.permissionGrants.item collection

func (*GraphServiceClient) Places ¶

Places the places property

func (*GraphServiceClient) PlacesById ¶

PlacesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.places.item collection

func (*GraphServiceClient) Planner ¶

Planner the planner property

func (*GraphServiceClient) Policies ¶

Policies the policies property

func (*GraphServiceClient) Print ¶

Print the print property

func (*GraphServiceClient) Privacy ¶ added in v0.1.0

Privacy the privacy property

func (*GraphServiceClient) Reports ¶

Reports the reports property

func (*GraphServiceClient) RoleManagement ¶

RoleManagement the roleManagement property

func (*GraphServiceClient) SchemaExtensions ¶

SchemaExtensions the schemaExtensions property

func (*GraphServiceClient) SchemaExtensionsById ¶

SchemaExtensionsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.schemaExtensions.item collection

func (*GraphServiceClient) ScopedRoleMemberships ¶

ScopedRoleMemberships the scopedRoleMemberships property

func (*GraphServiceClient) ScopedRoleMembershipsById ¶

ScopedRoleMembershipsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.scopedRoleMemberships.item collection

func (*GraphServiceClient) Search ¶

Search the search property

func (*GraphServiceClient) Security ¶

Security the security property

func (*GraphServiceClient) ServicePrincipals ¶

ServicePrincipals the servicePrincipals property

func (*GraphServiceClient) ServicePrincipalsById ¶

ServicePrincipalsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.servicePrincipals.item collection

func (*GraphServiceClient) Shares ¶

Shares the shares property

func (*GraphServiceClient) SharesById ¶

SharesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.shares.item collection

func (*GraphServiceClient) Sites ¶

Sites the sites property

func (*GraphServiceClient) SitesById ¶

SitesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.sites.item collection

func (*GraphServiceClient) Solutions ¶ added in v0.4.0

Solutions the solutions property

func (*GraphServiceClient) SubscribedSkus ¶

SubscribedSkus the subscribedSkus property

func (*GraphServiceClient) SubscribedSkusById ¶

SubscribedSkusById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.subscribedSkus.item collection

func (*GraphServiceClient) Subscriptions ¶

Subscriptions the subscriptions property

func (*GraphServiceClient) SubscriptionsById ¶

SubscriptionsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.subscriptions.item collection

func (*GraphServiceClient) Teams ¶

Teams the teams property

func (*GraphServiceClient) TeamsById ¶

TeamsById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.teams.item collection

func (*GraphServiceClient) TeamsTemplates ¶

TeamsTemplates the teamsTemplates property

func (*GraphServiceClient) TeamsTemplatesById ¶

TeamsTemplatesById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.teamsTemplates.item collection

func (*GraphServiceClient) Teamwork ¶

Teamwork the teamwork property

func (*GraphServiceClient) Users ¶

Users the users property

func (*GraphServiceClient) UsersById ¶

UsersById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.users.item collection

func (*GraphServiceClient) Workbooks ¶

Workbooks the workbooks property

func (*GraphServiceClient) WorkbooksById ¶

WorkbooksById gets an item from the github.com/microsoftgraph/msgraph-sdk-go/.workbooks.item collection

Directories ¶

Path Synopsis
me
me
add

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL