# 小白问题，为啥是红色的呀？

**URL:** <https://forum.canton.network/t/topic/3561>\
**Category:** App Development\
**Tags:** daml, sandbox, daml-sdk\
**Created:** [December 13, 2021, 12:23am UTC](https://forum.canton.network/t/topic/3561 "2021-12-13T00:23:19Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 13, 2021, 12:23am UTC](https://forum.canton.network/t/topic/3561/1 "2021-12-13T00:23:19Z")

</div>

![image](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/f/f8d49c1e98fe3e4943623988e8980742b005deb1.png)

---

<div class="post-metadata">

**Author:** ![SteveSeow](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/steveseow/32/2785_2.png) [@SteveSeow](https://forum.canton.network/u/SteveSeow)\
**Post date:** [December 13, 2021, 8:10am UTC](https://forum.canton.network/t/topic/3561/2 "2021-12-13T08:10:05Z")

</div>

我正在使用翻译帮助我用中文回答你。请原谅任何错误。

您是否在上面定义了 “Coin” 或包含 “template”  
定义了“Coin”？

---

<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:** [December 13, 2021, 8:35am UTC](https://forum.canton.network/t/topic/3561/3 "2021-12-13T08:35:41Z")

</div>

Hi @yuan_yan , please try to post your questions in English, we don’t have many native speakers of Mandarin on this forum.

To really diagnose your issue, you’d have to post the error message that you get when hovering over the `Coin` keywords. It may simply be that you have not yet defined a template `Coin`.

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 13, 2021, 8:40am UTC](https://forum.canton.network/t/topic/3561/4 "2021-12-13T08:40:34Z")

</div>

非常感谢您的回复，可以给我一个你的网络联系方式吗？实时的那种，我看你的文档也是翻译软件，我现在想学习，但是英文的确实理解不了。希望你能在线帮我看一下。

Steve Seow via Daml Developers Community \<[daml@discoursemail.com](mailto:daml@discoursemail.com)\> 于2021年12月13日周一 16:25写道：

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 13, 2021, 10:02am UTC](https://forum.canton.network/t/topic/3561/5 "2021-12-13T10:02:23Z")

</div>

I need to learn from you the calling method of JSON API. Can you give me an example? Format write one

Bernhard via Daml Developers Community \<[daml@discoursemail.com](mailto:daml@discoursemail.com)\> 于2021年12月13日周一 16:50写道：

---

<div class="post-metadata">

**Author:** ![SteveSeow](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/steveseow/32/2785_2.png) [@SteveSeow](https://forum.canton.network/u/SteveSeow)\
**Post date:** [December 13, 2021, 12:28pm UTC](https://forum.canton.network/t/topic/3561/6 "2021-12-13T12:28:02Z")

</div>

I recently created a learning series on YouTube. Take a look at this episode and see if it helps: [Daml 101: BYOF: Bring Your Own Frontend with JSON API [2021] - YouTube](https://youtu.be/9e-J1yi-Ej0)

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 13, 2021, 2:16pm UTC](https://forum.canton.network/t/topic/3561/7 "2021-12-13T14:16:30Z")

</div>

I still don’t quite understand your tutorial. Can you help me write a real example? It’s best to annotate.

Steve Seow via Daml Developers Community \<[daml@discoursemail.com](mailto:daml@discoursemail.com)\> 于2021年12月13日周一 20:43写道：

---

<div class="post-metadata">

**Author:** ![nemanja](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nemanja/32/842_2.png) [@nemanja](https://forum.canton.network/u/nemanja)\
**Post date:** [December 14, 2021, 9:15am UTC](https://forum.canton.network/t/topic/3561/8 "2021-12-14T09:15:02Z")

</div>

Hi @yuan_yan and welcome to the Daml Developer forum!

Full docs for the JSON API can be found [here](https://docs.daml.com/json-api/index.html) where you can see how to form requests and what the responses look like.

This browser-based [interactive tutorial](https://daml.com/learn/getting-started/your-first-feature) shows how you can add a UI feature with React that ends up calling the JSON API (as part of our frontend library).

Hope this helps 😀 🙏

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 14, 2021, 12:46pm UTC](https://forum.canton.network/t/topic/3561/9 "2021-12-14T12:46:53Z")

</div>

![image.png](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/6/6c294e6855dd60af8a256fdf0932b9381e26955f.png)

Why is it prompted that the service cannot be found

Nemanja via Daml Developers Community \<[daml@discoursemail.com](mailto:daml@discoursemail.com)\> 于2021年12月14日周二 17:30写道：

---

<div class="post-metadata">

**Author:** ![nemanja](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nemanja/32/842_2.png) [@nemanja](https://forum.canton.network/u/nemanja)\
**Post date:** [December 14, 2021, 12:51pm UTC](https://forum.canton.network/t/topic/3561/10 "2021-12-14T12:51:10Z")

</div>

Change the url to `url = 'http://127.0.0.1:7575/v1/create'`

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 14, 2021, 12:54pm UTC](https://forum.canton.network/t/topic/3561/11 "2021-12-14T12:54:35Z")

</div>

> [@nemanja](#):
>
> [http://127.0.0.1:757/v1/create](http://127.0.0.1:757/v1/create)

```haskell
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=757): Max retries exceeded with url: /v1/create/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001F932B284C0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝，无法连接。'))
type or paste code here

```

---

<div class="post-metadata">

**Author:** ![nemanja](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nemanja/32/842_2.png) [@nemanja](https://forum.canton.network/u/nemanja)\
**Post date:** [December 14, 2021, 12:58pm UTC](https://forum.canton.network/t/topic/3561/12 "2021-12-14T12:58:21Z")

</div>

yes, I had the wrong port number

so the url is `url = http://127.0.0.1:7575/v1/create`

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 14, 2021, 1:01pm UTC](https://forum.canton.network/t/topic/3561/13 "2021-12-14T13:01:24Z")

</div>

![image.png](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/b/bdabbe94f5d0ddfd221e726730e9fe9545720e14.png)

Where is the authorization set?

yuan yan [yuan.yan@eigen.capital](mailto:yuan.yan@eigen.capital) 于2021年12月14日周二 20:46写道：

 ![image.png](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/6/6c294e6855dd60af8a256fdf0932b9381e26955f.png)

---

<div class="post-metadata">

**Author:** ![nemanja](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nemanja/32/842_2.png) [@nemanja](https://forum.canton.network/u/nemanja)\
**Post date:** [December 14, 2021, 1:11pm UTC](https://forum.canton.network/t/topic/3561/14 "2021-12-14T13:11:23Z")

</div>

Fo each request you need to set a bearer token. You can read more about it [here](https://docs.daml.com/json-api/index.html#access-tokens) and [here](https://docs.daml.com/app-dev/authorization.html#access-tokens-and-claims).

Might be easier to make an example JSON API call via [Postman](https://www.postman.com)

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 14, 2021, 1:25pm UTC](https://forum.canton.network/t/topic/3561/15 "2021-12-14T13:25:29Z")

</div>

![image.png](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/a/af9f6e09896f326281db95502e5fce36302e34a3.png)

Is this format right?

---

<div class="post-metadata">

**Author:** ![nemanja](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nemanja/32/842_2.png) [@nemanja](https://forum.canton.network/u/nemanja)\
**Post date:** [December 14, 2021, 1:56pm UTC](https://forum.canton.network/t/topic/3561/16 "2021-12-14T13:56:51Z")

</div>

It should have `Bearer` in it, so `Authorization: Bearer your_token` (see [here](https://docs.daml.com/json-api/index.html#auth-via-http))

---

<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:** [December 14, 2021, 2:01pm UTC](https://forum.canton.network/t/topic/3561/17 "2021-12-14T14:01:09Z")

</div>

You are missing the protocol in your url: `http://`.

---

<div class="post-metadata">

**Author:** ![yuan\_yan](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/yuan_yan/32/2908_2.png) [@yuan\_yan](https://forum.canton.network/u/yuan_yan)\
**Post date:** [December 15, 2021, 1:27am UTC](https://forum.canton.network/t/topic/3561/18 "2021-12-15T01:27:07Z")

</div>

![image.png](https://canada1.discourse-cdn.com/flex028/uploads/daml/original/2X/f/f14d00f401ce2ba84154c8489ccbda94d05f6637.png)

Is there a problem?

---

<div class="post-metadata">

**Author:** ![nemanja](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nemanja/32/842_2.png) [@nemanja](https://forum.canton.network/u/nemanja)\
**Post date:** [December 15, 2021, 7:28am UTC](https://forum.canton.network/t/topic/3561/19 "2021-12-15T07:28:46Z")

</div>

You’re receiving a [401 error](https://docs.daml.com/json-api/index.html#failure-http-status-400-401-404-500), meaning that authentication failed. I’m guessing that the access token doesn’t have the necessary [claims](https://docs.daml.com/app-dev/authorization.html#access-tokens-and-claims) in it.

---

<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:** [December 15, 2021, 9:57am UTC](https://forum.canton.network/t/topic/3561/20 "2021-12-15T09:57:00Z")

</div>

What is that `requests` library you are using? It seems odd to me that `requests.post` takes just two parameters for url and headers. A `POST` usually has data that you are posting, ie I’d expect to have to supply at least a url, data, and then optionally headers.  
The structure of a request to `create` using the standard `fetch` API would look like this:

```haskell
fetch("http://127.0.0.1:7575/v1/create", {
  "headers": {
    "authorization": "Bearer TOKEN",
    "content-type": "application/json",
  },
  "body": "{\"templateId\":\"TEMPLATEID\",\"payload\":PAYLOAD}",
  "method": "POST",
});

```

[Next page](https://forum.canton.network/t/topic/3561.md?page=2)
