# Call the Create API

**URL:** <https://discourse.sst.dev/t/call-the-create-api/124>\
**Category:** Chapter Comments\
**Created:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124 "2018-05-09T19:42:50Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/21 "2018-05-09T19:42:57Z")

</div>

_From @ramonpm on Fri Aug 11 2017 13:53:03 GMT+0000 (UTC)_  
  
I’m having the same CORS problem here, and my serverless.yml is the same of this [https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/251d1defa682c70c7af770ba386b2069ef3eefda/serverless.yml#L42](https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/251d1defa682c70c7af770ba386b2069ef3eefda/serverless.yml#L42)

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/22 "2018-05-09T19:42:57Z")

</div>

_From @jayair on Fri Aug 11 2017 17:10:08 GMT+0000 (UTC)_  
  
@ramonpm Does calling the Create API directly work for you (like in this chapter - [http://serverless-stack.com/chapters/test-the-apis.html](http://serverless-stack.com/chapters/test-the-apis.html))?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/23 "2018-05-09T19:42:58Z")

</div>

_From @ramonpm on Fri Aug 11 2017 17:20:16 GMT+0000 (UTC)_  
  
Yes @jayair, it works for me when I call it directly.

2017-08-11 14:10 GMT-03:00 Jay V [notifications@github.com](mailto:notifications@github.com):

> @ramonpm [https://github.com/ramonpm](https://github.com/ramonpm) Does calling the Create API  
> directly work for you (like in this chapter - [http://serverless-stack.com/](http://serverless-stack.com/)  
> chapters/test-the-apis.html)?
> 
> —  
> You are receiving this because you were mentioned.  
> Reply to this email directly, view it on GitHub  
> [https://github.com/AnomalyInnovations/serverless-stack-com/issues/48#issuecomment-321868080](https://github.com/AnomalyInnovations/serverless-stack-com/issues/48#issuecomment-321868080),  
> or mute the thread  
> [https://github.com/notifications/unsubscribe-auth/AAM6dIIK9us52eK8h8HTwlNgsz-wI2jfks5sXIrxgaJpZM4M4OK7](https://github.com/notifications/unsubscribe-auth/AAM6dIIK9us52eK8h8HTwlNgsz-wI2jfks5sXIrxgaJpZM4M4OK7)  
> .

–  
Ramon de Paula Marques

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/24 "2018-05-09T19:42:58Z")

</div>

_From @jayair on Fri Aug 11 2017 17:25:14 GMT+0000 (UTC)_  
  
@ramonpm The other thing to check would be if you are returning the proper headers like so - [https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/libs/response-lib.js#L13](https://github.com/AnomalyInnovations/serverless-stack-demo-api/blob/master/libs/response-lib.js#L13).

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/25 "2018-05-09T19:42:58Z")

</div>

_From @ramonpm on Fri Aug 11 2017 17:28:07 GMT+0000 (UTC)_  
  
@jayair, thanks for your reply.  
Unfortunately my response-lib.js is exactly the same as well…

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/26 "2018-05-09T19:42:59Z")

</div>

_From @jayair on Sat Aug 12 2017 22:13:48 GMT+0000 (UTC)_  
  
@ramonpm Can I see a screenshot of the error that you are seeing in the browser console?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/27 "2018-05-09T19:42:59Z")

</div>

_From @jonsaw on Sun Aug 13 2017 13:27:01 GMT+0000 (UTC)_  
  
I’m having the same issue too. Screenshot attached:

 ![screen shot 2017-08-13 at 21 23 53](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/92ca3ce80cf1d149b7a51c74f9f9159d83fe11af.png)

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/28 "2018-05-09T19:42:59Z")

</div>

_From @jayair on Sun Aug 13 2017 18:35:19 GMT+0000 (UTC)_  
  
@jonsaw Can you check the CloudWatch logs for the create notes Lambda?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:42pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/29 "2018-05-09T19:42:59Z")

</div>

_From @jonsaw on Mon Aug 14 2017 01:27:49 GMT+0000 (UTC)_  
  
@jayair no logs from yesterday and today.

 ![screen shot 2017-08-14 at 09 28 14](https://yyz2.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/51d0a4474286c33716a6449f223ddda48ebf5fc6.png)

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/30 "2018-05-09T19:43:00Z")

</div>

_From @jayair on Mon Aug 14 2017 01:46:45 GMT+0000 (UTC)_  
  
@jonsaw Can I see your `serverless.yml`? And the IAM role attached to the Cognito Identity Pool? Here are some instructions on how to look it up - [https://github.com/AnomalyInnovations/serverless-stack-com/issues/112#issuecomment-317204545](https://github.com/AnomalyInnovations/serverless-stack-com/issues/112#issuecomment-317204545).

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/31 "2018-05-09T19:43:00Z")

</div>

_From @jonsaw on Mon Aug 14 2017 02:30:25 GMT+0000 (UTC)_  
  
serverless.yml

```auto
service: notes-api

# Use serverless-webpack plugin to transpile ES6/ES7
plugins:
  - serverless-webpack

# Enable auto-packing of external modules
custom:
  webpackIncludeModules: true

provider:
  name: aws
  runtime: nodejs6.10
  stage: prod
  region: ap-southeast-1

  iamRoleStatements:
    - Effect: Allow
      Action:
        - dynamodb:DescribeTable
        - dynamodb:Query
        - dynamodb:Scan
        - dynamodb:GetItem
        - dynamodb:PutItem
        - dynamodb:UpdateItem
        - dynamodb:DeleteItem
      Resource: "arn:aws:dynamodb:ap-southeast-1:*:*"

functions:
  create:
    handler: create.main
    events:
      - http:
          path: notes
          method: post
          cors: true
          authorizer: aws_iam
  get:
    handler: get.main
    events:
      - http:
          path: notes/{id}
          method: get
          cors: true
          authorizer: aws_iam
  list:
    handler: list.main
    events:
      - http:
          path: notes
          method: get
          cors: true
          authorizer: aws_iam
  update:
    handler: update.main
    events:
      - http:
          path: notes/{id}
          method: put
          cors: true
          authorizer: aws_iam
  delete:
    handler: delete.main
    events:
      - http:
          path: notes/{id}
          method: delete
          cors: true
          authorizer: aws_iam

```

Cognito Identity Pool IAM role:

```auto
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "mobileanalytics:PutEvents",
        "cognito-sync:*",
        "cognito-identity:*"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:*"
      ],
      "Resource": [
        "arn:aws:s3:::elasticbeanstalk-ap-southeast-1-999999999999/${cognito-identity.amazonaws.com:sub}*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "execute-api:Invoke"
      ],
      "Resource": [
        "arn:aws:execute-api:ap-southeast-1:*:xxxxxxxxxx/*"
      ]
    }
  ]
}

```

Thanks for the quick response @jayair .

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/32 "2018-05-09T19:43:00Z")

</div>

_From @jayair on Mon Aug 14 2017 17:28:30 GMT+0000 (UTC)_  
  
@jonsaw All this looks good. And I’m assuming you got through the Test the APIs chapter?

If so, then can you host your backend code so I can take a look?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/33 "2018-05-09T19:43:01Z")

</div>

_From @jonsaw on Tue Aug 15 2017 00:43:13 GMT+0000 (UTC)_  
  
Yes, got `OK` for the test APIs chapter.

Sure, backed code hosted [here](https://github.com/jonsaw/serverless-notes).

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/34 "2018-05-09T19:43:01Z")

</div>

_From @jayair on Tue Aug 15 2017 17:42:30 GMT+0000 (UTC)_  
  
@jonsaw Just tried your backend with my react app and the CORS part worked. Of course the request itself failed because I don’t have your DB.

 ![screen shot 2017-08-15 at 1 40 14 pm](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/87644a705e29eea1ea6e3b8e4b23bdfe9e816848.png)

Can you host your frontend code as well and I’ll take a look?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/35 "2018-05-09T19:43:01Z")

</div>

_From @jonsaw on Wed Aug 16 2017 00:09:00 GMT+0000 (UTC)_  
  
@jayair I’ll post it. But in the meantime, I was looking at the console and I noticed I got the following response headers:

```auto
content-length:358
content-type:application/json
date:Wed, 16 Aug 2017 00:05:04 GMT
status:403
via:1.1 f8f44b9f631a9dc3326cc7f64bcd4863.cloudfront.net (CloudFront)
x-amz-cf-id:CMEkFLWhGjdjYzTH3CLkgDdmsJjoURPbHh1o2NB2yThH0z_oLRzyjw==
x-amzn-errortype:IncompleteSignatureException
x-amzn-requestid:8e228d97-8216-11e7-b477-3b952b608cf8
x-cache:Error from cloudfront

```

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/36 "2018-05-09T19:43:02Z")

</div>

_From @jayair on Wed Aug 16 2017 17:05:22 GMT+0000 (UTC)_  
  
@jonsaw Yeah that’s a good clue. It seems like the signature for the request was not calculated properly. Let’s take a look at the frontend.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/37 "2018-05-09T19:43:02Z")

</div>

_From @dailenspencer on Wed Aug 23 2017 23:26:13 GMT+0000 (UTC)_  
  
Hey guys,

Great tutorial! I’m running into an ERR\_NAME\_NOT\_RESOLVED error when initiating the invokeApig call to create a new note. Screenshot here

 ![screen shot 2017-08-23 at 1 23 12 pm](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/78a0b4dcb50cb951b7f71f10f229a55eee27ecdc.png)

Any ideas would be helpful! Thanks

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/38 "2018-05-09T19:43:02Z")

</div>

_From @jayair on Thu Aug 24 2017 00:06:42 GMT+0000 (UTC)_  
  
@dailenspencer That sounds like you are not able to hit that URL from your local machine. Did the step where you tested the APIs work for you?

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/39 "2018-05-09T19:43:03Z")

</div>

_From @dailenspencer on Thu Aug 24 2017 01:05:48 GMT+0000 (UTC)_  
  
@jayair Thanks for the quick response. Just got back to my keyboard. Here is a screenshot of the test - you will see the data comes back empty; Not sure why this is.

 ![screen shot 2017-08-23 at 3 03 51 pm](https://canada1.discourse-cdn.com/flex032/uploads/serverless_stack/original/1X/7ba1059fef9a898cd589a4d8d39e9eab30cf23e1.png)

Update: seemed to narrow down the issue. The above terminal command was executing my list.js lambda function for some reason, hence the empty array returned. Inside my serverless.yml I had the following

```auto
list:
   # Defines an HTTP API endpoint that calls the main function in list.js
   # - path: url path is /notes
   # - method: GET request
   handler: list.main
   events:
     - http:
         path: notes
         method: post
         cors: true
         authorizer: aws_iam

```

the method property was set to **post** which made it identical to the create method. My lambda ended up being confused and called the list.js function instead of the create.js function.

---

<div class="post-metadata">

**Author:** ![anomalyinnovations](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.sst.dev/anomalyinnovations/32/10_2.png) [@anomalyinnovations](https://discourse.sst.dev/u/anomalyinnovations)\
**Post date:** [May 9, 2018, 7:43pm UTC](https://discourse.sst.dev/t/call-the-create-api/124/40 "2018-05-09T19:43:03Z")

</div>

_From @jayair on Thu Aug 24 2017 18:27:32 GMT+0000 (UTC)_  
  
@dailenspencer I just noticed in your original screenshot that you are trying to connect to the API endpoint that we have in the tutorial. Replace that with the one you are using in the `apig-test` command and give it a try.

[Previous page](https://discourse.sst.dev/t/call-the-create-api/124.md?page=1)

[Next page](https://discourse.sst.dev/t/call-the-create-api/124.md?page=3)
