msgraphsdkgo

package module
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: MIT Imports: 78 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/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"
    "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)
}

2.3 Get a Graph Service Client and Adapter object

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

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

client , err  := msgraphsdk.NewGraphServiceClientWithCredentials(cred, []string{"Files.Read"})
if err != nil {
    fmt.Printf("Error creating client: %v\n", err)
    return
}

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:

import (
    "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors"
)

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

// omitted for brevity

func printOdataError(err error) {
	switch err.(type) {
	case *odataerrors.ODataError:
		typed := err.(*odataerrors.ODataError)
		fmt.Printf("error:", typed.Error())
		if terr := typed.GetError(); terr != nil {
			fmt.Printf("code: %s", *terr.GetCode())
			fmt.Printf("msg: %s", *terr.GetMessage())
		}
	default:
		fmt.Printf("%T > error: %#v", err, err)
	}
}

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"
    "github.com/microsoftgraph/msgraph-sdk-go/models/odataerrors"
)

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

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

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

// omitted for brevity

func printOdataError(err error) {
        switch err.(type) {
        case *odataerrors.ODataError:
                typed := err.(*odataerrors.ODataError)
                fmt.Printf("error:", typed.Error())
                if terr := typed.GetError(); terr != nil {
                        fmt.Printf("code: %s", *terr.GetCode())
                        fmt.Printf("msg: %s", *terr.GetMessage())
                }
        default:
                fmt.Printf("%T > error: %#v", err, err)
        }
}

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 GraphBaseServiceClient added in v0.41.0

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

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

func NewGraphBaseServiceClient added in v0.41.1

NewGraphBaseServiceClient instantiates a new GraphBaseServiceClient and sets the default values.

func (*GraphBaseServiceClient) Admin added in v0.41.0

Admin provides operations to manage the admin singleton.

func (*GraphBaseServiceClient) AgreementAcceptances added in v0.41.0

AgreementAcceptances provides operations to manage the collection of agreementAcceptance entities.

func (*GraphBaseServiceClient) AgreementAcceptancesById added in v0.41.0

AgreementAcceptancesById provides operations to manage the collection of agreementAcceptance entities.

func (*GraphBaseServiceClient) Agreements added in v0.41.0

Agreements provides operations to manage the collection of agreement entities.

func (*GraphBaseServiceClient) AgreementsById added in v0.41.0

AgreementsById provides operations to manage the collection of agreement entities.

func (*GraphBaseServiceClient) AppCatalogs added in v0.41.0

AppCatalogs provides operations to manage the appCatalogs singleton.

func (*GraphBaseServiceClient) ApplicationTemplates added in v0.41.0

ApplicationTemplates provides operations to manage the collection of applicationTemplate entities.

func (*GraphBaseServiceClient) ApplicationTemplatesById added in v0.41.0

ApplicationTemplatesById provides operations to manage the collection of applicationTemplate entities.

func (*GraphBaseServiceClient) Applications added in v0.41.0

Applications provides operations to manage the collection of application entities.

func (*GraphBaseServiceClient) ApplicationsById added in v0.41.0

ApplicationsById provides operations to manage the collection of application entities.

func (*GraphBaseServiceClient) AuditLogs added in v0.41.0

AuditLogs provides operations to manage the auditLogRoot singleton.

func (*GraphBaseServiceClient) AuthenticationMethodConfigurations added in v0.41.0

AuthenticationMethodConfigurations provides operations to manage the collection of authenticationMethodConfiguration entities.

func (*GraphBaseServiceClient) AuthenticationMethodConfigurationsById added in v0.41.0

AuthenticationMethodConfigurationsById provides operations to manage the collection of authenticationMethodConfiguration entities.

func (*GraphBaseServiceClient) AuthenticationMethodsPolicy added in v0.41.0

AuthenticationMethodsPolicy provides operations to manage the authenticationMethodsPolicy singleton.

func (*GraphBaseServiceClient) Branding added in v0.41.0

Branding provides operations to manage the organizationalBranding singleton.

func (*GraphBaseServiceClient) CertificateBasedAuthConfiguration added in v0.41.0

CertificateBasedAuthConfiguration provides operations to manage the collection of certificateBasedAuthConfiguration entities.

func (*GraphBaseServiceClient) CertificateBasedAuthConfigurationById added in v0.41.0

CertificateBasedAuthConfigurationById provides operations to manage the collection of certificateBasedAuthConfiguration entities.

func (*GraphBaseServiceClient) Chats added in v0.41.0

Chats provides operations to manage the collection of chat entities.

func (*GraphBaseServiceClient) ChatsById added in v0.41.0

ChatsById provides operations to manage the collection of chat entities.

func (*GraphBaseServiceClient) Communications added in v0.41.0

Communications provides operations to manage the cloudCommunications singleton.

func (*GraphBaseServiceClient) Compliance added in v0.41.0

Compliance provides operations to manage the compliance singleton.

func (*GraphBaseServiceClient) Connections added in v0.41.0

Connections provides operations to manage the collection of externalConnection entities.

func (*GraphBaseServiceClient) ConnectionsById added in v0.41.0

ConnectionsById provides operations to manage the collection of externalConnection entities.

func (*GraphBaseServiceClient) Contacts added in v0.41.0

Contacts provides operations to manage the collection of orgContact entities.

func (*GraphBaseServiceClient) ContactsById added in v0.41.0

ContactsById provides operations to manage the collection of orgContact entities.

func (*GraphBaseServiceClient) Contracts added in v0.41.0

Contracts provides operations to manage the collection of contract entities.

func (*GraphBaseServiceClient) ContractsById added in v0.41.0

ContractsById provides operations to manage the collection of contract entities.

func (*GraphBaseServiceClient) DataPolicyOperations added in v0.41.0

DataPolicyOperations provides operations to manage the collection of dataPolicyOperation entities.

func (*GraphBaseServiceClient) DataPolicyOperationsById added in v0.41.0

DataPolicyOperationsById provides operations to manage the collection of dataPolicyOperation entities.

func (*GraphBaseServiceClient) DeviceAppManagement added in v0.41.0

DeviceAppManagement provides operations to manage the deviceAppManagement singleton.

func (*GraphBaseServiceClient) DeviceManagement added in v0.41.0

DeviceManagement provides operations to manage the deviceManagement singleton.

func (*GraphBaseServiceClient) Devices added in v0.41.0

Devices provides operations to manage the collection of device entities.

func (*GraphBaseServiceClient) DevicesById added in v0.41.0

DevicesById provides operations to manage the collection of device entities.

func (*GraphBaseServiceClient) Directory added in v0.41.0

Directory provides operations to manage the directory singleton.

func (*GraphBaseServiceClient) DirectoryObjects added in v0.41.0

DirectoryObjects provides operations to manage the collection of directoryObject entities.

func (*GraphBaseServiceClient) DirectoryObjectsById added in v0.41.0

DirectoryObjectsById provides operations to manage the collection of directoryObject entities.

func (*GraphBaseServiceClient) DirectoryRoleTemplates added in v0.41.0

DirectoryRoleTemplates provides operations to manage the collection of directoryRoleTemplate entities.

func (*GraphBaseServiceClient) DirectoryRoleTemplatesById added in v0.41.0

DirectoryRoleTemplatesById provides operations to manage the collection of directoryRoleTemplate entities.

func (*GraphBaseServiceClient) DirectoryRoles added in v0.41.0

DirectoryRoles provides operations to manage the collection of directoryRole entities.

func (*GraphBaseServiceClient) DirectoryRolesById added in v0.41.0

DirectoryRolesById provides operations to manage the collection of directoryRole entities.

func (*GraphBaseServiceClient) DomainDnsRecords added in v0.41.0

DomainDnsRecords provides operations to manage the collection of domainDnsRecord entities.

func (*GraphBaseServiceClient) DomainDnsRecordsById added in v0.41.0

DomainDnsRecordsById provides operations to manage the collection of domainDnsRecord entities.

func (*GraphBaseServiceClient) Domains added in v0.41.0

Domains provides operations to manage the collection of domain entities.

func (*GraphBaseServiceClient) DomainsById added in v0.41.0

DomainsById provides operations to manage the collection of domain entities.

func (*GraphBaseServiceClient) Drives added in v0.41.0

Drives provides operations to manage the collection of drive entities.

func (*GraphBaseServiceClient) DrivesById added in v0.41.0

DrivesById provides operations to manage the collection of drive entities.

func (*GraphBaseServiceClient) Education added in v0.41.0

Education provides operations to manage the educationRoot singleton.

func (*GraphBaseServiceClient) External added in v0.41.0

External provides operations to manage the external singleton.

func (*GraphBaseServiceClient) GetAdapter added in v0.41.1

GetAdapter returns the client current adapter, Method should only be called when the user is certain an adapter has been provided

func (*GraphBaseServiceClient) GroupLifecyclePolicies added in v0.41.0

GroupLifecyclePolicies provides operations to manage the collection of groupLifecyclePolicy entities.

func (*GraphBaseServiceClient) GroupLifecyclePoliciesById added in v0.41.0

GroupLifecyclePoliciesById provides operations to manage the collection of groupLifecyclePolicy entities.

func (*GraphBaseServiceClient) GroupSettingTemplates added in v0.41.0

GroupSettingTemplates provides operations to manage the collection of groupSettingTemplate entities.

func (*GraphBaseServiceClient) GroupSettingTemplatesById added in v0.41.0

GroupSettingTemplatesById provides operations to manage the collection of groupSettingTemplate entities.

func (*GraphBaseServiceClient) GroupSettings added in v0.41.0

GroupSettings provides operations to manage the collection of groupSetting entities.

func (*GraphBaseServiceClient) GroupSettingsById added in v0.41.0

GroupSettingsById provides operations to manage the collection of groupSetting entities.

func (*GraphBaseServiceClient) Groups added in v0.41.0

Groups provides operations to manage the collection of group entities.

func (*GraphBaseServiceClient) GroupsById added in v0.41.0

GroupsById provides operations to manage the collection of group entities.

func (*GraphBaseServiceClient) Identity added in v0.41.0

Identity provides operations to manage the identityContainer singleton.

func (*GraphBaseServiceClient) IdentityGovernance added in v0.41.0

IdentityGovernance provides operations to manage the identityGovernance singleton.

func (*GraphBaseServiceClient) IdentityProtection added in v0.41.0

IdentityProtection provides operations to manage the identityProtectionRoot singleton.

func (*GraphBaseServiceClient) IdentityProviders added in v0.41.0

IdentityProviders provides operations to manage the collection of identityProvider entities.

func (*GraphBaseServiceClient) IdentityProvidersById added in v0.41.0

IdentityProvidersById provides operations to manage the collection of identityProvider entities.

func (*GraphBaseServiceClient) InformationProtection added in v0.41.0

InformationProtection provides operations to manage the informationProtection singleton.

func (*GraphBaseServiceClient) Invitations added in v0.41.0

Invitations provides operations to manage the collection of invitation entities.

func (*GraphBaseServiceClient) InvitationsById added in v0.41.0

InvitationsById provides operations to manage the collection of invitation entities.

func (*GraphBaseServiceClient) Localizations added in v0.41.0

Localizations provides operations to manage the collection of organizationalBrandingLocalization entities.

func (*GraphBaseServiceClient) LocalizationsById added in v0.41.0

LocalizationsById provides operations to manage the collection of organizationalBrandingLocalization entities.

func (*GraphBaseServiceClient) Me added in v0.41.0

Me provides operations to manage the user singleton.

func (*GraphBaseServiceClient) Oauth2PermissionGrants added in v0.41.0

Oauth2PermissionGrants provides operations to manage the collection of oAuth2PermissionGrant entities.

func (*GraphBaseServiceClient) Oauth2PermissionGrantsById added in v0.41.0

Oauth2PermissionGrantsById provides operations to manage the collection of oAuth2PermissionGrant entities.

func (*GraphBaseServiceClient) Organization added in v0.41.0

Organization provides operations to manage the collection of organization entities.

func (*GraphBaseServiceClient) OrganizationById added in v0.41.0

OrganizationById provides operations to manage the collection of organization entities.

func (*GraphBaseServiceClient) PermissionGrants added in v0.41.0

PermissionGrants provides operations to manage the collection of resourceSpecificPermissionGrant entities.

func (*GraphBaseServiceClient) PermissionGrantsById added in v0.41.0

PermissionGrantsById provides operations to manage the collection of resourceSpecificPermissionGrant entities.

func (*GraphBaseServiceClient) Places added in v0.41.0

Places provides operations to manage the collection of place entities.

func (*GraphBaseServiceClient) PlacesById added in v0.41.0

PlacesById provides operations to manage the collection of place entities.

func (*GraphBaseServiceClient) Planner added in v0.41.0

Planner provides operations to manage the planner singleton.

func (*GraphBaseServiceClient) Policies added in v0.41.0

Policies provides operations to manage the policyRoot singleton.

func (*GraphBaseServiceClient) Print added in v0.41.0

Print provides operations to manage the print singleton.

func (*GraphBaseServiceClient) Privacy added in v0.41.0

Privacy provides operations to manage the privacy singleton.

func (*GraphBaseServiceClient) Reports added in v0.41.0

Reports provides operations to manage the reportRoot singleton.

func (*GraphBaseServiceClient) RoleManagement added in v0.41.0

RoleManagement provides operations to manage the roleManagement singleton.

func (*GraphBaseServiceClient) SchemaExtensions added in v0.41.0

SchemaExtensions provides operations to manage the collection of schemaExtension entities.

func (*GraphBaseServiceClient) SchemaExtensionsById added in v0.41.0

SchemaExtensionsById provides operations to manage the collection of schemaExtension entities.

func (*GraphBaseServiceClient) ScopedRoleMemberships added in v0.41.0

ScopedRoleMemberships provides operations to manage the collection of scopedRoleMembership entities.

func (*GraphBaseServiceClient) ScopedRoleMembershipsById added in v0.41.0

ScopedRoleMembershipsById provides operations to manage the collection of scopedRoleMembership entities.

func (*GraphBaseServiceClient) Search added in v0.41.0

Search provides operations to manage the searchEntity singleton.

func (*GraphBaseServiceClient) Security added in v0.41.0

Security provides operations to manage the security singleton.

func (*GraphBaseServiceClient) ServicePrincipals added in v0.41.0

ServicePrincipals provides operations to manage the collection of servicePrincipal entities.

func (*GraphBaseServiceClient) ServicePrincipalsById added in v0.41.0

ServicePrincipalsById provides operations to manage the collection of servicePrincipal entities.

func (*GraphBaseServiceClient) Shares added in v0.41.0

Shares provides operations to manage the collection of sharedDriveItem entities.

func (*GraphBaseServiceClient) SharesById added in v0.41.0

SharesById provides operations to manage the collection of sharedDriveItem entities.

func (*GraphBaseServiceClient) Sites added in v0.41.0

Sites provides operations to manage the collection of site entities.

func (*GraphBaseServiceClient) SitesById added in v0.41.0

SitesById provides operations to manage the collection of site entities.

func (*GraphBaseServiceClient) Solutions added in v0.41.0

Solutions provides operations to manage the solutionsRoot singleton.

func (*GraphBaseServiceClient) SubscribedSkus added in v0.41.0

SubscribedSkus provides operations to manage the collection of subscribedSku entities.

func (*GraphBaseServiceClient) SubscribedSkusById added in v0.41.0

SubscribedSkusById provides operations to manage the collection of subscribedSku entities.

func (*GraphBaseServiceClient) Subscriptions added in v0.41.0

Subscriptions provides operations to manage the collection of subscription entities.

func (*GraphBaseServiceClient) SubscriptionsById added in v0.41.0

SubscriptionsById provides operations to manage the collection of subscription entities.

func (*GraphBaseServiceClient) Teams added in v0.41.0

Teams provides operations to manage the collection of team entities.

func (*GraphBaseServiceClient) TeamsById added in v0.41.0

TeamsById provides operations to manage the collection of team entities.

func (*GraphBaseServiceClient) TeamsTemplates added in v0.41.0

TeamsTemplates provides operations to manage the collection of teamsTemplate entities.

func (*GraphBaseServiceClient) TeamsTemplatesById added in v0.41.0

TeamsTemplatesById provides operations to manage the collection of teamsTemplate entities.

func (*GraphBaseServiceClient) Teamwork added in v0.41.0

Teamwork provides operations to manage the teamwork singleton.

func (*GraphBaseServiceClient) TenantRelationships added in v0.54.0

TenantRelationships provides operations to manage the tenantRelationship singleton.

func (*GraphBaseServiceClient) Users added in v0.41.0

Users provides operations to manage the collection of user entities.

func (*GraphBaseServiceClient) UsersById added in v0.41.0

UsersById provides operations to manage the collection of user entities.

type GraphRequestAdapter

type GraphRequestAdapter struct {
	core.GraphRequestAdapterBase
}

GraphRequestAdapter is the core service used by GraphBaseServiceClient 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 {
	GraphBaseServiceClient
}

func NewGraphServiceClient

func NewGraphServiceClient(adapter abstractions.RequestAdapter) *GraphServiceClient

func NewGraphServiceClientWithCredentials added in v0.41.1

func NewGraphServiceClientWithCredentials(credential azcore.TokenCredential, scopes []string) (*GraphServiceClient, error)

NewGraphServiceClientWithCredentials instantiates a new GraphServiceClient with provided credentials and scopes

func NewGraphServiceClientWithCredentialsAndHosts added in v0.41.1

func NewGraphServiceClientWithCredentialsAndHosts(credential azcore.TokenCredential, scopes []string, validhosts []string) (*GraphServiceClient, error)

NewGraphServiceClientWithCredentialsAndHosts instantiates a new GraphServiceClient with provided credentials , scopes and validhosts

Jump to

Keyboard shortcuts

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