DAML HUb facing issues when DAZL code is calling outside apis
Hello Guys,
I am using the DAZL library to write a python bot and need to call and thirdparty api when the ledger is ready. In our company we set the proxy and call the third party api. It works for us. But we want to demo using the DAML Hub.
Here is the code snippet of the python code. I am replacing the api with a get to w3schools which is also facing the similar issue.
Can someone please help me?
import csv
import json
import logging
import os
from os.path import dirname, join
import dazl
import requests
from requests.structures import CaseInsensitiveDict
dazl.setup_default_logger(logging.INFO)
def main():
url = os.getenv('DAML_LEDGER_URL')
party = "ledger_id"
network = dazl.Network()
network.set_config(url=url)
client = network.aio_party(party)
def check_stuff():
# ADIA api should be called here
logging.info(f'A22222222222222222222222222222222')
x = requests.get('https://w3schools.com')#, proxies = proxies)
logging.info(x)
logging.info("A333333333333333333333333333333333")
return True
@client.ledger_ready()
def ensure_setup(event):
logging.info(f"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa checking here")
a = check_stuff()
logging.info("A44444444444444444444444444444444")
network.run_forever()
if __name__ == '__main__':
main()
Unfortunately we do not allow bots to communicate with the outside world for security reasons.
Please see this post for a more detailed explanation:
Hi Ivan, Welcome to the forums! When it comes to connecting to external sources, Daml Hub supports integrations. A standard integration will model the surface of a 3rd-party API through Daml contracts, which can then be acted upon on ledger. A good example of this is the Exberry integration, which is also used by the Marketplace app - https://github.com/digital-asset/daml-dit-integration-exberry The caveat here is that integrations can only be published by Digital Asset for security reasons. …
Following up on what @dtanabe and @Alex_Matson have both said, Bots in Daml Hub do not have access to the external network. This is intentional, and done for security reasons. What you’ll see when you attempt to run your bot is that the requests.get will fail because it cannot reach the outside world.
This leaves two options for meeting your requirement:
- Write an externally hosted service that uses an API already offered by Daml Hub to manage the external network calls.
- Write an ‘integration’ instead of a bot.
For the first option, Daml Hub already offers the HTTP JSON API for accessing data on a ledger. This lets externally hosted software authenticate using a JWT and issue requests for ledger data and issue commands to the ledger. I’ve linked to the hub documentation above, but the general structure of this approach would be to write a bot that would connect to the ledger using the JSON API and issue whatever requests are necessary to external systems. This would not be subject to the networking limitations above - the code issuing the network requests would not be hosted by Daml Hub.
The second option is to write an integration. Integrations are visible under the ‘browse integrations’ tab in Daml Hub, and can be deployed to a ledger for the purpose of connecting that ledger to external systems. Internally, Integrations are bots, but there’s a specific API they follow to interface with DAML Hub, and they need to be deployed by users with specific access. If this is the path you choose to follow, we can help, but in the meantime, here are a few links to show what an integration looks like in concrete terms.
We have an integration with the Coindesk API that shows how ledgers can issue web requests in response to ledger events and then store the data on ledger. This is a good illustration of the structure and patterns involved in writing a Daml Hub integration.

GitHub - digital-asset/daml-dit-integration-coindesk
Contribute to digital-asset/daml-dit-integration-coindesk development by creating an account on GitHub.
The code to issue the web request is here:
github.comdigital-asset/daml-dit-integration-coindesk/blob/7ce770124919f1297c226c4edbe845340d7b6321/src/core_int/integration_coindesk_price.py#L81
- events: 'IntegrationEvents'):
-
- # Request/Response style integration
-
- @events.ledger.contract_created('CoinDesk.PriceRequest:PriceRequest')
- async def on_contract_created(event):
- LOG.debug('Noticed new price request: %r', event)
-
- currencyCode = event.cdata['currencyCode']
-
- resp = await issue_coindesk_request(currencyCode)
-
- if resp['success']:
- return exercise(event.cid, 'PriceRequest_RespondSuccess', {
- 'updatedAt': resp['updatedAt'],
- 'rate': resp['rate']
- })
- else:
- return exercise(event.cid, 'PriceRequest_RespondFailure', {
- 'httpStatusCode': resp['httpStatusCode'],
- 'httpResponseBody': resp['httpResponseBody']
(You can see how it’s triggered by a ledger event.)
Integrations are also written with a specific framework, that’s a wrapper around Dazl.

GitHub - digital-asset/daml-dit-if
Contribute to digital-asset/daml-dit-if development by creating an account on GitHub.
The integration framework allows for health and status monitoring and manages the connection of the integration with Daml Hub itself.
There is also a build tool that makes it easy to build integrations and run them locally against a sandbox for testing.

GitHub - digital-asset/daml-dit-ddit
Contribute to digital-asset/daml-dit-ddit development by creating an account on GitHub.
The last two repositories have documentation in their readme that goes into more detail than I can in this post about how these pieces fit together. I’m also happy to field any other questions as well.