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

Get File Content error from Form Upload

I am trying to attach files uploaded to a Form to a Jira Issue but I am getting a BadRequest error early in the flow.

 

In the activity: GET FILE CONTENT (ONEDRIVE FOR BUSINESS) the INPUTS appears to have the right URL but the OUTPUT has errors.

 

Edit-your-flow-Power-Automate (1).png

 

INPUT:

 

[{"name":"Task - Create_anonymous.png","link":"https://XXX.sharepoint.com/personal/XXX/Documents/Apps/Microsoft%20Forms/XXX%20Service%20Desk%20(2)/...","id":"01PVJRN2GDHTOVH623X5AJATRKKYPSHA3J","type":null,"size":68091,"referenceId":"01PVJRN2HRJESD53VNRJC2UKLVO2PEMZU7","driveId":"b!eoT3hbZ3lkuqSZap3wewuTey4SB5hgtFhUK-Ow0n_36D2nwVnrIXRKR_IuhRgjgY","status":1,"uploadSessionUrl":null}]

 

OUTPUT:

 

{
    "statusCode"400,
    "headers": {
        "Timing-Allow-Origin""*",
        "x-ms-apihub-cached-response""false",
        "x-ms-apihub-obo""false",
        "Date""Mon, 15 Apr 2024 12:19:00 GMT",
        "Content-Length""575",
        "Content-Type""application/json"
    },
    "body": {
        "error": {
            "code"400,
            "source""australia-001.azure-apim.net",
            "clientRequestId""fe661283-23bc-4ca0-aa65-6c2adf1962b8",
            "message""The response is not in a JSON format.",
            "innerError""<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">\r\n<HTML><HEAD><TITLE>Bad Request</TITLE>\r\n<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\"></HEAD>\r\n<BODY><h2>Bad Request - Invalid URL</h2>\r\n<hr><p>HTTP Error 400. The request URL is invalid.</p>\r\n</BODY></HTML>\r\n"
        }
    }
}

I then tried the Action: GET FILE CONTENT FROM PATH (ONEDRIVE FOR BUSINESS) but got this OUTPUT ERROR:

{
    "statusCode"400,
    "headers": {
        "Cache-Control""no-cache",
        "Pragma""no-cache",
        "Transfer-Encoding""chunked",
        "x-ms-request-id""29d4afed-147b-4d79-a1cc-13d4195fdb7e",
        "X-AspNet-Version""4.0.30319",
        "X-Powered-By""ASP.NET",
        "Timing-Allow-Origin""*",
        "x-ms-apihub-cached-response""false",
        "x-ms-apihub-obo""false",
        "Date""Mon, 15 Apr 2024 12:29:46 GMT",
        "Content-Type""application/json",
        "Content-Length""92",
        "Expires""-1"
    },
    "body": {
        "status"400,
        "message""Invalid request",
        "source""api.connectorp.svc.ms"
    }
}
14 REPLIES 14
Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @GKlose,

 

The upload question returns a string with different properties for each uploaded file. You can use a json function to convert it from a string to an array.

 

After that you can loop through this array and retrieve the details of each item/attachment with an Apply to Each.

 

One of those properties is the id of the file. You can use that value in your Get File content action.

 

Below is an example

 

1. Expression to convert string answer to array (change the id to your Forms upload attachments question id)

 

 

json(outputs('Get_response_details')?['body/re63869bd6ae04a5683cde0c7419c6578'])

 

 

 

2. Expression to retrieve File Id

 

 

item()['Id']

 

 

 

idofcurrentitem.png

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


GKlose
Frequent Visitor

Hi @Expiscornovus , thank you so much for your suggestion. Before I try and implement this, will I be able to (use this ID to) actually copy or upload the file into Jira (as an attachment or comment linked to the Issue).

 

If so, I will create a new topic on how to do this. But for now I just need to know that I am heading in the right direction.

 

Use case: A Jira user should be able to open/view the attachment even though they do not have any access to the original attachment in Sharepoint*.

 

* There has been a change in that the Form now generates the attachment to a Sharepoint folder (as the Form ownership is now a Group and not an individual).

 

GKlose
Frequent Visitor

HI @Expiscornovus , to complicate things, I have now switched to storing the Uploads in Sharepoint.

 

So I have tried to replace the Onedrive Action with the Sharepoint Action (Get File Metadata) with the File Identifier being the UPLOAD dynamic field and the Site address being the Teams site from the drop down menu.

And I keep getting an error:

Route did not match
clientRequestId: f83a25d4-1749-497b-94be-7bfe65e0356e
serviceRequestId: f83a25d4-1749-497b-94be-7bfe65e0356e

I am so lost.

Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @GKlose,

 

Yes, that would be slightly different. In that case I would retrieve the path first (ServerRelativeUrl) of each upload (via a HTTP request) and use a Get File Content Using Path action instead of your Get File Metadata). 

 

Below are the steps of my proposed approach (also shared it earlier in this thread) and I also blogged about this recently with detailed steps:

https://www.expiscornovus.com/2024/02/13/retrieve-files-from-upload-file-question/

 

Below is a short snippet of that same example

 

1. Add a Send an HTTP request within the attachment question apply to each loop

a. Use as Site Address (this expression is used to retrieve the site address portion of the link)

 

 

 

join(take(split(item()['link'], '/'), 5), '/')

 

 

 

b. Use as URI (this expression is used to retrieve the file id portion of the link, a guid of 36 characters)

 

 

 

_api/web/GetFileById('@{substring(item()['link'], add(indexOf(item()['link'], 'sourcedoc=%7B'), 13), 36)}')?$select=ServerRelativeUrl

 

 

 

c. Use as Headers

 

 

 

{
  "Accept": "application/json;odata=nometadata",
  "Content-Type": "application/json;odata=nometadata"
}

 

 

 

 

2. Use a Get File Content using Path instead of a Get File Content

a. Use as Site Address

 

 

 

join(take(split(item()['link'], '/'), 5), '/')

 

 

 

b. Use as File Path (this expression is used to retrieve the file path portion of the ServerRelativeUrl field)

 

 

 

concat('/',join(skip(split(outputs('Send_an_HTTP_request_to_SharePoint')?['body']['ServerRelativeUrl'], '/'), 3), '/'))

 

 

 

 

getattachments_form.png

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Hi @Expiscornovus . Thank you so much. I checked out your blog post also. However I am getting stuck on the first step.

  1. For the 1st action "Get response details" I am forced to envelope it in an "Apply to each" which looks different from your flow which has the "Apply to each" after the "Get response details".

  2. The "Send an HTTP request to Sharepoint" is set-up as per youur instructions (see pic) but returns a Test error:

    Unable to process template language expressions in action 'Send_an_HTTP_request_to_SharePoint' inputs at line '0' and column '0': 'The template language expression 'substring(item()['link'], add(indexOf(item()['link'], 'sourcedoc=%7B'), 13), 36)' cannot be evaluated because property 'link' doesn't exist, available properties are 'webhookId, eventType, resourceData, eventTime'. Please see https://aka.ms/logicexpressions for usage details.'.

  3. I have set-up the "Get file content using path" as instructed but the Test has not yet reached that action (due to "2" above).

  4. Assuming "2" can be fixed and "3" works what else will be needed to extract the content(?) of the 1 or more attachments from the Form Upload (in Sharepoint as it is a Group Form) before it is somehow attached to the Jira Issue which is created from the same Form Response further down the flow?

    Edit-your-flow-Power-Automate (2).png
GKlose
Frequent Visitor

Hi @Expiscornovus . I just noticed some strikethrough text which appears to be full "Upload" Get Form Response data for when 2 files are uploaded.

 

This was discovered as the currently flow has a Create Jira Issue and simply displays the "Upload" dynamic content in the Issue description (my workaround for now).

 

Could this be a cause of the error in "2" in the previous post?

 

Screenshot 2024-04-26 140000.png

Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @GKlose,


Because you are already using an apply to each you would need to add another apply to each for your upload question. In your setup it should look like the below.

 

nestedapplytoeach.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Hi @Expiscornovus . Thanks for the inout. I did try enveloping your bits into an additional "Apply to each 2" but I wasn't even able to Save the changes as I got this error: 

The template validation failed: 'The template action 'Apply_to_each_2' at line '1' and column '11028' is not valid: "The template function 'body' is not expected at this location.".'.

 

The json function is for the "Upload" question in the Form responses (see pics below). Is that right?

f7dbaa55-c400-42a2-a717-3aadfced8e44.png

Edit-your-flow-Power-Automate (8).png

Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @GKlose,

 

I see your expression uses the below format, the body function is not expected/allowed within the outputs function.

 

outputs(body())

 

 

Can you try the below format instead, just a outputs function with the body property?

 

json(outputs('Get_response_details')?['body/r3bedbbeaf55e4f07808d2896d933214b'])

 

 

or just a body without an outputs function

 

json(body('Get_response_details')?['r3bedbbeaf55e4f07808d2896d933214b'])

 

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


GKlose
Frequent Visitor

Hi @Expiscornovus . Thank you for your patience. I have tried both of those expressions and both enable me to save but now I am getting the same error 400 with both versions.

 

Have I got the HTTP Expressions correct (see highlighted in blue below) or am I supposed to add some dynamic content in there?

 

The Join expression:

join(take(split(item()['link'], '/'), 5), '/')
 

The Substring expression:

substring(item()['link'], add(indexOf(item()['link'], 'sourcedoc=%7B'), 13), 36)
 
GKlose_0-1714313670171.png

 

GKlose_1-1714313710465.png

 

Test HTTP action INPUT:

GKlose_2-1714313772155.png

 

Test HTTP action OUTPUT:

 

GKlose_3-1714313816727.png

 

 

Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @GKlose,

 

The value within the GetFileById method looks strange. Just had another look at your uploaded files.

 

The solution I shared earlier was tested with Office files. With those you would get Office Online embedded links in the question response.  I would have to reuse the link and reuse the GUID in a HTTP request to find the direct link of each file.

 

However, in your case images/png files are used and the link property already has the correct direct link. Which makes the setup a bit easier and you don't have to use the Send an HTTP request anymore.


Try the below instead

 

Site Address

join(take(split(item()['link'], '/'), 5), '/')

 

File Path 

join(skip(split(item()['link'], '/'), 5), '/')

 

images_uploads.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


GKlose
Frequent Visitor

Hki @Expiscornovus . Progress. The Get file content by path Action now passes the test but the Get file metadata Action fails. Do I still need it? Remember, the end game is going to uploading/attaching these files to a Jira Issue.

Inputs:

{
    "method": "get",
    "path": "/datasets/https%253A%252F%252Fsagov.sharepoint.com%252Fteams%252FmywaterProject/files/",
    "host": {
        "api": {
        },
        "connection": {
            "name": "/providers/Microsoft.PowerApps/apis/shared_sharepointonline/connections/shared-sharepointonl-41be202d-ddbf-474c-b188-c700becf6144"
        }
    },
    "authentication": {
        "scheme": "Key",
        "parameter": "*sanitized*",
        "type": "Raw"
    }
}
 
Outputs:
{
    "statusCode": 404,
    "headers": {
        "Access-Control-Allow-Methods": "GET, PUT, PATCH, DELETE, POST",
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Max-Age": "3600",
        "Access-Control-Expose-Headers": "*",
        "Date": "Tue, 30 Apr 2024 10:16:26 GMT",
        "Content-Length": "54",
        "Content-Type": "application/json"
    },
    "body": {
        "statusCode": 404,
        "message": "Resource not found"
    }
}
Expiscornovus
Most Valuable Professional
Most Valuable Professional

Hi @GKlose,

 

Like mentioned in one of my first replies, the Get File Content Using Path action is used instead of your Get File Metadata. So, you don't really need that action.



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #MicrosoftCopilotStudio content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


GKlose
Frequent Visitor

Hi @Expiscornovus . Got it. So I have now included the next step "Create Jira Issue" (via a Switch) inside of the same "Apply to each" as the "Get file content using path" Action and there were no errors.

 

But I am not sure what we have achieved as ultimately we want to attach the 1-3 uploaded files (in this case 2) from the Form (stored in Sharepoint) into Jira (stored in Jira).

 

When I compared the outputs of the current dynamic content of "Upload" field from the "Get response details" with the "Current content" dynamic content from "Get file content using path" I noticed that the content was in the same format (so not sure of the value in the extra step) and the "Content content" only contained 1 of the 2 uploaded links.

 

---"Upload" output---

 

[{"name":"Edit-your-flow-Power-Automate (9)anonymous 1.png","link":"https://xxx.sharepoint.com/teams/mywaterProject/Shared%20Documents/Apps/Microsoft%20Forms/xxx%20Serv...","id":"017G3RMS2OIEHWLKBP3BHJAORK5BYONBP4","type":null,"size":77850,"referenceId":"017G3RMSZZD7HXOI5QGZGJNVQMY23QOWIH","driveId":"b!Zs1iNri5kUmxF1r03HrbI1I0OTVzdL5KgVVqn1qBREvUWWNQstleQ4H8RPeLFG","status":1,"uploadSessionUrl":null},{"name":"Edit-your-flow-Power-Automate (8)_anonymous 1.png","link":"https://xxx.sharepoint.com/teams/mywaterProject/Shared%20Documents/Apps/Microsoft%20Forms/xxx%20Serv...anonymous%201.png","id":"017G3RMS6VMFGGFGPW5JH2SGDWE3OSAWVO","type":null,"size":54421,"referenceId":"017G3RMSZZD7HXOI5QGZGJNVQMY23QOWIH","driveId":"b!Zs1iNri5kUmxF1r03HrbI1I0OTVzdL5KgVVqn1qBREvUWWNQstleQ4H8R-PeLFG","status":1,"uploadSessionUrl":null}]

 

---"Current content" output---

 

{"name":"Edit-your-flow-Power-Automate (8)anonymous 1.png","link":"https://xxx.sharepoint.com/teams/mywaterProject/Shared%20Documents/Apps/Microsoft%20Forms/xxx%20Serv...","id":"017G3RMS6VMFGGFGPW5JH2SGDWE3OSAWVO","type":null,"size":54421,"referenceId":"017G3RMSZZD7HXOI5QGZGJNVQMY23QOWIH","driveId":"b!Zs1iNri5kUmxF1r03HrbI1I0OTVzdL5KgVVqn1qBREvUWWNQstleQ4H8R-PeLFG","status":1,"uploadSessionUrl":null}

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (5,291)