# How can I get raw body string in Lambda (API gateway Lambda proxy)

**URL:** <https://forum.serverless.com/t/how-can-i-get-raw-body-string-in-lambda-api-gateway-lambda-proxy/1319>\
**Category:** Serverless Architectures\
**Created:** [February 13, 2017, 9:48pm UTC](https://forum.serverless.com/t/how-can-i-get-raw-body-string-in-lambda-api-gateway-lambda-proxy/1319 "2017-02-13T21:48:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![panorart](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@panorart](https://forum.serverless.com/u/panorart)\
**Post date:** [February 13, 2017, 9:48pm UTC](https://forum.serverless.com/t/how-can-i-get-raw-body-string-in-lambda-api-gateway-lambda-proxy/1319/1 "2017-02-13T21:48:56Z")

</div>

After enabled CORS on API gateway, here is the request I sent to the http end point:

```
$.ajax({
    type: 'put',
    url: 'https://xxxxx.execute-api.us-east-1.amazonaws.com/dev/artist/application/julian_test',
    data: {params: {param1: "543543", param2: "fdasghdfghdf", test: "yes"}},
    success: function(msg){
        console.log(msg);
    },
    error: function(msg){
        console.log(msg);
    }
});

```

Here is the lambda function(I’m using node serverless package, and no mistakes on the code):

```
module.exports.julian_test = (event, context, callback) => {
console.log(event);
console.log(event.body);

var response_success = {
statusCode: 200,
headers: {
    "Access-Control-Allow-Origin": "*"
},
body: JSON.stringify({
    firstUser: {
        username: "Julian",
        email: "awesome"
    },
    secondUser: {
        username: "Victor",
        email: "hello world"
    },
    thirdUser: {
        username: "Peter",
        email: "nice"
    }
})
};
callback(null, response_success);
};

```

The console.log(event.body) logs out : params%5Bparam1%5D=543543&params%5Bparam2%5D=fdasghdfghdf&params%5Btest%5D=yes

, which is not the format I want. I checked the OPTIONS Integration Request / body mapping template, here is the snapshot.

 ![](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/1X/7eecb9ea3dadcd406ae80ae9738e2c3b635552de.png)

I tried to delete the “application/json” but after that I receive the following response:

XMLHttpRequest cannot load [https://xxxxxx.execute-api.us-east-1.amazonaws.com/dev/artist/application/julian\_test](https://xxxxxx.execute-api.us-east-1.amazonaws.com/dev/artist/application/julian_test). Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access. The response had HTTP status code 500.

Does anyone know how to get a raw string request body in the back-end lambda? Please help!

---

<div class="post-metadata">

**Author:** ![DavidWells](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/davidwells/32/201_2.png) [@DavidWells](https://forum.serverless.com/u/DavidWells)\
**Post date:** [February 13, 2017, 9:53pm UTC](https://forum.serverless.com/t/how-can-i-get-raw-body-string-in-lambda-api-gateway-lambda-proxy/1319/2 "2017-02-13T21:53:42Z")

</div>

Do you have CORS set in serverless.yml. cors: true

```auto
provider:
  name: aws
  runtime: nodejs4.3

functions:
  hello:
    handler: handler.hello
    events:
       - http:
           path: hello
           method: get
           cors: true

```

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [February 14, 2017, 2:11am UTC](https://forum.serverless.com/t/how-can-i-get-raw-body-string-in-lambda-api-gateway-lambda-proxy/1319/3 "2017-02-14T02:11:41Z")

</div>

@panorart It looks like you’re using jQuery for your AJAX request. The jQuery docs state that data is converted to a query string unless it’s already a string.

Are you trying to pass this as a JSON object? If you are then try using `data: JSON.stringify({params: {param1: "543543", param2: "fdasghdfghdf", test: "yes"}})`.

You’ll need to use `JSON.parse(event.body)` in your Lambda to convert the string back to a JSON object.
