Tag: learn dynamics 365

Power Automate Import Failure: ‘GetTable’ failed with status code ‘Unauthorized’

‘GetTable’ failed with status code ‘Unauthorized’

Recently, one of our business users had left the firm, and handed over the canvas apps he was developing to his colleagues. There was one canvas app with flows that update SharePoint list. He had shared the app .zip file with the team and told, it’s a completed app and just needs to import to the target environment after creating the SharePoint list. So, the team didn’t bother much to collect further details about the source tenant where this was developed. He had created the app on a trail tenant which was tied with his account and was lost as soon as he left the firm.

But, the business users were unable to import the app and came to us with the below error.

Flow save failed with code
'DynamicOperationRequestClientFailure' and message
'The dynamic operation request to API 'sharepointonline' operation 'GetTable' failed with status code 'Unauthorized'. 
This may indicate invalid input parameters.
Error response: { "error_description": "Exception of type 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown." }'.

The Issue

The issue here was the SharePoint site dependency. The definition.js files of the Power Automate flows had references to the old site and the current user does not have access to the original site, hence the flow was failing with error ‘Unauthorized’ even though, SharePoint connection was created in the target environment.

The Fix

The fix was to edit the definition.js file and replace the SharePoint URL and List ID with the new site information. The definition.js file is in the exported zip file. We had to replace all the occurrence of the URL, list ID (defined under table) and view ID, and saved the definition.js file and copied it to the zip file. Importing the updated zip file worked.

{"dataset":"https://***.sharepoint.com/","table":"d2**826-e05a-4972-be****8","view":"**-27f2-4ace-a289-ef41a**"}

The Right Way

This is a known issue when moving PowerApps/ Power Automate to a new tenant. This behaviour is not consistent as some flows were imported with no errors and others were rejected due to Unauthorized exception on GetTable().

One way to avoid this issue, is to use variables instead of directly selecting the SharePoint site, list and view in the SharePoint actions inside your flow.

Another option is to use environment variables in your flow. This will also help us avoid direct SharePoint references in your flow.

Hope this helps.

If you know any alternate option to handle this, please let us know in the comments.

Do you want to be a Dynamics 365/Power Platform expert? then docs.microsoft.com is the Key.

When my colleagues are stuck on something, I always encourage them to do their best in Google search and then ask for help in the respective tech community, because good research is always important to nurture knowledge. But having said that, I always ensure that they check the Microsoft docs, if they haven’t, I suggest them to look into docs.microsoft.com.

Googling is a mandatory skill. BUT

Most developers start their career at the same pace and depend on random Google Searches. Even I started my career with a trust in blogs and communities. The blogs and videos are always helpful to make you understand the topics easily, but when you need deep technical knowledge, official documents or SDK documentation is the best source. These documents let you know the capabilities and limitations of the platform you work on.

Let’s take an example, if you are stuck at some point while using Power Apps Functions or D365APIs, what will you generally do? You might search it randomly and copy/paste the available piece of code (like we all do).

Can you imagine what can happen later to the system?

Is the code you copied supported by Microsoft?

Is it the optimal solution for your system and users?

SDK documentation is the answer to all these questions. It is your responsibility to ensure that you are not doing any unsupported customization.

We all know that the official documents are helpful but, do you know why people are not looking into these documents while working on something? It’s because we are all lazy…. These documents contain a broad range of technical information and are not as simple and easy to understand as individual blogs. But for technical knowledge and long-term future in D365 and Power Apps, it is advisable not to go with easy solutions. Reading through the official documents will definitely pay back your efforts. Once you start reading these documents and comprehend the topics, they become your true consultant.

In the start of our career, people may be short on time or lazy to check and read the SDK Documents. It wasn’t different for me either. But back in those days, I came across the blog of Ben Hosk and one of his statements struck me so hard “The CRM SDK can be stubborn, difficult, and renowned for not suffering fools gladly.” Reading this was the time when I decided to look into the Microsoft Documents along with the solutions from other Blogs and Videos available.

Now, referring the official documents for solution has more or less turned into a practice for me. If time does not permit to go through the documents, I would rather expand the deadline rather than compromise on the authenticity and quality of the solution. Moreover, I try to cover the topics during the weekend and learn something new from the official Microsoft Documents. So, if you are not familiar with these documents or fail to refer them even after knowing its benefits, it’s definitely a loss of opportunity to learn new things while at work. 

So, you should never bypass “learning something new with every customization you do”!!!!