Search code examples
gomicrosoft-graph-apioutlook-restapi

Type error trying the microsoft graph api for golang


I am currently playing around with the microsoft graph api examples for golang.

I am getting the following error using one of their examples:

"Cannot use '&contentType' (type *string) as the type *BodyType"

In other examples I would understand that its simply the wrong type and instead of passing in a type *string I need to pass in e.g a string.

However I have no idea what a *BodyType is in this scenario? What are they looking for here? https://learn.microsoft.com/en-gb/graph/api/message-update?view=graph-rest-1.0&tabs=go

requestBody := msgraphsdkm.NewMessage()
subject := "subject-value"
requestBody.SetSubject(&subject)
body := msgraphsdkm.NewItemBody()
requestBody.SetBody(body)
contentType := ""
body.SetContentType(&contentType)
content := "content-value"
body.SetContent(&content)
inferenceClassification := "other"
requestBody.SetInferenceClassification(&inferenceClassification)
messageId := "message-id"
graphClient.Me().MessagesById(&messageId).Patch(requestBody)

I am also getting the same error for inferenceClassification

Cannot use '&inferenceClassification' (type *string) as the type *InferenceClassificationType I've also no idea what this is looking for?

Apologies for the basic questions

Update: As per Gavins comment its expecting an int contentType := 1 body.SetContentType((*msgraphsdk.BodyType)(&contentType))


Solution

  • contentType := 1
    
    body.SetContentType((*msgraphsdkm.BodyType)(&contentType))
    

    It needed an int as per Gavins comment https://github.com/microsoftgraph/msgraph-sdk-go/blob/eb2d097f9010a618832461f649740084d7823b02/models/body_type.go#L6