# How to Generate Code Snippet that can be Pasted into Script Body?

**URL:** <https://community.postman.com/t/how-to-generate-code-snippet-that-can-be-pasted-into-script-body/11415>\
**Category:** Help Hub\
**Created:** [March 18, 2020, 4:05pm UTC](https://community.postman.com/t/how-to-generate-code-snippet-that-can-be-pasted-into-script-body/11415 "2020-03-18T16:05:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BobDuffett](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@BobDuffett](https://community.postman.com/u/BobDuffett)\
**Post date:** [March 18, 2020, 4:05pm UTC](https://community.postman.com/t/how-to-generate-code-snippet-that-can-be-pasted-into-script-body/11415/1 "2020-03-18T16:05:52Z")

</div>

How do you convert a Request via the Code button into script language compatible with Postman’s script language? I want to paste the request into a pre-request script.

i.e. I want the generated code to look like:

pm.sendRequest(“[https://postman-echo.com/get](https://postman-echo.com/get)”, function (err, response) {  
console.log(response.json());  
});

None of the 20+ languages, including the 3 JavaScript versions, look like Postman Javascript.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [March 18, 2020, 5:03pm UTC](https://community.postman.com/t/how-to-generate-code-snippet-that-can-be-pasted-into-script-body/11415/2 "2020-03-18T17:03:51Z")

</div>

Hey @BobDuffett,

I think the `Nodejs - Request` would be the closest at _auto-creating_ what you need. It would give you something like this:

```
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://postman-echo.com/get',
  'headers': {
    'test-header': '123345'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});

```

If you slightly changed it to this and added it to the pre-request, it would work:

```
var options = {
  'url': 'https://postman-echo.com/get',
  'header': {
    'test-header': '123345'
  }
};
pm.sendRequest(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.json());
});

```

More examples for the `pm.sendRequest()` function can be found here:

> <https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990>
