microsoftgraph / msgraph-sdk-go

Microsoft Graph SDK for Go
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
235 stars 36 forks source link

Could I got exmaple on the usage of 'appid={appid}' or 'uniquename={uniquename}' in import area? #698

Closed suqin-haha closed 4 months ago

suqin-haha commented 5 months ago

it's new to me that have the kind of import in go from the doc import graphapplications(uniquename='{uniquename}') "github.com/microsoftgraph/msgraph-sdk-go/applications(uniquename='{uniquename}')"

https://learn.microsoft.com/en-us/graph/api/application-upsert?view=graph-rest-1.0&tabs=go

I am keeping get error about it. Could I get a real/detailed emaple code about it?

rkodev commented 4 months ago

Hi @suqin-haha, Sorry for the challenge with the snipet. You can use the example below as we work to fix the snippet

// Code snippets are only available for the latest major version. Current major version is $v1.*

// Dependencies
import (
      "context"
      abstractions "github.com/microsoft/kiota-abstractions-go"
      msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
      graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
      graphapplicationswithuniquename "github.com/microsoftgraph/msgraph-sdk-go/applicationswithuniquename
      //other-imports
)

headers := abstractions.NewRequestHeaders()
headers.Add("Prefer", "create-if-missing")

configuration := &graphapplicationswithuniquename.ApplicationsWithUniqueNameRequestBuilderPatchRequestConfiguration{{
    Headers: headers,
}
requestBody := graphmodels.NewApplication()
displayName := "Display name"
requestBody.SetDisplayName(&displayName) 

// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
uniqueName := "{uniqueName}"
applications, err := graphClient.ApplicationsWithUniqueName(&uniqueName).Patch(context.Background(), requestBody, configuration)