Git Product home page Git Product logo

msgraph.go's Introduction

msgraph.go

v1.0 beta
pkg.go.dev pkg.go.dev

(The online references at pkg.go.dev above are not shown due to huge size of packages - #23)

Introduction

Microsoft Graph client library for Go. Still in PoC or pre-alpha stage. Don't use in production.

The library code is auto-generated from the REST API specification available at https://graph.microsoft.com/v1.0/$metadata.

The code generator is written in pure Go, in contrast to the official code generator heavily relying on C# and non-portable .NET Framework.

v0.x.x releases

See GitHub releases for all release tags and release notes, and pkg.go.dev for all Go module versions available for your applications.

Until v1.0.0, all types of changes might be included in every release: bug fixes, new features, even incompatible API updates.

Usage

You can choose API version when importing msgraph package:

import msgraph "github.com/yaegashi/msgraph.go/v1.0"
import msgraph "github.com/yaegashi/msgraph.go/beta"

You could benefit from better IDE assisted coding experience because Graph API specs are completely translated to Go codes by msgraph.go.

Code examples in the repository:

Hacking

Run go generate ./gen to download the metadata and generate library code from it.

$ go generate ./gen
2020/08/02 19:46:20 Downloading https://graph.microsoft.com/v1.0/$metadata to metadata/v1.0.xml
2020/08/02 19:46:20 metadata/v1.0.xml already exists, skipping
2020/08/02 19:46:21 Downloading https://graph.microsoft.com/beta/$metadata to metadata/beta.xml
2020/08/02 19:46:21 metadata/beta.xml already exists, skipping
2020/08/02 19:46:21 Creating directory ../v1.0
2020/08/02 19:46:21 Removing ../v1.0/ModelAverage.go
2020/08/02 19:46:21 Removing ../v1.0/RequestSchema.go
2020/08/02 19:46:21 Removing ../v1.0/RequestAndroid.go.go
...
2020/08/02 19:47:06 Creating ../v1.0/extensions.go
2020/08/02 19:47:06 Creating ../v1.0/msgraph.go
2020/08/02 19:47:06 Creating ../v1.0/const.go
2020/08/02 19:47:06 Creating ../v1.0/EnumAction.gonEnum.go
...
2020/08/02 19:47:07 Formatting ../v1.0/ModelMedia.go
2020/08/02 19:47:07 Formatting ../v1.0/RequestWorkbookFunctionsN.go
2020/08/02 19:47:07 Formatting ../v1.0/EnumReject.go

(Currently code generation from the latest metadata is broken - #22)

Todo

  • Save indented metadata.xml
  • Support Action elements in metadata
  • Support Function elements in metadata
  • Support batch requests
  • Access to additional properties like @odata.type @odata.id
  • Split output into multiple files
  • Generate camel cases in golang manner (IpAddress -> IPAddress)
  • Provide easy way to generate pointers to literals
  • Provide easy way to generate pointers to constants
  • Provide easy way to add queries like $expand $select $filter
  • Every request method should take a ctx as the first arg for better control
  • Online API docs (the output is too big for pkg.go.dev to handle - #23)
  • Unit tests
  • CI
  • Persist OAuth2 tokens in file
  • Persist OAuth2 tokens in object storage like Azure Blob
  • OAuth2 device auth grant
  • OAuth2 client credentials grant
  • Use string for EnumType (pointed out in #6)
  • Reduce number of generated files (#11)
  • Provide easy way to add HTTP headers like Prefer: outlook.timezone="Tokyo Standard Time"
  • Support max number of pages to retrieve from a collection
  • Support Windows time zone names in DateTimeTimeZone (utilize wtz.go)

References

Applications

msgraph.go's People

Contributors

charlesgreen avatar deepdiver1975 avatar yaegashi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

msgraph.go's Issues

Cannot sendMail with attachments

Currently the way that SendMail is defined, it is not obvious how to send a message with attachments.

Message is defined with Attachments: []Attachment; but when you pass an Attachment object to the API, you must provide either a FileAttachment or an ItemAttachment. In my case I wanted to provide a FileAttachment, which requires setting the ContentBytes field, which is not present on the Attachment struct.

I realize this is somewhat of a problem with representing the graph data-types (which make use of subclassing) in Go (which doesn't); and wondered if you'd given this some thought already – it's definitely not clear what the right solution is. Maybe an AddFileAttachment(file *FileAttachment) method on SendMailRequestBuilder?

Problem

I want to add a new License to a user:

newLicense := msgraph.AssignedLicense{
	SKUID:         &skui,
}

_, err = p.graphClient.Users().ID(*user.ID).AssignLicense(&msgraph.UserAssignLicenseRequestParameter{
	AddLicenses:    []msgraph.AssignedLicense{newLicense},
	RemoveLicenses: []msgraph.UUID{},
}).Request().Post(p.ctx)

I Get this response:
400 Bad Request: {"error":{"code":"Request_BadRequest","message":"Cannot convert a primitive value to the expected type 'Edm.Guid'. See the inner exception for more details.","innerError":{"date":"2020-04-16T22:07:51","request-id":"7d9ce15b-053c-47da-9bc7-c19eb0335462"}}}

what I am doing wrong?

does not compile on macOS

There are lots of files in the beta folder and macOS does not like it.

➜ go build
go build github.com/yaegashi/msgraph.go/beta: /usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64/compile: fork/exec /usr/local/Cellar/go/1.14/libexec/pkg/tool/darwin_amd64/compile: argument list too long

The beta folder is auto-generated, so I would recommend folding files where related.

For example:

  • ACLModel.go and ACLTypeEnum.go could be combined into one ACL.go
  • many AccessPackage*.go into AccessPackage.go
  • many more AndroidDeviceOwner*.go into AndroidDeviceOwner

Also seen in:

Documentation is too large to display on pkg.go.dev

pkg.go.dev now gives us a better diagnostic message: Documentation is too large to display

However as of v0.1.3, we receive this for both API versions v1.0 and beta. ☹️ We need the alternative API doc infrastructure for msgraph.go.

For the time being, a possible workaround would be seeing v0.1.2 documentation instead (only for v1.0 API):

How to create Azure AD app using service principal credentials

I have created an Azure AD app using " az ad sp create-for-rbac --sdk-auth --role Owner" command.
Also i have given required api permission as mentioned below:
api-permission

I am getting 403 error with below code:
error i am getting
error": "graphrbac.ApplicationsClient#Create: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code=\"Unknown\" Message=\"Unknown service error\" Details=[{\"odata.error\":{\"code\":\"Authorization_RequestDenied\",\"date\":\"2021-12-23T11:41:23\",\"message\":{\"lang\":\"en\",\"value\":\"Insufficient privileges to complete the operation.\"},\"requestId\":\"f192ac37-8b05-4a81-a582-13f0f5ca3594\"}}]"

Code i am using to initialize app client is :

appClient := graphrbac.NewApplicationsClient(tenantID) credConfig := auth.NewClientCredentialsConfig(clientID, clientSecret, tenantID) //credConfig.Resource = azure.PublicCloud.ResourceIdentifiers.Graph credConfig.Resource = "https://graph.microsoft.com" authorizer, err := credConfig.Authorizer() if err != nil { return appClient, err } appClient.Authorizer = authorizer

I am not sure how i can create an Azure AD app client for microsoft Graph API SDK, since there is no method i have found for the same.

update to latest xml

a new objectidentity resource was added:

  <ComplexType Name="objectIdentity">
        <Property Name="signInType" Type="Edm.String" />
        <Property Name="issuer" Type="Edm.String" />
        <Property Name="issuerAssignedId" Type="Edm.String" />
   </ComplexType>

it is used in the user resource.

GetMemberGroups doesn't work

Don't know what i am doing wrong ?!?

fmt.Println(p.graphClient.Groups().ID(azureUserID).MemberOf().ID(azureUserID).GetMemberGroups(&msgraph.DirectoryObjectGetMemberGroupsRequestParameter{SecurityEnabledOnly:P.Bool(false)}).Request().Post(p.ctx))

Official Microsoft Graph Go SDK

Hello everyone 👋

Vincent here from the Microsoft Graph SDKs team. I'm reaching out to announce we're working on an official Go SDK, we haven't announced the community preview yet as there are still a number of things we need to work through, but I though I'd reach out to give you an opportunity to provide feedback before anybody else!

A few benefits from this new SDK:

  • Fluent style APIs to all endpoints of the API
  • Contains all the models of the API
  • Is updated weekly to always be in sync with the API
  • Supports v1 and beta
  • Relies on Azure identity to provide support for multiple authentication flows (you also can implement your own authentication provider)
  • Provides middleware for Retry handling and Redirect handling (more to come)
  • And many more features to come!

As with every pre-previews, we have a list of known limitations we're working through.

We'd love for you to pop by the repos under our org, give it a try, and give us feedback on your experience with this new SDK.

Top seems to be ignored

I'm trying to use Top() on a query and the query string part of the request seems to simply be ignored. When I check the URL to debug, the query string is present, but the reply seems to be ignoring it.
Sample code:

graphClient := msgraph.NewClient(...)
ct := graphClient.Teams().ID(teamid).Channels().ID(channel).Messages().Request()
ct.Top(20)
fmt.Println("calling url: %s", ct.URL()) // calling url: https://graph.microsoft.com/beta/teams/.../channels/.../messages?%24top=20
rct, err := ct.Get(ctx)
fmt.Println("got %#v messages", len(rct)) // got 592 messages 

Unable to clear string attributes

The correct way to clear a string attribute is to assign it null value, but in the model, struct attributes are marked as omitempty, which means null values won't be pass to the API.

Is there any workaround?

How to download the Photo of a user?

I would like to obtain the Photo for a given user. I just find the metadata like height

			photo, err := graphClient.Users().ID( *user.ID ).Photo().Request().Get(ctx)
			var height = photo.Height

The documentation states that there should be a "$value" added to the path. How do I construct it?

Update code generator

Current msgrpah-generator.go cannot handle the latest API specfication.

Support Alias attribute (in v1.0 and beta):

<Schema Namespace="microsoft.graph" Alias="graph" xmlns="http://docs.oasis-open.org/odata/ns/edm">

Support different Namespace other than microsoft.graph (in beta):

<Schema Namespace="microsoft.graph.callRecords" xmlns="http://docs.oasis-open.org/odata/ns/edm">

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.