microsoftgraph / msgraph-beta-sdk-ruby

Microsoft Graph Beta Ruby SDK
https://learn.microsoft.com/graph/sdks/use-beta?tabs=Ruby
MIT License
8 stars 0 forks source link

Body for GetPresencesByUserId blank #114

Open mattdrewitt opened 4 months ago

mattdrewitt commented 4 months ago

I have the following code:

context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new(
  ENV.fetch("MICROSOFT_TENANT_ID"),
  ENV.fetch("MICROSOFT_CLIENT_ID"),
  ENV.fetch("MICROSOFT_CLIENT_SECRET")
)

authentication_provider = MicrosoftGraphCore::Authentication::OAuthAuthenticationProvider.new(context, nil, ["https://graph.microsoft.com/.default"])

adapter = MicrosoftGraphBeta::GraphRequestAdapter.new(authentication_provider)
client = MicrosoftGraphBeta::GraphServiceClient.new(adapter)

begin
  body = MicrosoftGraphBeta::Communications::GetPresencesByUserId::GetPresencesByUserIdPostRequestBody.new
  body.ids = users.collect { |user| user[:id] }
  request = client.communications.get_presences_by_user_id.post(body)

  result = request.resume
rescue => e
  puts e.error
end

Note: I'm not showing the list of users above, but users is an array of hashes I'm pulling from for testing this example.

But it outputs:

#<MicrosoftGraphBeta::Models::ODataErrorsMainError:0x0000ffff92322638
 @additional_data={},
 @code="InvalidArgument",
 @inner_error=
  #<MicrosoftGraphBeta::Models::ODataErrorsInnerError:0x0000ffff92322368 
  @additional_data={"date"=>"2024-06-05T15:00:32"}, 
  @client_request_id="<REDACTED>", 
  @request_id="<REDACTED>">,
  @message="[ids]: Required property 'ids' not found in JSON. Path '', line 1, position 2.">

If I look at the body I will see the ids in the array, but for some reason serialization isn't working?

I tested the serializer and that seems to work fine, but its something about GetPresencesByUserIdRequestBuilder.to_post_request_information#56 as the line seems to the what actually uses it, but the content if I manually call it :

ri = client.communications.get_presences_by_user_id.to_post_request_information(body)

is blank:

irb(main):255> ri.inspect
=> "#<MicrosoftKiotaAbstractions::RequestInformation:0x0000ffff974b89e8 @headers=#<MicrosoftKiotaAbstractions::RequestHeaders:0x0000ffff974bfb80 
  @headers={\"Accept\"=>[\"application/json\"], \"Content-Type\"=>[\"application/json\"]}>, 
  @query_parameters={}, 
  @path_parameters={\"baseurl\"=>\"https://graph.microsoft.com/beta\"}, 
  @url_template=\"{+baseurl}/communications/getPresencesByUserId\", 
  @http_method=:POST, 
  @content=\"{}\">"

I'm not sure if I'm doing something wrong or this is broken. Let me know if you need more details.

baywet commented 3 months ago

Hi @mattdrewitt Thanks for using the SDK and for reaching out. Yes, the code you've shared looks correct, and it does look like a serialization issue. Here is roughly the trace of the calls

  1. builder sets the body
  2. which writes the object value
  3. which writes the information to a temp writer ??? this is where I believe we have a problem
  4. which uses auto-serialization information to serialize the object

Step 3 basically throws away the serialized body, I'm not sure why this was implemented like that, and it differs from other languages.

Is this something you'd like to look into further now that you have these pointers?