Adding an attachment via API - Power automate HTTP Post

Good morning, <Note in writing this, I have actually Solved the issue – read on!>

I am using Power automate (flow) to integrate between BUZ and ServiceM8. All is going extremely well thank you apart from……

I have created workorders and each workorder is derived from data in an excel file (.xlsm). I would like to add the excel file as an attachment. Manually it works perfectly so i am happy with the basic concepts.

Looking at the howto and the documentation, I have completed Step1 (Create Work order), Step2 (Create attachment) and am having difficulty with step 3 (upload attachment data)

I am having two main issue being;

  1. I don’t understand enough of curl to translate curlopt to the http request I am using.
  2. My data file is in sharepoint - however for what it is worth, I have a base64 string with the content.

My request looks like;

And this actually works - but it creates a file (when I extract the attachment that looks like….

{“filepath”:"UEsDBBQA

so obviously it appears that the entire body is used as the file content.

If I take away the json and just put $content as the body, I receive the following error. (Actually I don’t receive an error - and the attachment is created - but it has saved the data as the base64 string rather that the actual binary data.

OK - now I have done some updates and now the issue is solved - however it may be beneficial for others to see the solution.

Note this is power automate, macro enabled excel file stored in sharepoint example.

  1. When I get the file content using path sharepoint connector I get the content-type of application/vnd.ms-excel.sheet.macroEnabled.12

  2. In the HTML Post operation, I use this string as the content-type

  3. The accept header is still application/json

  4. The body of the request is; body(‘Get_file_Content_using_Path’) - ie the complete body returned from the sharepoint action get file content using path which looks like;

  5. {

    “$content-type”: “application/vnd.ms-excel.sheet.macroEnabled.12”,

    “$content”: "UEsDBBQA…………………………….”}

the only remaining issue(s) I have are;

  1. Just clicking on the link in service m8 (On a PC web interface) does not allow me to view the file - it recomends appsheet or google sheets - I would prefer to open with excel
  2. If I right click on the link, it downloads the file to downloads with a weird name such as dbo_0059afd6-96a9-494a-b665-23d593c72bcb.xlsm. This also happens when I upload a file via the web interface (drag and drop).
  3. The IOS App opens the file with no issues.

So in essence, my real question now that I have answered the original issue (Uploading) is can I extend serviceM8 so that when I click on a document it actually opens that document directly (In web view).

All the best

Stan

Hi Stan,

Nice work getting the upload piece sorted. For anyone else following along, the documented approach is (1) create the Attachment record and then (2) upload the file data to Attachment/{uuid}.file as binary data, which attaches it to the job’s Diary.

On your new question (opening an Excel file directly in the web dashboard): at the moment, Excel/Office files can’t be previewed in ServiceM8 on desktop/web, so they need to be downloaded and opened in Excel (it’s by design).

That means there isn’t a way to “extend” ServiceM8 so a single click opens an .xlsm inline in the web view (the workaround is typically to:

  • convert the file to PDF before attaching, so it can be viewed in-browser as a PDF
  • or host the workbook in SharePoint/OneDrive/etc and add a link in the job (so the browser opens the SharePoint/Office web experience instead)

On the “dbo_…” download filename: we’ve seen cases where downloads default to a system-generated identifier like dbo_<uuid>… in the online dashboard, and there isn’t currently a supported way to customise that automatic naming.

That should clarify what’s currently possible in the web dashboard.

Thanks,
Cody

Thanks Cody for the advice/answers

Stan