# Grpc before invoke script not able to retrieve message data the actual request data that is sent

**URL:** <https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799>\
**Category:** Help Hub\
**Created:** [November 4, 2022, 10:05pm UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799 "2022-11-04T22:05:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadayalan](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kadayalan](https://community.postman.com/u/kadayalan)\
**Post date:** [November 4, 2022, 10:05pm UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799/1 "2022-11-04T22:05:51Z")

</div>

In grpc request to retrieve the request data I tried pm.request but if I use under before invoke the message section is empty but if I use it under after response the pm.request message section has data

Is there a way to get the request data in the before invoke script

I need to do some calculations before invoking with request data and validate against the response data

Thank you in Advance

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 7, 2022, 12:46pm UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799/2 "2022-11-07T12:46:01Z")

</div>

From the blurb.

> **[Postman JavaScript reference | Postman Learning Center](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/)**
>
> Postman JavaScript reference: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

_The `pm.request` object provides access to the data for the request the script is running within. For a **Pre-request Script** this is the request that’s about to run, and for a **Test** script this is the request that has already run._

Sounds like this needs to be in the pre-request script.

---

<div class="post-metadata">

**Author:** ![kadayalan](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kadayalan](https://community.postman.com/u/kadayalan)\
**Post date:** [November 7, 2022, 5:13pm UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799/3 "2022-11-07T17:13:35Z")

</div>

Sample data what I am looking for

Request string in the Before invoke{“id”:“636061423599ae7c03604497”,“name”:“grpc://localhost:9091”,“url”:{“host”:[“g-p7pykxy4kpop1nonwl761z5mnl68w2”,“srv”,“pstmn”,“io”],“query”:,“variable”:},“methodPath”:“user.login”,“auth”:{},“metadata”:,“messages”:}

here Message section is empty, I was expecting data

But in the After response

Request string in the After response{“id”:“636061423599ae7c03604497”,“name”:“grpc://localhost:9091”,“url”:{“host”:[“g-p7pykxy4kpop1nonwl761z5mnl68w2”,“srv”,“pstmn”,“io”],“query”:,“variable”:},“methodPath”:“user.login”,“auth”:{},“metadata”:,“messages”:[{“data”:{“password”:“demo”,“username”:“test”},“timestamp”:“2022-11-07T17:11:05.390Z”}]}

After response has message data  
username and Password

---

<div class="post-metadata">

**Author:** ![appurva21](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/appurva21/32/34560_2.png) [@appurva21](https://community.postman.com/u/appurva21)\
**Post date:** [November 21, 2022, 6:37am UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799/4 "2022-11-21T06:37:04Z")

</div>

@kadayalan Thanks for reporting the issue!

We have fixed this in the latest release of the app (v10.4.1) and you should now have access to the request message in the _Before invoke_ script as well for Unary and Server streaming methods.

---

<div class="post-metadata">

**Author:** ![appurva21](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/appurva21/32/34560_2.png) [@appurva21](https://community.postman.com/u/appurva21)\
**Post date:** [November 29, 2022, 10:58am UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799/5 "2022-11-29T10:58:36Z")

</div>

@kadayalan We have made a change to the data exposed by our API. With Postman v10.5.6, request message data in **Before invoke** script will be a string instead of a Javascript object.

You can convert it to an object using the below snippet in your script:

```javascript
const message = JSON.parse(pm.request.messages.idx(0).data);

```

Note: This only affects the **Before invoke** script. **After response** scripts will continue to work as is.

---

<div class="post-metadata">

**Author:** ![kadayalan](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kadayalan](https://community.postman.com/u/kadayalan)\
**Post date:** [November 30, 2022, 5:32pm UTC](https://community.postman.com/t/grpc-before-invoke-script-not-able-to-retrieve-message-data-the-actual-request-data-that-is-sent/40799/6 "2022-11-30T17:32:42Z")

</div>

Thank you will check on it
