Forum Discussion

raym85's avatar
raym85
Advocate I
1 year ago
Solved

Issues with Fabric Connection REST API and On-Prem Connections

 

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="\"
)

  • 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.

11 Replies

  • what's the reason you want to create a new connection this way?  What is the error message?

  • 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

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    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.

    • raym85's avatar
      raym85
      Advocate I

      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? 

      • v-hashadapu's avatar
        v-hashadapu
        Community Support

        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.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    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.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    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.

  • v-hashadapu's avatar
    v-hashadapu
    Community Support

    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.

  • DEEP_ER's avatar
    DEEP_ER
    Regular Visitor

    Hi everyone i want to connect SAP hanadb with Fabric, but facing error while building connection.

  • I've been struggling for a few days trying to get this API to work. Creating connections with an on-premises gateway requires encrypting credentials, which is what I suspect is going wrong. I'm commenting here to bring the solution as soon as I have it.