# Api の記法について

**URL:** <https://forum.asana.com/t/api/47052>\
**Category:** 質問とアドバイス\
**Created:** [11 April 2019 11:21 UTC](https://forum.asana.com/t/api/47052 "2019-04-11T11:21:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![You1024](https://luna1.co/8d76cd.png) [@You1024](https://forum.asana.com/u/You1024)\
**Post date:** [11 April 2019 11:21 UTC](https://forum.asana.com/t/api/47052/1 "2019-04-11T11:21:05Z")

</div>

連携したいサービスの都合でAPIの記法を変えたいです。  
**–data-urlencode** ではなく、 **-d** を使ってjsonで記述したいのですが、  
対応してるでしょうか？

# OKな場合

```auto
curl -H "Authorization: Bearer 0/beebfahogeeb05adbc" \
https://app.asana.com/api/1.0/tasks \
--data-urlencode "name=Incident" \
--data-urlencode "notes=hoge" \
--data-urlencode "projects=111821772381982"

```

# ダメだったやつ１

```auto
curl -H '{"Authorization:" "Bearer 0/beebfahogeeb05adbc"}' \
https://app.asana.com/api/1.0/tasks \
-d '{"data": {"name": "Incident","notes": "hoge","projcet": "111821772381982"}}'

```

# ダメだったやつ２

```auto
curl -H '{"Authorization:" "Bearer 0/beebfahogeeb05adbc"}' \
https://app.asana.com/api/1.0/tasks \
-d '{"name": "Incident","notes": "hoge","projcet": "111821772381982"}'

```

# その時に発生したエラー

```auto
{"errors":[{"message":"Could not interpret {\"data\": {\"name\": \"Incident\",\"notes\": \"hoge\",\"projcet\": \"111828089080\"}} as an identifier in {\"data\": {\"name\": \"Incident\",\"notes\": \"hoge\",\"projcet\": \"111828089080\"}}.","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}%

```

---

<div class="post-metadata">

**Author:** ![ShunS](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/shuns/32/115053_2.png) [@ShunS](https://forum.asana.com/u/ShunS)\
**Post date:** [11 April 2019 13:01 UTC](https://forum.asana.com/t/api/47052/2 "2019-04-11T13:01:01Z")

</div>

@You1024 さん、コメントありがとうございます。  
[Build an app with Asana](https://asana.com/developers/documentation/getting-started/input-output-options) の JSON の例を参考にして、 `-H "Content-Type: application/json"` をつけるとうまくいきました。  
プロジェクトは複数の場合もあるので `projects` にする必要があるようです。  
以下が、私が試したコマンドです。私はアクセストークンを Mac の環境変数にして `$ASANA_ACCESS_TOKEN` で参照できるようにしています。

```
curl -H "Authorization: Bearer $ASANA_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
https://app.asana.com/api/1.0/tasks \
-d '{"data": {"name": "Incident","notes": "hoge","projects": "XXXXXXXXXXXXXX"}}'

```

例の中にアクセストークンが記載されていますが、短いのでおそらく完全なものではないですよね？  
トークンの機密性についてはすでにご存知だと思いますが、念の為ご確認です。

---

<div class="post-metadata">

**Author:** ![You1024](https://luna1.co/8d76cd.png) [@You1024](https://forum.asana.com/u/You1024)\
**Post date:** [12 April 2019 01:27 UTC](https://forum.asana.com/t/api/47052/3 "2019-04-12T01:27:35Z")

</div>

@ShunS

ご教示ありがとうございます。  
それで試してご連絡します。

また、Tokenは実際のものではありません。私が適当に記載したものです。  
ご注意ありがとうございます。
