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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Create file with conte...
Power Automate
Unanswered

Create file with content (with audience targeting)

(0) ShareShare
ReportReport
Posted on by 11

Hi,
I'm trying to do "Create file" (aspx file to SiteColumns, located on a different site than the file from I'm get content). With an uncomplicated aspx page, everything goes correctly. But if I add to the file audience targeting I get the best error ever "Object reference not set to an instance of an object". If I try to create a file in the same site as target (with audience targieting), everything goes fine. I realize that the audience groups are created dynamically in site, so in flow I added a restful _api/web/ensureuser (@v)?@V='groupEmail@ccc.com', which generates it when there isn't exist. Rest works fine, adds groups BUT that doesn't fix the problem !!
Flow only works for pages without an audience targeting set.
Any ideas.

regards

 

Categories:
  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @tesss,

     

    Can you share a couple of screenshots of your setup?

     

    Have you tried using the claims value of the group in the audience field? Below is an example of that.

     

    updatefileproperties_audience.png

  • tesss Profile Picture
    11 on at

    Thank you for your reply but that's not what I meant.

    The problem is in the response from "Get file content using path".

    When response (not metadate!) includes audience targeting and I'm trying to save it as a new file on ANOTHER site then there is an error. If audience targeting is empty, then everything is fine.

    I do adding Audience using rest 

    tesss_1-1635330940160.png

     

     

  • tesss Profile Picture
    11 on at

    Details 

    I have two files, one doesn't have set an audience the other has.
    In flow I use "Get file content using path" then in another Site I do "Create file".
    With set audience, create a new page doesn't work. If audience isn't set everything works fine.
    Interestingly, creating a new file works fine with these two variants, when everything is done in the context of one site.

    tesss_0-1635334152247.png

     

  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @tesss,

     

    Thanks for sharing a screenshot your current setup. That helps clarifying what you are looking for.

     

    Can you format it as an array and use the key property in the fieldvalue of the audience targeting field? Let me know how your test works out.

     

    keyinbody.png

  • tesss Profile Picture
    11 on at

    Forget about recipients for a moment, let's assume I don't want to carry this information over to a new file.
    The reality is that rest ValidateUpdateListItem doesn't run if the file had Audiences set.
    Because it is interrupted at the level of creating a new file.

     

    tesss_0-1635336775290.png

    if "File Content" is from file with Audience set AND (this is important) file is on different site then - error !

    if "File Content" is from file without audiences and is on different site then - is ok

    if "File Content" is from file with audiences set and is on the same site then is ok !

  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @tesss,

     

    Have you tried creating the page with a POST request against /_api/sitepages/pages endpoint instead of the Create File action. That option should give you a bit more options in the body of the request.

  • tesss Profile Picture
    11 on at

    Hi @Expiscornovus,

    Thanks for you help. I still have a problem, I can't do it properly.

    1.  I'm using "Get file content"
    2.  Create new file by rest api (how can i add content to body on this place ??)

     

    tesss_0-1635406831350.png

    3. Update file

    tesss_1-1635407020236.png

     

    It's work fine when content comes from a file with no properties "Audiences" - if content has audiences set then "BadGateway"

     

    tesss_2-1635407357645.png

     

     

  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @tesss,

     

    Let me try and reproduce this in my development environment.

     

    Just a couple of things to double check for my repro:

    What type of audience are you using? Security Group or Microsoft 365 Group?

    And I am also assuming that audience targeting is enabled on the target site pages library?

  • tesss Profile Picture
    11 on at

    There are two identical sites, audience is run on the sitepages libraries. I am using Public Office 365 Groups.

    I would like to mention that all flow works fine within one site. It only breaks down if I'm running between two sites.

     

    Thank

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 302 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 263

#3
Henil Profile Picture

Henil 115

Last 30 days Overall leaderboard