# Add an API to Create a Note

**URL:** <https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451>\
**Category:** Chapter Comments\
**Created:** [August 26, 2021, 1:09am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451 "2021-08-26T01:09:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 26, 2021, 1:09am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/1 "2021-08-26T01:09:37Z")

</div>

Link to chapter — [https://serverless-stack.com/chapters/add-an-api-to-create-a-note.html](https://serverless-stack.com/chapters/add-an-api-to-create-a-note.html)

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 30, 2021, 3:17am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/2 "2021-08-30T03:17:45Z")

</div>

![スクリーンショット 2021-08-30 11.37.47](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/2X/5/500ec184c618dd75a8a8e0845980b16dfe02d837.png)

When I test the API following the code, the response is `Failed to load resource: the server responded with a status of 404 ()`.

```auto
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"content":"Hello World","attachment":"hello.jpg"}' \
https://5bv7x0iuga.execute-api.us-east-1.amazonaws.com/notes

```

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 30, 2021, 3:52am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/3 "2021-08-30T03:52:36Z")

</div>

Are you using the URL from your API? The one in the screenshot is from the example we have in the chapter.

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 30, 2021, 4:26am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/4 "2021-08-30T04:26:47Z")

</div>

Yes. I use from my API.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 30, 2021, 5:58pm UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/5 "2021-08-30T17:58:18Z")

</div>

Hmm can you try running `sst start` again? It seems like maybe the route wasn’t deployed.

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 31, 2021, 12:40am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/6 "2021-08-31T00:40:14Z")

</div>

I do `npx sst start`. And the response is like this… 😢

```auto
HTTP/1.1 404 Not Found
Date: Tue, 31 Aug 2021 00:34:36 GMT
Content-Type: application/json
Content-Length: 23
Connection: close
apigw-requestid: E5_caiI2NjMEMUQ=

{
  "message": "Not Found"
}

```

Also I tried previous hello world too. And response was  
`Hello, World! Your request was received at 31/Aug/2021:00:59:44 +0000.`.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 31, 2021, 1:02am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/7 "2021-08-31T01:02:00Z")

</div>

Hmm can you share a GitHub repo with your app? I can take a look.

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 31, 2021, 1:05am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/8 "2021-08-31T01:05:18Z")

</div>

Thank you so much…!!

> **[GitHub - minna607842/demo-notes-app](https://github.com/minna607842/demo-notes-app)**
>
> Contribute to minna607842/demo-notes-app development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 31, 2021, 1:45am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/9 "2021-08-31T01:45:35Z")

</div>

Hmm you might’ve missed the **Adding to the App** step in the chapter? Your `lib/index.js` isn’t adding the `ApiStack`.

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 31, 2021, 1:57am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/10 "2021-08-31T01:57:14Z")

</div>

- index.js

```auto
import StorageStack from "./StorageStack";
import ApiStack from "./ApiStack";

export default function main(app) {
  const storageStack = new StorageStack(app, "storage");

  new ApiStack(app, "api", {
    table: storageStack.table,
  });
}

```

Hmm… I recreated iam user from another AWS account and tried again. But it’s still error:404. So I guess it’s not a problem of account.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 31, 2021, 2:19am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/11 "2021-08-31T02:19:01Z")

</div>

I tried your repo with the updated `lib/index.js` and it worked for me.

 ![Screen Shot 2021-08-30 at 10.18.20 PM](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/2X/4/466392c36b444b414b2230df9d35ebbba3225418.png)

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 31, 2021, 3:03am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/12 "2021-08-31T03:03:01Z")

</div>

I recreated note app. And hello world was statusCode: 200 in terminal like your terminal. But when I move to test the API with `curl -X POST \`, Again `{"message":"Not Found"}` and error: 404…

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 31, 2021, 7:11am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/13 "2021-08-31T07:11:38Z")

</div>

I deleted the file. And I pulled from the repository and fixed what you mentioned. But the hello world have 404 error and `{"message":"Not Found"}`.

```auto
Failed to load resource: the server responded with a status of 404 ()

```

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [August 31, 2021, 7:41am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/14 "2021-08-31T07:41:24Z")

</div>

I did `curl -X POST \ -v`. And the response:

```auto
* We are completely uploaded and fine
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 404 
< date: Tue, 31 Aug 2021 07:36:23 GMT
< content-type: application/json
< content-length: 23
< apigw-requestid: E69Oqg1wtjMEMBw=
< 
* Connection #0 to host p57ypgdxgf.execute-api.ap-northeast-1.amazonaws.com left intact
{"message":"Not Found"}* Closing connection 0

```

Also I took a loom. So it would be helpful, if you could check it out. 🙇‍♂️[Loom | Free Screen & Video Recording Software](https://www.loom.com/share/09b16602ed9c413f8b6adced7b9c9c61)

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [August 31, 2021, 8:30pm UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/15 "2021-08-31T20:30:16Z")

</div>

We remove the Hello World API in this chapter. So it shouldn’t work anymore.

But the URL in your Loom video is missing `/notes` at the end.

 ![Screen Shot 2021-08-31 at 4.29.28 PM](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/2X/4/48e7a7b478222ea1485a3b854b3f2270a096bd4b.png)

---

<div class="post-metadata">

**Author:** ![teru-mi](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/teru-mi/32/1211_2.png) [@teru-mi](https://discourse.sst.dev/u/teru-mi)\
**Post date:** [September 1, 2021, 1:17am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/16 "2021-09-01T01:17:30Z")

</div>

Ohh… `/notes` at the end. 🥶 I got it. Thank you so much 🙇‍♂️

---

<div class="post-metadata">

**Author:** ![wmbond](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/wmbond/32/1224_2.png) [@wmbond](https://discourse.sst.dev/u/wmbond)\
**Post date:** [September 8, 2021, 1:01am UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/18 "2021-09-08T01:01:48Z")

</div>

**If you’re running the following on the windows platform**

curl -X POST -H ‘Content-Type: application/json’ -d ‘{“content”:“Hello World”,“attachment”:“hello.jpg”}’ [https://yourendpoint.amazonaws.com/notes](https://yourendpoint.amazonaws.com/notes)

**And messages/errors are returned**

- Unnecessary use of -X or --request, POST is already inferred.
- Could not resolve host: application
- {“message”:“Internal Server Error”}

**Apply the following resolution**

- Optionally drop the -X POST switch
- Replace sgl-quotes w/ dbl-quotes
- Escape the dbl-quotes surrounding the NVPs inside the {JSON}

**Example**

curl -H “Content-Type: application/json” -d “{\“content\”:\“Hello World\”,\“attachment\”:\“hello.jpg\”}” [https://yourendpoint.amazonaws.com/notes](https://yourendpoint.amazonaws.com/notes)

_Just began the SST tutorial, encountered the above, and sharing for anyone new like me._

---

<div class="post-metadata">

**Author:** ![groffcole](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@groffcole](https://discourse.sst.dev/u/groffcole)\
**Post date:** [September 22, 2021, 12:43pm UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/19 "2021-09-22T12:43:50Z")

</div>

Since adding the storage and api stacks I have noticed the the “my-stack” stack is still hanging around. What’s the recommended way to manage these dangling stacks? I could go to the console and manually delete them I supposed, but that feels cumbersome.

---

<div class="post-metadata">

**Author:** ![jayair](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/jayair/32/9_2.png) [@jayair](https://discourse.sst.dev/u/jayair)\
**Post date:** [September 22, 2021, 6:47pm UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/20 "2021-09-22T18:47:28Z")

</div>

Hmm that’s not right. Can you try doing a full `npx sst deploy`?

---

<div class="post-metadata">

**Author:** ![groffcole](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@groffcole](https://discourse.sst.dev/u/groffcole)\
**Post date:** [September 29, 2021, 12:24pm UTC](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451/21 "2021-09-29T12:24:54Z")

</div>

I just ran `npx sst deploy` and am still seeing the “my-stack” stack. It’s possible I could’ve missed something while working through the beginning of the guide. These are the stacks I see in my console:

- dev-sst-notes-debug-stack
- dev-sst-notes-my-stack
- dev-sst-notes-storage
- dev-sst-notes-api

I would expect all but the `dev-sst-notes-my-stack` stack to exist.

What do you think?

* * *

Update:  
I also ran `npm sst deploy --stage prod` and am still seeing the `prod-sst-notes-my-stack` stack.

[Next page](https://discourse.sst.dev/t/add-an-api-to-create-a-note/2451.md?page=2)
