# How to add external API call within a template

**URL:** <https://forum.canton.network/t/how-to-add-external-api-call-within-a-template/3019>\
**Category:** App Development\
**Created:** [August 20, 2021, 12:42pm UTC](https://forum.canton.network/t/how-to-add-external-api-call-within-a-template/3019 "2021-08-20T12:42:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![seardes](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/seardes/32/2390_2.png) [@seardes](https://forum.canton.network/u/seardes)\
**Post date:** [August 20, 2021, 12:42pm UTC](https://forum.canton.network/t/how-to-add-external-api-call-within-a-template/3019/1 "2021-08-20T12:42:04Z")

</div>

Dear DAML community,

I am very new to DAML and am trying to understand if it is possible to add a call to an external API within a template?  
after quite a bit of searching I couldn’t find any similar query that might help me understand if it is possible or no.

An example use case would be a call to an external authentication API within a template ‘UserAuth’

```haskell
type UAuthID = ContractId UserAuth

template UserAuth 
    with
        user : Party
        backend : Party
        token : Text
    where 
        signatory backend
        observer user

        controller backend can
            Authenticate : UAuthID
                with
                    newToken : Text
                do
                    -- need to call an external API here to validate token.
                    create this with
                        token = newToken

```

I wanted to know if this kind of action is possible or not.  
Thank you in advance!

---

<div class="post-metadata">

**Author:** ![bernhard](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/bernhard/32/356_2.png) [@bernhard](https://forum.canton.network/u/bernhard)\
**Post date:** [August 20, 2021, 1:28pm UTC](https://forum.canton.network/t/how-to-add-external-api-call-within-a-template/3019/2 "2021-08-20T13:28:47Z")

</div>

Hi @seardes , welcome to the Daml forums.

It is not possible to make any external calls from Daml templates. Imagine Daml templates as the schema for a multi-party system in that it tries to capture what happens _on_ the ledger, not on the outside world. It covers the data schema (in the `with` clause), permissions (in the `signatory`, `observer`, and `controller` clauses), and data transformations/processes (in the `do` clause).

The transformations/processes are triggered by external stimuli - someone calling the Daml Ledger API. And they result in transactions, which can be streamed and transformed into external actions by integrations. It’s really a [CRQS model](https://martinfowler.com/bliki/CQRS.html).

So if you need input from an external system, whatever calls the Daml Ledger API needs to supply those inputs. If you want to trigger an external system as the result of an on-ledger event, you need to write an integration that listens for that event and calls the external system.

---

<div class="post-metadata">

**Author:** ![seardes](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/seardes/32/2390_2.png) [@seardes](https://forum.canton.network/u/seardes)\
**Post date:** [August 20, 2021, 2:07pm UTC](https://forum.canton.network/t/how-to-add-external-api-call-within-a-template/3019/3 "2021-08-20T14:07:08Z")

</div>

Hi @bernhard,  
Thank you for your explanation, it cleared up a couple of things for me.  
It helped me understand the concept of DAML much better!
