# DAML HUb facing issues when DAZL code is calling outside apis

**URL:** <https://forum.canton.network/t/daml-hub-facing-issues-when-dazl-code-is-calling-outside-apis/3265>\
**Category:** App Development\
**Tags:** features and bugs, damlhub\
**Created:** [October 5, 2021, 3:52pm UTC](https://forum.canton.network/t/daml-hub-facing-issues-when-dazl-code-is-calling-outside-apis/3265 "2021-10-05T15:52:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aryan\_b](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@aryan\_b](https://forum.canton.network/u/aryan_b)\
**Post date:** [October 5, 2021, 3:52pm UTC](https://forum.canton.network/t/daml-hub-facing-issues-when-dazl-code-is-calling-outside-apis/3265/1 "2021-10-05T15:52:44Z")

</div>

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?

```haskell
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()

```

---

<div class="post-metadata">

**Author:** ![dtanabe](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/dtanabe/32/91_2.png) [@dtanabe](https://forum.canton.network/u/dtanabe)\
**Post date:** [October 5, 2021, 4:06pm UTC](https://forum.canton.network/t/daml-hub-facing-issues-when-dazl-code-is-calling-outside-apis/3265/2 "2021-10-05T16:06:42Z")

</div>

Unfortunately we do not allow bots to communicate with the outside world for security reasons.

Please see this post for a more detailed explanation:

> [@DA-Marketplace / External Integration](https://discuss.daml.com/t/da-marketplace-external-integration/3259/2):
>
> 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](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. …

---

<div class="post-metadata">

**Author:** ![Michael\_Schaeffer](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/michael_schaeffer/32/503_2.png) [@Michael\_Schaeffer](https://forum.canton.network/u/Michael_Schaeffer)\
**Post date:** [October 5, 2021, 6:19pm UTC](https://forum.canton.network/t/daml-hub-facing-issues-when-dazl-code-is-calling-outside-apis/3265/3 "2021-10-05T18:19:03Z")

</div>

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:

1. Write an externally hosted service that uses an API already offered by Daml Hub to manage the external network calls.
2. Write an ‘integration’ instead of a bot.

For the first option, Daml Hub already offers the [HTTP JSON](https://hub.daml.com/docs/api#tag/JSON-API) 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](https://github.com/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:

> <https://github.com/digital-asset/daml-dit-integration-coindesk/blob/7ce770124919f1297c226c4edbe845340d7b6321/src/core_int/integration_coindesk_price.py#L81>

(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](https://github.com/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](https://github.com/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.
