# How to successfully create a contract using python request lib?

**URL:** <https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891>\
**Category:** App Development\
**Tags:** daml, json-api\
**Created:** [July 22, 2020, 3:18am UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891 "2020-07-22T03:18:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![KsarCapital](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/ksarcapital/32/644_2.png) [@KsarCapital](https://forum.canton.network/u/KsarCapital)\
**Post date:** [July 22, 2020, 3:18am UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/1 "2020-07-22T03:18:10Z")

</div>

Hello Damler’s  
my snadbox is runing against my ledger id  
my json api is also runing  
but when ever I run a python script to create a contract, the token was specified by authentication using JWT same ledger id used to start sandbox.  
under `ui/package.json` i have added `"proxy": "http://localhost:7575" `  
I am getting the following error:

```haskell
HTTP service responded: <Response [404]>
{'errors': ['HttpMethod(POST), uri: http://localhost:7575/command/create'], 'status': 404}

```

Please advise  
Thanks,

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [July 22, 2020, 4:14am UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/2 "2020-07-22T04:14:27Z")

</div>

Hi @KsarCapital, welcome to the forum!

The endpoint for creating new contracts is `/v1/create` not `/command/create` which seems to be what your code is using. You can find this and more information in the [docs](https://docs.daml.com/json-api/index.html#http-request).

Let us know if changing that fixes your issue!

---

<div class="post-metadata">

**Author:** ![andreolf](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/andreolf/32/491_2.png) [@andreolf](https://forum.canton.network/u/andreolf)\
**Post date:** [July 22, 2020, 7:02am UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/3 "2020-07-22T07:02:22Z")

</div>

Welcome to the forum @KsarCapital!

---

<div class="post-metadata">

**Author:** ![KsarCapital](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/ksarcapital/32/644_2.png) [@KsarCapital](https://forum.canton.network/u/KsarCapital)\
**Post date:** [July 22, 2020, 7:48pm UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/4 "2020-07-22T19:48:55Z")

</div>

I have got a different error:  
Cause: spray.json.DeserializationException: Expected JsString([:]:), got: {“entityName”:“Transfer”,“moduleName”:“Main”}’], ‘status’: 400}

Many thanks for the pointer @cocreature,

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [July 22, 2020, 11:02pm UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/5 "2020-07-22T23:02:10Z")

</div>

Hi @KsarCapital, if you look at the linked docs for the `/v1/create` request, you can see an example of the format for the request body

```haskell
 {
  "templateId": "Iou:Iou",
  "payload": {
    "issuer": "Alice",
    "owner": "Alice",
    "currency": "USD",
    "amount": "999.99",
    "observers": []
  }
}

```

There is no `entityName` and `moduleName` field. Instead there is a single `templateId` field with (optional package id, ) module and entity name separated by colons. Are you maybe working based on some old documentation that uses a different format?

---

<div class="post-metadata">

**Author:** ![KsarCapital](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/ksarcapital/32/644_2.png) [@KsarCapital](https://forum.canton.network/u/KsarCapital)\
**Post date:** [July 22, 2020, 11:50pm UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/6 "2020-07-22T23:50:37Z")

</div>

sdk-version: 1.3.0  
daml 1.2

---

<div class="post-metadata">

**Author:** ![KsarCapital](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/ksarcapital/32/644_2.png) [@KsarCapital](https://forum.canton.network/u/KsarCapital)\
**Post date:** [July 23, 2020, 12:08am UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/7 "2020-07-23T00:08:22Z")

</div>

Here is my request:

return requests.post(

```
f"{endpoint}/v1/create",

headers = tokenHeader,

json = {

  "templateId" : {

    "moduleName": "Main",

    "entityName": contractName

  },

  "meta" : {

    "ledgerEffectiveTime": epoch # Wall time unsupported on DABL

  },

  "argument": {

    "event": damlDict,

    "owner": singatoryParty,

    "obs": singatoryParty

  }

},

verify=False

```

)

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [July 23, 2020, 6:43am UTC](https://forum.canton.network/t/how-to-successfully-create-a-contract-using-python-request-lib/891/8 "2020-07-23T06:43:10Z")

</div>

If you compare the JSON response body in your code to the one in the docs, there are 3 differences:

1. `templateId` should be a single string with module name and entity name separate by `:`.
2. You don’t need to set anything in `meta`.
3. `argument` is called `payload`.

If you change those things in your example, you get

```haskell
{
  "templateId" : "Main:{}".format(contractName),
  "payload": {
    "event": damlDict,
    "owner": singatoryParty,
    "obs": singatoryParty

  }
}

```

which should hopefully do the trick.

Could you share where you got the format in your code from? This used to be the syntax a few months ago (way before SDK 1.0.0) but there might still be some documentation that we need to update.
