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

Get attachment content is not implemented #92

Closed
Renji-FR opened this issue Feb 7, 2023 · 3 comments · Fixed by microsoft/kiota#2379
Closed

Get attachment content is not implemented #92

Renji-FR opened this issue Feb 7, 2023 · 3 comments · Fixed by microsoft/kiota#2379
Assignees

Comments

@Renji-FR
Copy link

Renji-FR commented Feb 7, 2023

Hi,

The Graph API documentation describe how to retrieve attachment content from the API:

https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http

GET /me/messages/{id}/attachments/{id}
GET /users/{id | userPrincipalName}/messages/{id}/attachments/{id}

GET /me/messages/{id}/attachments/{id}/$value
GET /users/{id | userPrincipalName}/messages/{id}/attachments/{id}/$value

One example: https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http#example-8-get-the-mime-raw-contents-of-an-event-attachment-on-a-message

GET https://graph.microsoft.com/v1.0/me/messages/AAMkADVIOAAA=/attachments/AAMkADVIOAAABEgAQACvkutl6c4FMifPyS6NvXsM=/$value

The issue is $value seems not to be implemented.

class AttachmentItemRequestBuilderGetQueryParameters
        """
        The fileAttachment and itemAttachment attachments for the message.
        """
        # Expand related entities
        expand: Optional[List[str]] = None

        # Select properties to be returned
        select: Optional[List[str]] = None

The class AttachmentItemRequestBuilderGetQueryParameters does not contain value : Optional[bool] = None

So it is not possible to use $value like described in https://learn.microsoft.com/en-us/graph/query-parameters?tabs=http#other-odata-url-capabilities

$value	Retrieves or updates the binary value of an item.	GET /me/photo/$value
@samwelkanda samwelkanda self-assigned this Feb 10, 2023
@Renji-FR
Copy link
Author

Renji-FR commented Feb 20, 2023

I use that as workaround:

from msgraph.generated.models.attachment_item import AttachmentItem

# attachment is of type AttachmentItem

content = attachment.additional_data['content_bytes']
content = base64.b64decode(content)
content = content.decode('ascii')

@Renji-FR
Copy link
Author

Renji-FR commented May 2, 2023

@samwelkanda @baywet Hi

With the last version of your SDK, my workaround does not work anymore:

from msgraph.generated.models.attachment_item import AttachmentItem

# attachment is of type AttachmentItem

content = attachment.additional_data['content_bytes']
content = base64.b64decode(content)
content = content.decode('ascii')

content_bytes does not exist anymore.

I can not find any documentation to download mail attachments.
I think I am not alone, see #110

@Renji-FR
Copy link
Author

Renji-FR commented May 2, 2023

Ok found how to download a message attachment:

request_message = self._msgraph_request.messages.by_message_id(message_id)
request_attachment = request_message .attachments.by_attachment_id(attachment_id)

attachment = await request_attachment .get(
    request_configuration=request_config
)

content = attachment.content_bytes
content = base64.b64decode(content)
content = content.decode('ascii')

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

Successfully merging a pull request may close this issue.

2 participants