cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DerekHurley
Helper I
Helper I

Can I attach JSON as a file to an email from Power Apps?

I want to send an email from Power Apps with the data recorded in the app formatted as JSON and attached as a .json file on the email. I also want to attach any pictures taken. I have been following Shane Young's video (https://www.youtube.com/watch?v=V3feURQfY3M) for how to attach the pictures, which works very well. But I have not been able to attach the JSON as a file to the email.

 

Copying how pictures are sent as attachments I have tried putting in JSON as:

 

{
    Name: "test.json",

    ContentBytes: 'The Formatted JSON',
    '@odata.type': I have tried a few different odata types but nothing worked
}

 

I can put the JSON in the body of the email but ideally, we would like is as a file. Does anyone know if this can be done? Or is it a limitation with the connection or Power Apps?

 

- Note: I am using the Office365.SendEmailV2 connection and it works perfectly for pictures. 

1 ACCEPTED SOLUTION

Accepted Solutions

.Hi @DerekHurley ,

 

Has your issue resolved?

I just find a workaround for your case via Flow. Let's create a flow:

1. create a PowerApps instant flow

2. Add 'Compose' action, set Input: Ask in PowerApp, get the JSON passed from PowerApps

3. Add 'Create File' from OneDrive for business action, select the Folder Path, enter the File Name, select File Content to Outputs of previous 'Compose' action.

4. Add 'Get file content' action, Set File: Id of previous 'Create File' action

5. Add 'Send an email (V2)' action, Set To, Subject and Body, enter Attachment Name, Select Attachment Content: File Content of previous 'Get file content' action.

 

Then add the flow into PowerApps, apply the Json result into the flow run code.

 

FlowName.Run( JSON(
{
GUID: gblReferenceGUID,
author_name: cmbName.Selected.DisplayName,
created_date_time: Now(),
Region: drpRegion.Selected.Value,
Site: txtSite.Text,
section1: {
name: "induction",
values: {
result_value: gblSiteInduction,
result_schema: "traffic_light",
result_text: txtSiteInductionComments.Text
}
},
section2: {
name: "documentation",
values: {
result_value: gblDocuments,
result_schema: "traffic_light",
result_text: txtDocumentsComments.Text
}
}
},
JSONFormat.IndentFour
))

 

Flow steps:

Snipaste_2020-03-09_12-06-32.png

Test Result:

Snipaste_2020-03-09_12-18-17.png

Sik

View solution in original post

4 REPLIES 4
v-siky-msft
Community Support
Community Support

Hi @DerekHurley 

 

How did you define the 'The Formatted JSON'?

The ContentBytes should be Blob URL, e.g.  appres://blobmanager/4cc184e7f90b4f5781a498cec7a161d4/1

Please refer to this video: https://www.youtube.com/watch?v=Ws6xEr5N1cU 

 

If you want to convert the Data to Blob URL, I am afraid it is not supported in PowerApps.

If you want this feature, please submit an idea to PowerApps Ideas Forum. https://powerusers.microsoft.com/t5/Power-Apps-Ideas/idb-p/PowerAppsIdeas 

Sik

Hi @v-siky-msft ,

 

Thanks for the response.

 

Here is (a shortened version of) what I have in Power Apps:

JSON(
    {
        GUID: gblReferenceGUID,
        author_name: cmbName.Selected.DisplayName,
        created_date_time: Now(),
        Region: drpRegion.Selected.Value,
        Site: txtSite.Text,
        section1: {
            name: "induction",
            values: {
                result_value: gblSiteInduction,
                result_schema: "traffic_light",
                result_text: txtSiteInductionComments.Text
            }
        },
        section2: {
            name: "documentation",
            values: {
                result_value: gblDocuments,
                result_schema: "traffic_light",
                result_text: txtDocumentsComments.Text
            }
        }
    },
    JSONFormat.IndentFour
)

 Which results in:

{
    "GUID": "a6ced1d9-61eb-4bf2-b2ea-68c8ffb9bbaa",
    "Region": "EUAF",
    "Site": "Perth",
    "author_name": "Derek Hurley",
    "created_date_time": "2020-02-21T05:53:13.071Z",
    "section1": {
        "name": "induction",
        "values": {
            "result_schema": "traffic_light",
            "result_text": null,
            "result_value": "Good"
        }
    },
    "section2": {
        "name": "documentation",
        "values": {
            "result_schema": "traffic_light",
            "result_text": "Test comments",
            "result_value": "Bad"
        }
    }
}

 

The above JSON is what I put into ContentBytes. What I am trying to do is send the above JSON (which is a text string) as a .json file attached to an email. 

 

I have done this with pictures, is there a way to do it for JSON?

 

Thanks.

@DerekHurley 

The codes just convert the data to JSON type, but the ContentBytes requires the Blob URL of Files. 

I come up with an idea that use AzureBlobStorage connector to create JSON file into blob storage, and then recall the JSON File Blob URL in ContentBytes parameter.  Reference: create block blob, get blob content 

AzureBlobStorage.CreateBlockBlob(<folderpath>,"Name.JSON",JSON("ABC"),{'Content-Type':"application/json"})
AzureBlobStorage.GetFileContent(<JSONFileBlobID>)
Office365Outlook.SendEmailV2("v-sikyan@microsoft.com","Subject goes here","Body goes here",{Attachments:Table({
Name: "Test.JSON",ContentBytes:<JSONFileBlobURL>,'@odata.type':""})})

I cannot verify this idea since my Azure subscription expired.

If it doesn't work, please submit a ticket to Microsoft for further assistance.

https://admin.powerplatform.microsoft.com/support 

Sik

 

.Hi @DerekHurley ,

 

Has your issue resolved?

I just find a workaround for your case via Flow. Let's create a flow:

1. create a PowerApps instant flow

2. Add 'Compose' action, set Input: Ask in PowerApp, get the JSON passed from PowerApps

3. Add 'Create File' from OneDrive for business action, select the Folder Path, enter the File Name, select File Content to Outputs of previous 'Compose' action.

4. Add 'Get file content' action, Set File: Id of previous 'Create File' action

5. Add 'Send an email (V2)' action, Set To, Subject and Body, enter Attachment Name, Select Attachment Content: File Content of previous 'Get file content' action.

 

Then add the flow into PowerApps, apply the Json result into the flow run code.

 

FlowName.Run( JSON(
{
GUID: gblReferenceGUID,
author_name: cmbName.Selected.DisplayName,
created_date_time: Now(),
Region: drpRegion.Selected.Value,
Site: txtSite.Text,
section1: {
name: "induction",
values: {
result_value: gblSiteInduction,
result_schema: "traffic_light",
result_text: txtSiteInductionComments.Text
}
},
section2: {
name: "documentation",
values: {
result_value: gblDocuments,
result_schema: "traffic_light",
result_text: txtDocumentsComments.Text
}
}
},
JSONFormat.IndentFour
))

 

Flow steps:

Snipaste_2020-03-09_12-06-32.png

Test Result:

Snipaste_2020-03-09_12-18-17.png

Sik

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,292)