Skip to Content
Menu
This question has been flagged
1 Reply
2587 Views

how can we create attachments in odoo through API call .i need to fetch chat history from an mobile application to odoo which may contain attachments(image/Pdf).need to create these as attachments in Odoo as well.how can we do that

Avatar
Discard
Best Answer

Hello Genelia,

Please find Code in Comment. 

Hope this answer helps you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

You can create attachment in odoo from any API by following steps :

- store binary content from the API response in a seperate variable and then create dictionary as shown below:

attachment_vals = {
'name': 'attachment_name.pdf',
'type': 'binary',
'raw': document_content, // binary content
'res_model': record._name,
'res_id': record.id
}
self.env['ir.attachment'].create(attachment_vals)

it will create an attachment and will be visible under the record in "Attachment Section".