Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Outlook] Error "The annotation 'odata.type' was found" on moving a message #351

Open
KikiLittlePanda opened this issue Jan 3, 2025 · 0 comments

Comments

@KikiLittlePanda
Copy link

KikiLittlePanda commented Jan 3, 2025

Hello,

Using the v3.1.2

I want to move an Outlook message to another folder, but I get this error:

{"error":{"code":"RequestBodyRead","message":"The annotation 'odata.type' was found. This annotation is either not recognized or not expected at the current position."}}

The code I wrote:

    private function moveMessage(\Office365\Outlook\Messages\Message $message, string $folderId): void
    {
        $message->move($folderId);
        $message->executeQuery();
    }

So I went into the ODataRequest class to debug

Here is the dump of the $request in executeQueryDirect():

^ Office365\Runtime\Http\RequestOptions^ {#1041
  +Url: "https://graph.microsoft.com/v1.0/me/Messages/xxx-id-xxx/Move"
  +Method: "POST"
  +Headers: array:2 [
    "Accept" => "application/json;odata.metadata=full;odata.streaming=false;ieee754compatible=true"
    "Content-Type" => "application/json;OData.metadata=full;OData.streaming=false;IEEE754Compatible=true"
  ]
  +Data: "{"DestinationId":"xxx-folderid-xxx=","@odata.type":".ClientValue"}"
  +IncludeHeaders: false
  +IncludeBody: true
  +AuthType: null
  +UserCredentials: null
  +Verbose: false
  +SSLVersion: null
  +StreamHandle: null
  +ConnectTimeout: null
  +TransferEncodingChunkedAllowed: false
  +FollowLocation: false
  +IPResolve: null
  +ForbidReuse: false
}

The ensureAnnotation() function is apparently adding this annotation.
I have no error and the move is functional if I comment these red lines:

    protected function ensureAnnotation($type, &$json,$format)
    {
        $typeName = (string)$type->getServerTypeInfo();
        if ($format instanceof JsonLightFormat && $format->MetadataLevel == ODataMetadataLevel::Verbose) {

            $json[$format->MetadataTag] = array("type" => $typeName);
            if(isset($format->ParameterTag)){
                $json = array($format->ParameterTag => $json);
            }
        }
-        elseif ($format instanceof JsonFormat){
-            if(!($type instanceof ClientValueCollection))
-                $json[$format->TypeTag] = "$typeName";
-        }
    }

I don't feel like it's a fix for this issue, so I'm here to ask how I could correctly fix it 😕

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant