msgraphsdkgo

package module
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 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/go/azure

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/go/azure"
    "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/microsoft/graph"
)

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, graph.CreateUserCollectionResponseFromDiscriminatorValue)

err = pageIterator.Iterate(func(pageItem interface{}) bool {
    user := pageItem.(graph.User)
    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) AgreementAcceptancesById ¶

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

func (*GraphServiceClient) AgreementsById ¶

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

func (*GraphServiceClient) ApplicationTemplatesById ¶

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

func (*GraphServiceClient) ApplicationsById ¶

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

func (*GraphServiceClient) AuthenticationMethodConfigurationsById ¶

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

func (*GraphServiceClient) CertificateBasedAuthConfigurationById ¶

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

func (*GraphServiceClient) ChatsById ¶

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

func (*GraphServiceClient) ConnectionsById ¶

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

func (*GraphServiceClient) ContactsById ¶

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

func (*GraphServiceClient) ContractsById ¶

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

func (*GraphServiceClient) DataPolicyOperationsById ¶

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

func (*GraphServiceClient) DevicesById ¶

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

func (*GraphServiceClient) DirectoryObjectsById ¶

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

func (*GraphServiceClient) DirectoryRoleTemplatesById ¶

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

func (*GraphServiceClient) DirectoryRolesById ¶

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

func (*GraphServiceClient) DomainDnsRecordsById ¶

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

func (*GraphServiceClient) DomainsById ¶

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

func (*GraphServiceClient) DrivesById ¶

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

func (*GraphServiceClient) Get ¶

func (*GraphServiceClient) GroupLifecyclePoliciesById ¶

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

func (*GraphServiceClient) GroupSettingTemplatesById ¶

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

func (*GraphServiceClient) GroupSettingsById ¶

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

func (*GraphServiceClient) GroupsById ¶

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

func (*GraphServiceClient) IdentityProvidersById ¶

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

func (*GraphServiceClient) InvitationsById ¶

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

func (*GraphServiceClient) LocalizationsById ¶

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

func (*GraphServiceClient) Oauth2PermissionGrantsById ¶

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

func (*GraphServiceClient) OrganizationById ¶

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

func (*GraphServiceClient) PermissionGrantsById ¶

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

func (*GraphServiceClient) PlacesById ¶

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

func (*GraphServiceClient) SchemaExtensionsById ¶

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

func (*GraphServiceClient) ScopedRoleMembershipsById ¶

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

func (*GraphServiceClient) ServicePrincipalsById ¶

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

func (*GraphServiceClient) SharesById ¶

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

func (*GraphServiceClient) SitesById ¶

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

func (*GraphServiceClient) SubscribedSkusById ¶

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

func (*GraphServiceClient) SubscriptionsById ¶

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

func (*GraphServiceClient) TeamsById ¶

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

func (*GraphServiceClient) TeamsTemplatesById ¶

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

func (*GraphServiceClient) UsersById ¶

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

func (*GraphServiceClient) WorkbooksById ¶

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

type GraphServiceClientGetOptions ¶

type GraphServiceClientGetOptions struct {
	// Request headers
	H map[string]string
	// Request options
	O []ida96af0f171bb75f894a4013a6b3146a4397c58f11adb81a2b7cbea9314783a9.RequestOption
	// Response handler to use in place of the default response handling provided by the core service
	ResponseHandler ida96af0f171bb75f894a4013a6b3146a4397c58f11adb81a2b7cbea9314783a9.ResponseHandler
}

GraphServiceClientGetOptions options for Get

Directories ¶

Path Synopsis
me
me
models
add

Jump to

Keyboard shortcuts

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