Skip to content

Get attachment content is not implemented #92

Closed
microsoft/kiota
#2379

Description

@Renji-FR

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

Activity

  1. Renji-FR commented on Feb 20, 2023

    @Renji-FR
    Author

    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')
  2. Renji-FR commented on May 2, 2023

    @Renji-FR
    Author

    Samwel K. (@samwelkanda) Vincent Biret (@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

  3. Renji-FR commented on May 2, 2023

    @Renji-FR
    Author

    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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions