Invalid data type – The data type passed to the action does not match the expected type

Loading

In Power Automate, each action expects data in a specific data type (e.g., text, number, boolean, array, or object). If an action receives data in the wrong format, it may fail with the following error:

“Invalid data type – The data type passed to the action does not match the expected type.”

This issue commonly arises when working with dynamic content, variables, or API responses that return unexpected formats.


2. Causes of “Invalid Data Type” Error

Several factors can trigger this error:

  1. Mismatched Data Type – The action expects a number but receives a string (e.g., "123" instead of 123).
  2. Null or Empty Values – The action requires a value, but the field is empty or null.
  3. Incorrect JSON Parsing – A JSON object or array is incorrectly formatted or not parsed before use.
  4. Unexpected API Response Format – The response data is in a different format than expected.
  5. Dynamic Content Issues – A previous step outputs the wrong type, such as a boolean instead of text.
  6. Array vs. Single Value Mismatch – An action expects a single item but receives an array.
  7. Expression or Variable Type Issues – Power Automate functions return an unexpected type.
  8. Inconsistent Formatting in Excel/SharePoint – Data types differ between source and destination.

3. Step-by-Step Troubleshooting Guide

Step 1: Identify the Failing Action

  1. Open Power Automate (https://flow.microsoft.com).
  2. Go to My Flows and select the affected flow.
  3. Click Run History and locate the failed run.
  4. Expand the failed action and review the Inputs and Outputs sections.

Solution:

  • Look at what data type was expected vs. what was actually received.

Step 2: Check Data Type in Dynamic Content

Power Automate actions often rely on dynamic content from previous steps. If an action fails due to a type mismatch, the input field may contain unexpected data.

Solution:

  1. In the failed action, check the Inputs section.
  2. If the data type looks incorrect, go back to the step where the data originates.
  3. Use the “Compose” action before the failing step to inspect the actual value.

Example:

  • If a field expects a number but receives "45" (a string), convert it using int().

Step 3: Convert Data Type Using Expressions

If an action expects a specific data type, use Power Automate expressions to convert it.

Common Conversions:

Expected TypeExpression
String → Numberint(variables('yourVariable'))
Number → Stringstring(variables('yourVariable'))
Boolean → Stringif(variables('yourVariable'), 'true', 'false')
Date → StringformatDateTime(utcNow(), 'yyyy-MM-dd')
String → DateparseDateTime('2024-03-09', 'yyyy-MM-dd')
Array → Stringjoin(variables('yourArray'), ', ')

Example:

  • If an API returns "100" (as a string) but a number is required, convert it using: plaintextCopyEditint(outputs('PreviousStep')?['body/value'])

Step 4: Handle Null or Empty Values

If a required field is missing, the action might fail due to a null value.

Solution:

  • Use coalesce() to provide a default value: coalesce(variables('yourVariable'), 0)

Example:

  • If a SharePoint field is empty, the flow might break. Use coalesce() to replace null with a default value.

Step 5: Validate JSON Parsing

If working with JSON data, ensure the structure matches what the action expects.

Solution:

  • Use “Parse JSON” to validate the structure before using the data.
  • If the action expects a single value but receives an array, extract the first value using: outputs('Parse_JSON')?['body'][0]

Example:

  • If an API returns: { "users": [ { "name": "Alice" }, { "name": "Bob" } ] } But the flow expects just one user, use: plaintextCopyEditoutputs('Parse_JSON')?['body']['users'][0]['name']

Step 6: Check API Responses for Unexpected Formats

Sometimes APIs return unexpected data types.

Solution:

  • Use “Compose” to inspect API responses before using them.
  • If an API returns "null" instead of {}, handle it with coalesce().

Example:

  • If an API sometimes returns {"value": null}, ensure your flow checks for null before processing.

Step 7: Fix Array vs. Single Value Issues

Some actions expect a single value but receive an array instead.

Solution:

  • Use first() to extract the first item: plaintextCopyEditfirst(outputs('PreviousStep')?['body'])
  • If the action expects an array, ensure the input is wrapped in square brackets [ ].

Example:

  • If an action expects "email": "user@example.com" but receives "email": ["user@example.com"], use: plaintextCopyEditfirst(outputs('PreviousStep')?['body']['email'])

Step 8: Ensure Excel/SharePoint Column Types Match

If working with Excel, SharePoint, or Dataverse, column types must match the expected format.

Solution:

  1. Open the data source (Excel, SharePoint, etc.).
  2. Check the column type (e.g., Text, Number, Date).
  3. Ensure that Power Automate sends data in the correct format.

Example:

  • If a SharePoint “Number” column receives "123" (string), convert it using: plaintextCopyEditint(variables('YourVariable'))

4. Preventative Measures

To prevent “Invalid Data Type” errors in the future:

Always inspect dynamic content before using it in actions.
Use the “Compose” action to check variable contents before processing.
Ensure JSON data is properly parsed before extracting values.
Use Power Automate expressions to convert data types where needed.
Check API responses for unexpected formats before using them.
Validate SharePoint, Excel, and Dataverse column types before sending data.

Leave a Reply

Your email address will not be published. Required fields are marked *