Categorygithub.com/microsoftgraph/msgraph-sdk-go-core
modulepackage
1.2.1
Repository: https://github.com/microsoftgraph/msgraph-sdk-go-core.git
Documentation: pkg.go.dev

# README

Microsoft Graph Core SDK for Go

PkgGoDev Coverage Sonarcloud Status

Get started with the Microsoft Graph Core SDK for Go by integrating the Microsoft Graph API into your Go application! You can also have a look at the Go documentation

Note: Although you can use this library directly, we recommend you use the v1 or beta library which rely on this library and additionally provide a fluent style Go API and models.

Note: The Microsoft Graph Go SDK is currently in Release Candidate (RC) version starting from version 0.34.1. The SDK is still undergoing testing but minimum breaking changes should be expected. Checkout the known limitations.

Samples and usage guide

1. Installation

go get github.com/microsoftgraph/msgraph-sdk-go-core
go get github.com/Azure/azure-sdk-for-go/sdk/azidentity

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 GraphRequestAdapterBase 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/microsoftgraph/msgraph-sdk-go-core/authentication"
    "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{"Mail.Read", "Mail.Send"})
if err != nil {
    fmt.Printf("Error authentication provider: %v\n", err)
    return
}

2.3 Get a Request Adapter object

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

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

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

3. Make requests against the service

After you have a GraphRequestAdapterBase 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 details

To retrieve the user's details

import abs "github.com/microsoft/kiota-abstractions-go"

requestInf := abs.NewRequestInformation()
targetUrl, err := url.Parse("https://graph.microsoft.com/v1.0/me")
if err != nil {
    fmt.Printf("Error parsing URL: %v\n", err)
}
requestInf.SetUri(*targetUrl)

// User is your own type that implements Parsable or comes from the service library
user, err := adapter.SendAsync(*requestInf, func() { return &User }, nil)

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

4. Issues

For known issues, see issues.

5. Contributions

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

6. License

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

7. Third-party notices

Third-party notices

# Packages

No description provided by the author
No description provided by the author

# Functions

CreateBatchRequestItemDiscriminator creates a new instance of the appropriate class based on discriminator value.
CreateBatchResponseDiscriminator creates a new instance of the appropriate class based on discriminator value.
No description provided by the author
GetBatchResponseById returns the response of the batch request item with the given id.
GetDefaultClient creates a new http client with a preconfigured middleware pipeline.
GetDefaultMiddlewaresWithOptions creates a default slice of middleware for the Graph Client.
No description provided by the author
NewBatchItem creates an instance of BatchItem.
NewBatchRequest creates an instance of BatchRequest.
NewBatchRequestCollection creates an instance of a BatchRequestCollection with a default request limit.
NewBatchRequestCollectionWithLimit creates an instance of a BatchRequestCollection with a defined limit in requests.
No description provided by the author
NewGraphRequestAdapterBase creates a new GraphRequestAdapterBase with the given parameters.
NewGraphRequestAdapterBaseWithParseNodeFactory creates a new GraphRequestAdapterBase with the given parameters.
NewGraphRequestAdapterBaseWithParseNodeFactoryAndSerializationWriterFactory creates a new GraphRequestAdapterBase with the given parameters.
NewGraphRequestAdapterBaseWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient creates a new GraphRequestAdapterBase with the given parameters.
NewGraphTelemetryHandler creates a new GraphTelemetryHandler.
NewPageIterator creates an iterator instance It has three parameters.
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Variables

* The SDK version */ x-release-please-start-version.
No description provided by the author

# Structs

No description provided by the author
GraphClientOptions represents a combination of GraphServiceVersion and GraphServiceLibraryVersion GraphServiceVersion is version of the targeted service.
GraphRequestAdapterBase is the core service used by GraphServiceClient to make requests to Microsoft Graph.
GraphTelemetryHandler is a middleware handler that adds telemetry headers to requests.
PageIterator represents an iterator object that can be used to get subsequent pages of a collection.
PageResult represents a page object built from a graph response object.

# Interfaces

BatchItem is an instance of the BatchRequest payload to be later serialized to a json payload.
BatchRequest models all the properties of a batch request.
BatchResponse instance of batch request result payload.
PageWithOdataDeltaLink represents a contract with the GetOdataDeltaLink() method.
PageWithOdataNextLink represents a contract with the GetOdataNextLink() method.

# Type aliases

RequestBody is a type alias for http request bodies.
RequestHeader is a type alias for http request headers.