web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get all attachment arr...
Power Automate
Unanswered

Get all attachment arrays from json object

(0) ShareShare
ReportReport
Posted on by

Hi,

 

So I've hit a little of a dead end.

 

The goal:

I'm tasked with getting all attachments from all attached emails in all levels (so if an email has an email attachment which has an email attachment with files attached, I need to get those files.)

 

The problem:

How can I extract and bundle all "Attachments"-arrays from the graph-response (I'm using the outlook, send api-call function in Power Automate which gives me a nice looking json with all subsequent attachments in several different arrays.)

 

There can be 0 arrays with attachments, or there can be x arrays with attachments, and all of the arrays stays under the email item in the json.

 

So somehow I have to be able to either take all the attachments regardless of which array they belong to, or I have to somehow go through the json and check if there is an array and extract the data from that array. I'm leaning towards solution 1 but I can't really get it working.

Categories:
I have the same question (0)
  • CU28111532-0 Profile Picture
    on at

    Ah, right! No, I don't need to know any pathing at all. I just need the valuepairs, but that's where I fall flat on my face. 😕

  • lbendlin Profile Picture
    8,540 Super User 2025 Season 2 on at

    That's what I meant with the brute forcing - flatten / ignore the hierarchy and collect all pairs of name/contentBytes. Those represent the actual attachments, regardless of how deeply nested (unless you need to know the full hierarchy path/depth? )

  • CU28111532-0 Profile Picture
    on at

    Yeah, the problem is that I also need to handle the emails (which has no contentType). So in the perfect life I could gather all the attachment-items from all the arrays to a new array, then loop through this array and finally do a conditioned Each-loop where I handle the files and emails.

     

    The attachment arrays can also hold emails that has their own attachment arrays which can contain emails which has their own attachment arrays and so on/so forth... So it'd have to be able to handle all the attachment arrays without hesitation.

  • lbendlin Profile Picture
    8,540 Super User 2025 Season 2 on at

    You could parse by contentType.  For the attachment that is a parent the contentType is null.

     

    lbendlin_0-1692278394318.png

     

    for the true attachments it is not null

    lbendlin_1-1692278427986.png

    Or you could brute force the parsing by using  a Select action on name and contentBytes  values only.

     

     

     

  • CU28111532-0 Profile Picture
    on at

    Here's a very simple result from the api-call. I can't really show the real data because of there being privacy issues by doing that:

    But as you can see there are several attachments-arrays, and I need to get every data from every child under every attachment-array and "flatten" them so I can work with the data.

       

     

     

     

    {
     "@odata.type": "#microsoft.graph.message",
     "id": "",
     "createdDateTime": "2023-08-17T09:49:48Z",
     "lastModifiedDateTime": "2023-08-17T09:51:24Z",
     "receivedDateTime": "2023-08-17T09:29:08Z",
     "sentDateTime": "2023-08-17T09:29:06Z",
     "hasAttachments": true,
     "internetMessageId": "REDACTED",
     "subject": "Fw: Testmejl: med signatur och attachad bild (png)",
     "bodyPreview": "Ska innehålla ett mejl som är forwardat as attachment och inuti det mejlet ska det ligga en PNG-fil samt signatur med",
     "importance": "normal",
     "conversationId": "REDACTED=",
     "conversationIndex": "REDACTED",
     "isDeliveryReceiptRequested": false,
     "isReadReceiptRequested": false,
     "isRead": true,
     "isDraft": false,
     "webLink": "REDACTED",
     "internetMessageHeaders": [],
     "sender": {
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     },
     "from": {
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     },
     "toRecipients": [{
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     }],
     "flag": {
     "flagStatus": "notFlagged"
     },
     "attachments": [
     {
     "@odata.type": "#microsoft.graph.itemAttachment",
     "id": "REDACTED",
     "lastModifiedDateTime": "2023-08-17T09:51:24Z",
     "name": "Testmejl: med signatur och attachad bild (png)",
     "contentType": null,
     "size": 27964,
     "isInline": false,
     "item@odata.associationLink": "https://graph.microsoft.com/beta/users('REDACTED')/messages('')/$ref",
     "item@odata.navigationLink": "https://graph.microsoft.com/beta/users('REDACTED')/messages('')",
     "item": {
     "@odata.type": "#microsoft.graph.message",
     "id": "",
     "createdDateTime": "2023-08-17T09:49:48Z",
     "lastModifiedDateTime": "2023-08-17T09:51:24Z",
     "receivedDateTime": "2023-08-17T09:22:03Z",
     "sentDateTime": "2023-08-17T09:22:02Z",
     "hasAttachments": true,
     "internetMessageId": "REDACTED",
     "subject": "Testmejl: med signatur och attachad bild (png)",
     "bodyPreview": "Best regards,\r\n\r\nREDACTED",
     "importance": "normal",
     "conversationId": "REDACTED",
     "conversationIndex": "REDACTED",
     "isDeliveryReceiptRequested": false,
     "isReadReceiptRequested": false,
     "isRead": false,
     "isDraft": false,
     "webLink": "REDACTED",
     "internetMessageHeaders": [{
     "name": "Received",
     "value": "from REDACTED (REDACTED20b:36a::10) by REDACTED with HTTPS; Thu, 17 Aug 2023 09:22:03 +0000"
     }, {
     "name": "Received",
     "value": "from REDACTED (REDACTED10:1a1::5) by REDACTED (REDACTED20b:36a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id REDACTED31; Thu, 17 Aug 2023 09:22:02 +0000"
     }, {
     "name": "Received",
     "value": "from REDACTED ([REDACTED:c0d6:7fb2]) by REDACTED ([REDACTED:c0d6:7fb2%6]) with mapi id REDACTED029; Thu, 17 Aug 2023 09:22:02 +0000"
     }, {
     "name": "Authentication-Results",
     "value": "dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=abb.com;"
     }, {
     "name": "Content-Type",
     "value": "application/ms-tnef"
     }, {
     "name": "Content-Transfer-Encoding",
     "value": "binary"
     }, {
     "name": "From",
     "value": "\"REDACTED\" <REDACTED>"
     }, {
     "name": "To",
     "value": "\"REDACTED\" <REDACTED>"
     }, {
     "name": "CC",
     "value": "REDACTED"
     }, {
     "name": "Subject",
     "value": "Testmejl: med signatur och attachad bild (png)"
     }, {
     "name": "Thread-Topic",
     "value": "Testmejl: med signatur och attachad bild (png)"
     }, {
     "name": "Thread-Index",
     "value": "REDACTED"
     }, {
     "name": "Date",
     "value": "Thu, 17 Aug 2023 09:22:02 +0000"
     }, {
     "name": "Message-ID",
     "value": "REDACTED"
     }, {
     "name": "Accept-Language",
     "value": "en-US"
     }, {
     "name": "Content-Language",
     "value": "en-US"
     }, {
     "name": "X-MS-Has-Attach",
     "value": "yes"
     }, {
     "name": "X-MS-Exchange-Organization-SCL",
     "value": "1"
     }, {
     "name": "X-MS-TNEF-Correlator",
     "value": "REDACTED"
     }, {
     "name": "MIME-Version",
     "value": "1.0"
     }, {
     "name": "X-MS-Exchange-Organization-MessageDirectionality",
     "value": "Originating"
     }, {
     "name": "X-MS-Exchange-Organization-AuthSource",
     "value": "REDACTED"
     }, {
     "name": "X-MS-Exchange-Organization-AuthAs",
     "value": "Internal"
     }, {
     "name": "X-MS-Exchange-Organization-AuthMechanism",
     "value": "04"
     }, {
     "name": "X-MS-Exchange-Organization-Network-Message-Id",
     "value": "REDACTED"
     }, {
     "name": "X-MS-PublicTrafficType",
     "value": "Email"
     }, {
     "name": "X-MS-TrafficTypeDiagnostic",
     "value": "DBAPR06MB7077:EE_|AM8PR06MB7426:EE_|DBAPR06MB7077:EE_"
     }, {
     "name": "Return-Path",
     "value": "REDACTED"
     }, {
     "name": "X-MS-Exchange-Organization-ExpirationStartTime",
     "value": "17 Aug 2023 09:22:02.6308 (UTC)"
     }, {
     "name": "X-MS-Exchange-Organization-ExpirationStartTimeReason",
     "value": "OriginalSubmit"
     }, {
     "name": "X-MS-Exchange-Organization-ExpirationInterval",
     "value": "1:00:00:00.0000000"
     }, {
     "name": "X-MS-Exchange-Organization-ExpirationIntervalReason",
     "value": "OriginalSubmit"
     }, {
     "name": "X-MS-Office365-Filtering-Correlation-Id",
     "value": "3c705933-1ee4-485d-9d0c-08db9f036a6c"
     }, {
     "name": "X-MS-Exchange-AtpMessageProperties",
     "value": "SA|SL"
     }, {
     "name": "X-Microsoft-Antispam",
     "value": "BCL:0;"
     }, {
     "name": "X-Forefront-Antispam-Report",
     "value": "CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:REDACTED;PTR:;CAT:NONE;SFS:;DIR:INT;"
     }, {
     "name": "X-MS-Exchange-CrossTenant-OriginalArrivalTime",
     "value": "17 Aug 2023 09:22:02.2082 (UTC)"
     }, {
     "name": "X-MS-Exchange-CrossTenant-FromEntityHeader",
     "value": "Hosted"
     }, {
     "name": "X-MS-Exchange-CrossTenant-Id",
     "value": "REDACTED"
     }, {
     "name": "X-MS-Exchange-CrossTenant-AuthSource",
     "value": "REDACTED"
     }, {
     "name": "X-MS-Exchange-CrossTenant-AuthAs",
     "value": "Internal"
     }, {
     "name": "X-MS-Exchange-CrossTenant-Network-Message-Id",
     "value": "REDACTED"
     }, {
     "name": "X-MS-Exchange-CrossTenant-MailboxType",
     "value": "HOSTED"
     }, {
     "name": "X-MS-Exchange-CrossTenant-UserPrincipalName",
     "value": "REDACTED"
     }, {
     "name": "X-MS-Exchange-Transport-CrossTenantHeadersStamped",
     "value": "AM8PR06MB7426"
     }, {
     "name": "X-MS-Exchange-Transport-EndToEndLatency",
     "value": "00:00:01.0975480"
     }, {
     "name": "X-MS-Exchange-Processed-By-BccFoldering",
     "value": "REDACTED027"
     }, {
     "name": "X-Microsoft-Antispam-Mailbox-Delivery",
     "value": "ucf:0;jmr:0;auth:0;dest:I;ENG:(910001)(944506478)(944626604)(920097)(425001)(930097)(140003)(1420103);"
     }, {
     "name": "X-Microsoft-Antispam-Message-Info",
     "value": "REDACTED"
     }],
     "body": {
     "contentType": "html",
     "content": ""
     },
     "sender": {
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     },
     "from": {
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     },
     "toRecipients": [{
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     }],
     "ccRecipients": [{
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     }, {
     "emailAddress": {
     "name": "REDACTED",
     "address": "REDACTED"
     }
     }],
     "flag": {
     "flagStatus": "notFlagged"
     },
     "attachments": [{
     "@odata.type": "#microsoft.graph.fileAttachment",
     "@odata.mediaContentType": "image/png",
     "id": "REDACTED",
     "lastModifiedDateTime": "2023-08-17T09:51:24Z",
     "name": "image.png",
     "contentType": "image/png",
     "size": 1219,
     "isInline": true,
     "contentId": "REDACTED",
     "contentLocation": null,
     "contentBytes": "REDACTED"
     }, {
     "@odata.type": "#microsoft.graph.fileAttachment",
     "@odata.mediaContentType": "image/png",
     "id": "REDACTED",
     "lastModifiedDateTime": "2023-08-17T09:51:24Z",
     "name": "download.png",
     "contentType": "image/png",
     "size": 2222,
     "isInline": false,
     "contentId": null,
     "contentLocation": null,
     "contentBytes": "REDACTED"
     }]
     }
     }],
     "body": {
     "contentType": "html",
     "content": ""
     }
     }

     

     

     

     

     

  • lbendlin Profile Picture
    8,540 Super User 2025 Season 2 on at
    I'm using the outlook, send api-call function in Power Automate which gives me a nice looking json with all subsequent attachments in several different arrays.

    would you mind showing a sample output for that?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 258 Super User 2025 Season 2

#2
trice602 Profile Picture

trice602 205 Super User 2025 Season 2

#3
Expiscornovus Profile Picture

Expiscornovus 204 Most Valuable Professional

Last 30 days Overall leaderboard