Last active
June 9, 2025 20:55
-
-
Save MarkPryceMaherMSFT/e55a12c4955e624aeb3b33b183c356e9 to your computer and use it in GitHub Desktop.
Example code using the new fabric rest api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import notebookutils | |
| import sempy.fabric as fabric | |
| from sempy.fabric.exceptions import FabricHTTPException, WorkspaceNotFoundException | |
| def pad_or_truncate_string(input_string, length, pad_char=' '): | |
| # Truncate if the string is longer than the specified length | |
| if len(input_string) > length: | |
| return input_string[:length] | |
| # Pad if the string is shorter than the specified length | |
| return input_string.ljust(length, pad_char) | |
| def display_return(data): | |
| table_details = [ | |
| { | |
| 'tableName': table['tableName'], | |
| 'status': table['status'], | |
| 'startDateTime': table['startDateTime'], | |
| 'endDateTime': table['endDateTime'], | |
| 'lastSuccessfulSyncDateTime': table['lastSuccessfulSyncDateTime'], | |
| 'error': table['error'] | |
| } | |
| for table in data | |
| ] | |
| for detail in table_details: | |
| print(f"Table: {pad_or_truncate_string(detail['tableName'],20)} status: {detail['status']} start: {detail['startDateTime']} end: {detail['endDateTime']} Last Update: {detail['lastSuccessfulSyncDateTime']} error: {detail['error']} ") | |
| print('') | |
| #print(data) | |
| return; | |
| workspace_id=spark.conf.get("trident.workspace.id") | |
| lakehouse_id=spark.conf.get("trident.lakehouse.id") | |
| #Instantiate the client | |
| client = fabric.FabricRestClient() | |
| # This is the SQL endpoint I want to sync with the lakehouse, this needs to be the GUI | |
| sqlendpoint = fabric.FabricRestClient().get(f"/v1/workspaces/{workspace_id}/lakehouses/{lakehouse_id}").json()['properties']['sqlEndpointProperties']['id'] | |
| # URI for the call | |
| uri = f"v1/workspaces/{workspace_id}/sqlEndpoints/{sqlendpoint}/refreshMetadata?preview=true" | |
| # This is the action, we want to take | |
| payload = {} | |
| # Example of setting a timeout | |
| payload = { "timeout": {"timeUnit": "Seconds", "value": "60"} } | |
| try: | |
| response = client.post(uri,json= payload, lro_wait = True) | |
| sync_status = json.loads(response.text) | |
| display_return(sync_status) | |
| except Exception as e: print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment