cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kanyavenkatappa
Frequent Visitor

To create news article based on the email received using Power automate

I have a requirement to build news article based on the email I received from customer. I followed this post .  It helped to some extent, but I am stuck in step 12 where I need to savepageasdraft. I get an error as "bad gateway" at this step.

16 REPLIES 16
Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,

 

Can you share a screenshot of how you currently have configured the Send an HTTP request action where you are saving the page as draft?

 

Can you also post the json value you are using in your body of that action?

Thank you. Here is the snapshot of GetFileMetadata and Send HTTP.getfilemetadata.PNGsendhttp.PNG

 

and the JSON

 

{"__metadata":{"type":"SP.Publishing.SitePage"},"LayoutWebpartsContent":"[{\"id\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"instanceId\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"title\":\"\\n Title area\\n \",\"description\":\"\\n Title area description\\n \",\"audiences\":[],\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{\"imageSource\":\"/_LAYOUTS/IMAGES/SLEEKTEMPLATEIMAGETILE.JPG\"},\"links\":{},\"customMetadata\":{\"imageSource\":{}}},\"dataVersion\":\"1.4\",\"properties\":{\"imageSourceType\":2,\"title\":\"@{variables('PageName')}\",\"textAlignment\":\"Left\",\"showPublishDate\":false,\"authors\":[],\"showTopicHeader\":false,\"authorByline\":[],\"layoutType\":\"CutInShape\",\"titlePlaceholder\":\"Name your news post\",\"topicHeader\":\"\",\"hasTitleBeenCommitted\":false},\"reservedHeight\":306}]","AuthorByline":[],"TopicHeader":"","Title":"@{variables('PageName')}","BannerImageUrl":"/_layouts/15/images/sitepagethumbnail.png","CanvasContent1":"[{\"controlType\":4,\"id\":\"1212fc8d-dd6b-408a-8d5d-9f1cc787efbb\",\"position\":{\"controlIndex\":2,\"sectionIndex\":1,\"sectionFactor\":12,\"zoneIndex\":1,\"layoutIndex\":1},\"addedFromPersistedData\":true,\"emphasis\":{},\"innerHTML\":\"<p>@{outputs('Compose')}@{outputs('Html_to_text')?['body']}<br></p>\"},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]","Categories":""}

Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,


Just to double check. Do you have a Send an HTTP request to SharePoint action which will create a news post page first?

 

createpage.png

 

If so, I think the problem is the PageName variable in your Get file metadata action. The news posts page will get a random name which won't correspond with the PageName variable in the File Identifier field.

 

Can you try and use this expression for the File Identifier field which will use the Url field instead?

 

 

replace(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['d']['Url'], '/', '%2f')

 

 

 

replace_field.png

 

After that you should be able to checkout and save the page as a draft based on the itemid of the file from the Get File metadata action.

 

itemid_savepagecheckout.png

Yes, I have Send an HTTP to create news post. I changed Get file metadata as per your suggestion. Still no luck. PFAgetfilemetadata_1.PNGsendhttp_1.PNG

Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,

 

Do you have the checkout page http request action in your flow? In your screenshot I only see a Get file metadata followed by a savepageasdraft, just making sure you have all the actions in place.

 

Btw, can you also share the raw input of the Send an HTTP request to SharePoint 2 action of the failed flow run?

Hi @Expiscornovus,

Yes I do have checkoutpage "Send an HTTP request".

checkout.PNG

 

Let me know if this is what you are looking from "Send an HTTP request to SharEPoint 2"

{
"inputs": {
"host": {
"connectionName": "shared_sharepointonline_1",
"operationId": "HttpRequest",
"apiId": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline"
},
"parameters": {
"dataset": "https://somewebsite/teams/sitename",
"parameters/method": "POST",
"parameters/uri": "_api/SitePages/pages(@{outputs('Get_file_metadata')?['body/ItemId']})/SavePageAsDraft",
"parameters/headers": {
"content-type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose"
},
"parameters/body": "{\"__metadata\":{\"type\":\"SP.Publishing.SitePage\"},\"LayoutWebpartsContent\":\"[{\\\"id\\\":\\\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\\\",\\\"instanceId\\\":\\\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\\\",\\\"title\\\":\\\"\\\\n Title area\\\\n \\\",\\\"description\\\":\\\"\\\\n Title area description\\\\n \\\",\\\"audiences\\\":[],\\\"serverProcessedContent\\\":{\\\"htmlStrings\\\":{},\\\"searchablePlainTexts\\\":{},\\\"imageSources\\\":{\\\"imageSource\\\":\\\"/_LAYOUTS/IMAGES/SLEEKTEMPLATEIMAGETILE.JPG\\\"},\\\"links\\\":{},\\\"customMetadata\\\":{\\\"imageSource\\\":{}}},\\\"dataVersion\\\":\\\"1.4\\\",\\\"properties\\\":{\\\"imageSourceType\\\":2,\\\"title\\\":\\\"@{variables('PageName')}\\\",\\\"textAlignment\\\":\\\"Left\\\",\\\"showPublishDate\\\":false,\\\"authors\\\":[],\\\"showTopicHeader\\\":false,\\\"authorByline\\\":[],\\\"layoutType\\\":\\\"CutInShape\\\",\\\"titlePlaceholder\\\":\\\"Name your news post\\\",\\\"topicHeader\\\":\\\"\\\",\\\"hasTitleBeenCommitted\\\":false},\\\"reservedHeight\\\":306}]\",\"AuthorByline\":[],\"TopicHeader\":\"\",\"Title\":\"@{variables('PageName')}@{outputs('Compose')}\",\"BannerImageUrl\":\"/_layouts/15/images/sitepagethumbnail.png\",\"CanvasContent1\":\"[{\\\"controlType\\\":4,\\\"id\\\":\\\"1212fc8d-dd6b-408a-8d5d-9f1cc787efbb\\\",\\\"position\\\":{\\\"controlIndex\\\":2,\\\"sectionIndex\\\":1,\\\"sectionFactor\\\":12,\\\"zoneIndex\\\":1,\\\"layoutIndex\\\":1},\\\"addedFromPersistedData\\\":true,\\\"emphasis\\\":{},\\\"innerHTML\\\":\\\"<p><br></p>\\\"},{\\\"controlType\\\":0,\\\"pageSettingsSlice\\\":{\\\"isDefaultDescription\\\":true,\\\"isDefaultThumbnail\\\":true}}]\",\"Categories\":\"\"}"
},
"authentication": "@parameters('$authentication')"
}
}

Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,

 

I was looking for the raw inputs to see the actual values which are used in the different dynamic content fields and variables. This way I can try and reproduce it with your test data. In your reply I still see the variables and the outputs of the compose actions as expressions. Can you post the actual values you are using?

 

Below is the raw input I used in my test. I was able to create the page as draft with this sample. Can you check if that sample works for you as well?

 

{
    "host": {
        "connectionReferenceName": "shared_sharepointonline",
        "operationId": "HttpRequest"
    },
    "parameters": {
        "dataset": "",
        "parameters/method": "POST",
        "parameters/uri": "_api/sitepages/pages(131)/SavePageAsDraft",
        "parameters/headers": {
            "content-type": "application/json;odata=verbose",
            "Accept": "application/json;odata-verbose"
        },
        "parameters/body": "{\"__metadata\":{\"type\":\"SP.Publishing.SitePage\"},\"LayoutWebpartsContent\":\"[{\\\"id\\\":\\\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\\\",\\\"instanceId\\\":\\\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\\\",\\\"title\\\":\\\"\\\\n Title area\\\\n \\\",\\\"description\\\":\\\"\\\\n Title area description\\\\n \\\",\\\"audiences\\\":[],\\\"serverProcessedContent\\\":{\\\"htmlStrings\\\":{},\\\"searchablePlainTexts\\\":{},\\\"imageSources\\\":{\\\"imageSource\\\":\\\"/_LAYOUTS/IMAGES/SLEEKTEMPLATEIMAGETILE.JPG\\\"},\\\"links\\\":{},\\\"customMetadata\\\":{\\\"imageSource\\\":{}}},\\\"dataVersion\\\":\\\"1.4\\\",\\\"properties\\\":{\\\"imageSourceType\\\":2,\\\"title\\\":\\\"Test\\\",\\\"textAlignment\\\":\\\"Left\\\",\\\"showPublishDate\\\":false,\\\"authors\\\":[],\\\"showTopicHeader\\\":false,\\\"authorByline\\\":[],\\\"layoutType\\\":\\\"CutInShape\\\",\\\"titlePlaceholder\\\":\\\"Name your news post\\\",\\\"topicHeader\\\":\\\"\\\",\\\"hasTitleBeenCommitted\\\":false},\\\"reservedHeight\\\":306}]\",\"AuthorByline\":[],\"TopicHeader\":\"\",\"Title\":\"Test\",\"BannerImageUrl\":\"/_layouts/15/images/sitepagethumbnail.png\",\"CanvasContent1\":\"[{\\\"controlType\\\":4,\\\"id\\\":\\\"1212fc8d-dd6b-408a-8d5d-9f1cc787efbb\\\",\\\"position\\\":{\\\"controlIndex\\\":2,\\\"sectionIndex\\\":1,\\\"sectionFactor\\\":12,\\\"zoneIndex\\\":1,\\\"layoutIndex\\\":1},\\\"addedFromPersistedData\\\":true,\\\"emphasis\\\":{},\\\"innerHTML\\\":\\\"<p>Test<b>Bold</b><br></p>\\\"},{\\\"controlType\\\":0,\\\"pageSettingsSlice\\\":{\\\"isDefaultDescription\\\":true,\\\"isDefaultThumbnail\\\":true}}]\",\"Categories\":\"\"}"
    }
}

 flowrunhistory.png

I don't have an option of "Show raw input". Is something disabled?

I have put savepageasdraft error and savepageasdraft

PFA snapshotretryerror.PNGsavepageasdraf.PNG

 

Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,

 

Can you share what the values are of the following elements in your flow?

@{variables('PageName')} & @{outputs('Compose')}

 

I want to use the same pagename and topicheader as you to see if I can reproduce this error.

PageName is the email subject I am using -> FW: goodone

Outputs(Compose): is email body -->

Hello all,
What are you doing
Good thanks

Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,

 

I can reproduce this behaviour with your data and setup. I think the issue is that you are using the email body for the Title field.

 

Are you sure this is in the right place. Imo it makes more sense that it would be in the body of the page you are creating, within the innerHTML property instead?

 

topicheader_innerhtml.png

 

Edit: btw, I was testing it like this.

 

testcontent.png

kanyavenkatappa
Frequent Visitor

Hi @Expiscornovus,

email body has somehow skipped from innerHtml when taking screenshot. Later I had changed it under innerHTML.

Would you be able to share your complete flow ?

kanyavenkatappa
Frequent Visitor

Any updates @Expiscornovus 

Expiscornovus
Super User
Super User

Hi @kanyavenkatappa,


This is the whole flow I have been using and tested.

 

1. Add a Manually trigger action, a initialize variable and a compose action.

 

createpost_test.png

 

2. Add a Send an HTTP request to SharePoint action.

createpage.png

 

3. Add a Get File metadata action. Configure it to use the following expression:

 

replace(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['d']['Url'], '/', '%2f')

 

 

 

replace_field.png

 

4. Add another Send an HTTP request to SharePoint action. Use the following URI:

/_api/sitepages/pages(@{outputs('Get_file_metadata')?['body/ItemId']})/checkoutpage

checkoutpage01.png

 

5. Add a last Send an HTTP request to SharePoint action.

 

Use the following URI:

_api/sitepages/pages(@{outputs('Get_file_metadata')?['body/ItemId']})/SavePageAsDraft

 

Use the following body

{"__metadata":{"type":"SP.Publishing.SitePage"},"LayoutWebpartsContent":"[{\"id\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"instanceId\":\"cbe7b0a9-3504-44dd-a3a3-0e5cacd07788\",\"title\":\"\\n Title area\\n \",\"description\":\"\\n Title area description\\n \",\"audiences\":[],\"serverProcessedContent\":{\"htmlStrings\":{},\"searchablePlainTexts\":{},\"imageSources\":{\"imageSource\":\"/_LAYOUTS/IMAGES/SLEEKTEMPLATEIMAGETILE.JPG\"},\"links\":{},\"customMetadata\":{\"imageSource\":{}}},\"dataVersion\":\"1.4\",\"properties\":{\"imageSourceType\":2,\"title\":\"@{variables('PageName')}\",\"textAlignment\":\"Left\",\"showPublishDate\":false,\"authors\":[],\"showTopicHeader\":false,\"authorByline\":[],\"layoutType\":\"CutInShape\",\"titlePlaceholder\":\"Name your news post\",\"topicHeader\":\"\",\"hasTitleBeenCommitted\":false},\"reservedHeight\":306}]","AuthorByline":[],"TopicHeader":"","Title":"@{variables('PageName')}","BannerImageUrl":"/_layouts/15/images/sitepagethumbnail.png","CanvasContent1":"[{\"controlType\":4,\"id\":\"1212fc8d-dd6b-408a-8d5d-9f1cc787efbb\",\"position\":{\"controlIndex\":2,\"sectionIndex\":1,\"sectionFactor\":12,\"zoneIndex\":1,\"layoutIndex\":1},\"addedFromPersistedData\":true,\"emphasis\":{},\"innerHTML\":\"@{outputs('Compose')}\"},{\"controlType\":0,\"pageSettingsSlice\":{\"isDefaultDescription\":true,\"isDefaultThumbnail\":true}}]","Categories":""}

 

savepageasdraft_again.png

TKEnes
Helper I
Helper I

Hi @Expiscornovus,

I am trying to follow your steps but I have a question: On the initialize variable and compose part you are already giving a title and content for the news post. But the title and content should be from the email that came. How can you achieve that? Especially when its a mail from a group.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (3,123)