Categories: Azure

Logic App errors out when using variables in a SharePoint Action

I have a Logic App that reads out a SharePoint library and stores all the documents found into Azure Blob Storage (ADF only supports Lists). I was trying to make this Logic App “generic”, meaning I could change the source folder and the destination container by using variables. That way, I have one single Logic App which can read out any SharePoint library, instead of creating a new Logic App for each library.

So I adapted my HTTP trigger to accept a JSON payload, which contains the name of the folder on SharePoint and the name of the blob container.

Inside my SharePoint activity “List Folder”, I use the variable “sourcefolder” from my HTTP request body.

However, when I run the Logic App, I get the error “The resource you are looking for has been removed, had its name changed, or is temporarily unavailable”.

The activity itself will error out with “NotFound”, but when you check the output you’ll see the actual error message. There’s also a very helpful “The response is not in a JSON format”. I’m pretty sure the SharePoint folder does exist and there are documents in it, so the problem is actually something else. After some trial and error, I went to the code view and found the following JSON for the activity:

"List_folder": {
	"inputs": {
		"host": {
			"connection": {
				"name": "@parameters('$connections')['sharepointonline']['connectionId']"
			}
		},
		"method": "get",
		"path": "/datasets/@{encodeURIComponent(encodeURIComponent('https://mysharepoint.sharepoint.com/sites/mysite'))}/folders/@{encodeURIComponent(triggerBody()?['sourcefolder'])}"
	},

I noticed the website had twice the function encodeURIComponent, but the folder only once. So I added another encodeURIComponent around the first one:

.../folders/@{encodeURIComponent(encodeURIComponent(triggerBody()?['sourcefolder']))}"

And lo and behold, the Logic App ran without issues.

The annoying part is that you don’t actually see that the code was modified, the designer will still show the variable exactly as in the second screenshot.


------------------------------------------------
Do you like this blog post? You can thank me by buying me a beer 🙂
Koen Verbeeck

Koen Verbeeck is a Microsoft Business Intelligence consultant at AE, helping clients to get insight in their data. Koen has a comprehensive knowledge of the SQL Server BI stack, with a particular love for Integration Services. He's also a speaker at various conferences.

Recent Posts

Free webinar – Tackling the Gaps and Islands Problem with T-SQL Window Functions

I'm hosting a free webinar at MSSQLTips.com at the 19th of December 2024, 6PM UTC.…

5 days ago

dataMinds Connect 2024 – Session Materials

The slides and scripts for my session "Tackling the Gaps & Islands Problem with T-SQL…

4 weeks ago

Connect to Power BI as a Guest User in another Tenant

Sometimes your Microsoft Entra ID account (formerly known as Azure Active Directory) is added as…

2 months ago

How to use a Script Activity in ADF as a Lookup

In Azure Data Factory (ADF, but also Synapse Pipelines and Fabric Pipelines), you have a…

4 months ago

Database Build Error – Incorrect syntax near DISTINCT

I wrote a piece of SQL that had some new T-SQL syntax in it: IS…

4 months ago

Speaking at dataMinds Connect 2024

I'm very excited to announce I've been selected as a speaker for dataMinds Connect 2024,…

5 months ago