# Slack -\> Postman via webhook (parse JSON)

**URL:** <https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043>\
**Category:** Help Hub\
**Created:** [October 17, 2018, 3:44pm UTC](https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043 "2018-10-17T15:44:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_pm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@steve\_pm](https://community.postman.com/u/steve_pm)\
**Post date:** [October 17, 2018, 3:44pm UTC](https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043/1 "2018-10-17T15:44:41Z")

</div>

Hi - sorry for the super n00b question… Trying to take JSON message from a Slack slash command and parse this in postman.

- Created a Postman webhook via Postman API, linked to a Collection
- Using this as the URL for the slash command in Slack - seems to be connected as when the slash command is run in Slack the Collection Chain runs in Postman … but unsure where/how to pull the JSON before this happens?

I am trying to use inputs from the JSON to update Environment Variables - but struggling to figure out how to parse these.

Any advice please?

---

<div class="post-metadata">

**Author:** ![bhargavkaranam96](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@bhargavkaranam96](https://community.postman.com/u/bhargavkaranam96)\
**Post date:** [October 18, 2018, 10:55am UTC](https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043/2 "2018-10-18T10:55:03Z")

</div>

Hey @steve_pm,  
You can use `globals.previousRequest` in your pre request script to access the payload that was sent to the webhook. You can do something like this,

```auto
let previousRequest = JSON.parse(globals.previousRequest),
    webhookRequestData = previousRequest.data;

```

`webhookRequestData` will contain the data sent to you.

---

<div class="post-metadata">

**Author:** ![steve\_pm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@steve\_pm](https://community.postman.com/u/steve_pm)\
**Post date:** [October 18, 2018, 1:14pm UTC](https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043/3 "2018-10-18T13:14:27Z")

</div>

Hey @bhargavkaranam96 - thanks for replying. Simplifying a bit - I am using this code right now in pre request script. response\_url is a field in the Slack payload, so just trying to set this variable in the environment (then will figure the rest out).

However it’s still not setting the variable. The Body script runs correctly, as does the test script afterwards - so it’s working, but the variable is not being set. Any ideas?

let previousRequest = JSON.parse(globals.previousRequest),  
webhookRequestData = previousRequest.data;

pm.environment.set(“response\_url”, webhookRequestData.response\_url );

_just to add, I can see the payload from Slack in the postman monitor for the webhook still, including the response\_url field and its contents…_

---

<div class="post-metadata">

**Author:** ![bhargavkaranam96](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@bhargavkaranam96](https://community.postman.com/u/bhargavkaranam96)\
**Post date:** [October 19, 2018, 5:31am UTC](https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043/4 "2018-10-19T05:31:55Z")

</div>

Could you `console.log(previousRequest.data)` and check if you’re receiving the data correctly? Could you also check if the environment you provided during the creation of webhook matches the one you are currently using?

---

<div class="post-metadata">

**Author:** ![Shri1](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Shri1](https://community.postman.com/u/Shri1)\
**Post date:** [February 21, 2019, 7:59am UTC](https://community.postman.com/t/slack-postman-via-webhook-parse-json/3043/5 "2019-02-21T07:59:25Z")

</div>

Do you have a complete step by step info about Webhook testing using Postman. Please provide repo
