Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredJoin us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered
Hi everyone,
I’ve been working with the Fabric Connection REST API (POST https://api.fabric.microsoft.com/v1/connections) and have run into challenges when trying to use it with an on-premises connection. So far, I haven’t been able to get it working, and the documentation doesn’t provide much clarity on whether this scenario is fully supported or if there are specific steps required to make it work.
Has anyone successfully used the API with an on-prem connection? If so, I’d love to hear about your experience and any insights you can share. Additionally, I think the documentation for this API could be more detailed, especially around on-prem support, to help avoid confusion and unnecessary troubleshooting.
Any help or guidance would be greatly appreciated!
Thanks!
import requests
import json
from notebookutils import mssparkutils
# Function to create a connection and return the connection ID
def create_connection(display_name, server_name, database_name, username, password, gateway_id):
# Define headers
headers = {
"Authorization": "Bearer " + mssparkutils.credentials.getToken('pbi'),
"Content-Type": "application/json"
}
url = "https://api.fabric.microsoft.com/v1/connections"
payload_onprem_sql = {
"connectivityType": "OnPremisesGateway",
"gatewayId": gateway_id,
"displayName": display_name,
"connectionDetails": {
"type": "SQL",
"creationMethod": "SQL",
#"path": f"{server_name};{database_name}",
"parameters": [
{ "dataType": "Text",
"name": "server",
"value": server_name
},
{ "dataType": "Text",
"name": "database",
"value": database_name
}
]
},
"privacyLevel": "Organizational",
"credentialDetails": {
"singleSignOnType": "None",
"connectionEncryption": "Any",
"skipTestConnection": False,
"credentials": {
"credentialType": "Basic",
"username": username,
"password": password
},
}
}
print(f"\nPayload for creating connection (JSON format):\n{json.dumps(payload_onprem_sql, indent=4)}\n")
response = requests.post(url, headers=headers, json=payload_onprem_sql)
if response.status_code == 201:
print(f'Connection "{display_name}" was successfully created.')
return response.json().get('id')
else:
print(f"Failed to create connection. Status code: {response.status_code}")
print("Response:", response.text)
return None
print("\nTesting OnPrem SQL Connection:")
create_connection(
display_name="sqlconnonprem",
server_name=r"",
database_name="",
username="",
password="",
gateway_id="\"
)
Solved! Go to Solution.
Hi @raym85 , Thank you for reaching out to the Microsoft Community Forum.s
Based on the error message you’re receiving (400 - invalid input: the Values field is required) and the payload you shared, the problem likely stems from incorrect formatting of the connectionDetails.parameters section. In Fabric’s REST API, the parameters field typically requires a values property, which should contain an array of parameter values. The API might expect the SQL connection string in a specific format rather than individual server and database parameters.
Fabric REST APIs - Create Connection
If this helped solve the issue, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.
Hi everyone i want to connect SAP hanadb with Fabric, but facing error while building connection.
Hi @raym85 , Please let us know if your issue is solved. If it is, consider marking the answers that helped 'Accept as Solution', so others with similar queries can find them easily. If not, please share the details.
Thank you.
Hi @raym85 , Please let us know if your issue is solved. If it is, consider marking the answers that helped 'Accept as Solution', so others with similar queries can find them easily. If not, please share the details.
Thank you.
Hi @raym85 , Please let us know if your issue is solved. If it is, consider marking the answers that helped 'Accept as Solution', so others with similar queries can find them easily. If not, please share the details.
Thank you.
Hi @raym85 , Thank you for reaching out to the Microsoft Community Forum.s
Based on the error message you’re receiving (400 - invalid input: the Values field is required) and the payload you shared, the problem likely stems from incorrect formatting of the connectionDetails.parameters section. In Fabric’s REST API, the parameters field typically requires a values property, which should contain an array of parameter values. The API might expect the SQL connection string in a specific format rather than individual server and database parameters.
Fabric REST APIs - Create Connection
If this helped solve the issue, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.
No the example in the documentation does not give a sample to show what the payload should look like. Can you show me what it should look like?
Hi , Thank you for reaching out to the Microsoft Community Forum.
You’re right, the docs at Create Connection show cloud and VNet examples but don’t give a sample for an on-premises SQL connection. I just mentioned the documentation for reference. Please try below:
{
"connectivityType": "OnPremisesGateway",
"gatewayId": "your-gateway-id-here",
"displayName": "sqlconnonprem",
"connectionDetails": {
"type": "SQL",
"creationMethod": "SQL",
"parameters": [
{ "dataType": "Text", "name": "server", "value": "your_server_name" },
{ "dataType": "Text", "name": "database", "value": "your_database_name" }
]
},
"privacyLevel": "Organizational",
"credentialDetails": {
"singleSignOnType": "None",
"connectionEncryption": "Any",
"skipTestConnection": false,
"credentials": {
"credentialType": "Basic",
"username": "your_username",
"password": "your_password"
}
}
}
If this helped solve the issue, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.
client is looking to automate the connections that need to be created, the error is mainly a 400 saying invalid input the Values field is required. but no matter how i changed the payload nothing seemed to work
If you have a Pro license you can open a Pro ticket at https://admin.powerplatform.microsoft.com/newsupportticket/powerbi
Otherwise you can raise an issue at https://community.fabric.microsoft.com/t5/Issues/idb-p/Issues .
what's the reason you want to create a new connection this way? What is the error message?
User | Count |
---|---|
13 | |
4 | |
3 | |
3 | |
3 |
User | Count |
---|---|
8 | |
8 | |
7 | |
6 | |
5 |