I have REST API endpoint that can't work without query parameters (for example mydoman.com/api?search=something). If you just call base URL (mydoman.com/api), it will throw 400 Bad Request error.
This API can't be added as Web data source on Power BI Services portal, because it will try to validate only base URL, without parameters. As base URL returns 400 Bad Request error, Power BI Services will think it's not valid.
From MS support for more details.
Root cause: Gateway Limitation. – it validates only the base URL when you configure it. There is no options under gateway to pass Query parameters and Header parameters.
The problem is that when a published dataset is refreshed Configure under gateway, Power BI does some static analysis on the code to determine what the data sources for the dataset are and whether the supplied credentials are correct. Unfortunately in some cases, such as when the definition of a data source depends on the parameters from a custom M function, that static analysis fails and therefore the dataset does not refresh and Failed to add under gateway.