postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.86k stars 841 forks source link

Sending struct via GRPC request #10753

Open v1lev opened 2 years ago

v1lev commented 2 years ago

Is there an existing issue for this?

Describe the Issue

Hi! I can't figure out how to properly send google.protobuf.Struct. Whenever I add a Struct field to the message it is received just as an empty field on the server.

Server = Python application with gRPC AsyncIO API Client = Postman

Sample message definition:

syntax = "proto3";
import "google/protobuf/struct.proto";

message Message {
  google.protobuf.Struct data = 1;
  google.protobuf.Struct another_data = 2;
}

Sample message that is sent via UI:

{
  "data": {
    "key": "value"
  }
  "another_data": {}
}

No matter of keys and values the data field is always empty at the server side.

Steps To Reproduce

  1. Create GRPC api with a request containing google.protobuf.Struct field
  2. Import it into Postman, create a request
  3. Fill a Struct field with a JSON-like entity
  4. At the server side the Struct field will be empty

Screenshots or Videos

No response

Environment Information

- Operating System: macOS Monterey 12.1
- Platform Type: Native App
- Postman Version: v9.14.13

Additional Context?

No response

igor-sirotin commented 2 years ago

I would like to add that the struct is also received wrong.

My proto message:

message MyMessage {
  google.protobuf.Struct data = 1;
}

I take this JSON:

{ 
  "myKey1": "myValue1",
  "myKey2": "myValue2"
}

And convert it in a C++ app with ::google::protobuf::util::JsonStringToMessage.

Having this done I expected to see in Postmane just the same JSON structure as I sent from the service. But what I get in postman is a "json of json":

{
    "key": "json",
    "value": {
        "struct_value": {
            "fields": [
                {
                    "key": "myKey1",
                    "value": {
                        "string_value": "myValue1"
                    }
                },
                {
                    "key": "myKey2",
                    "value": {
                        "string_value": "myValue2"
                    }
                }
            ]
        }
    }
}
Chen-hao-Huang commented 1 year ago

Similar bug happened to me too, the request worked with GrpcUI, but the server got an empty map when I copy pasted the same raw JSON to postman

codenirvana commented 1 year ago

@aawwsed10 Can you share the type definition and JSON value (without any sensitive information)?

Chen-hao-Huang commented 1 year ago

@aawwsed10 Can you share the type definition and JSON value (without any sensitive information)?

{
"object": {
...     
"attributes": {"test":"123"},
...
}
}

message Object{
...
    google.protobuf.Struct attributes = 12;                
...
}

and using postman the server would get map[] and with grpcui the server gets map[test:123]

const-tmp commented 1 year ago

Same issue Request:

{
    "data": {
        "action": "deposit"
    },
    "id": 8
}

Proto:

message UpdateTemplateRequest {
  int32 id = 1;
  google.protobuf.Struct data = 2;
}

Actual request data on server: id:8 data:{}

rahulrayal commented 1 year ago

Why you guys still didn't fixed it? It's a major bug

glovenkevin commented 1 year ago

It happen to me too, I was using postman with gRPC to send a struct-type property into golang applications. The apps didn't receive the payload completely, especially for the struct-type. Is there any progress on this issue?

lanzay commented 1 year ago

google.protobuf.Struct - do not work :(

More and more people are facing this problem. We like this product but we are forced to look for other alternatives - it's a pity.

Can you please tell us when you can start solving this problem?

glovenkevin commented 1 year ago

I don't know if any of you come to this post, but currently, I managed to use the gRPC struct value with some syntax provided. Probably this issue has been solved.

here is a simple sample of how I managed to send the struct value

...
"recipient": [
        "9a71327e-5ac6-46a8-8219-2e2cadeed303"
    ],
    "payload": {"fields": {
        "action_url": {
            "string_value": "https://xxxx.xxxx"
        },
        "request_number": {
            "string_value": "asdf"
        }
    }},
    "sender": "f7e442bc-14f7-4ee0-99c9-b317a190af45",
...

the struct value is set up to the object, and there is already a syntax for it. like

image

it is the same as the igor-sirotin mention before,

o-shevchenko commented 1 year ago

I faced that issue too. I've spent a lot of time debugging my code but it looks like there is an issue with Postman.

xuanyuwang commented 11 months ago

The issue is still existing at of 2023 Dec 27 with

Version 10.21.9
UI Version: 10.21.9-ui-231220-0601
Desktop Platform Version: 10.21.0 (10.21.0)

Spent hours to figure out what went wrong :(

panoet commented 10 months ago

I am facing this also, now

anmol242 commented 9 months ago

We are also seeing the same problem. When we use the server reflection proto definition, everything works great. However, when we make a GRPC call while importing the proto file, it truncates the data in the fields it is sending to server. Also,server reflection expects 'google.protobuf.Struct' in the request in a different format, while importing the proto file expects the 'google.protobuf.Struct' in the request in a different format .

For eg: If I have message like this in the proto file:

syntax = "proto3";
import "google/protobuf/struct.proto";

message Message {
  google.protobuf.Struct data = 1;
  string user_id = 2;
}

For Server reflection postman is expecting this in request:

{
    "data": {
        "fields": [
            {
                "key": "email",
                "value": {
                    "string_value": "abc@mail.com"
                }
            },
            {
                "key": "address",
                "value": {
                    "string_value": "Delhi, India"
                }
            }
         ]
     },
     user_id: "test-id"
 }      

When I import the proto file on postman:

{
    "data": {
        "fields": {
            "email": {
               "string_value": "abc@mail.com"
               },
            "address": {
                 "stringValue":"Delhi, India"
                 }
            }
      },
    user_id: "test-id"
}

The server reflection request works fine but the one I am sending while importing proto file doesn't.

PJEstrada commented 4 months ago

Still experiencing this on July 15, 2024

iurydias commented 3 months ago

Same problem here...

Sahil-Agarwal-DD commented 2 months ago

I am still facing this issue!

xsor-hbo commented 2 months ago

Below is what worked for me. Using server reflection. Postman Version 11.11.1

{
    "my_struct_field": {
        "fields": {
            "my_field_name": {
                "string_value": "abc"
            }
        }
    }
}
Sahil-Agarwal-DD commented 2 months ago

When I use server reflection, I get this - (properties is the struct field) Postman Version 11.11.1

"properties": {
                    "fields": [
                        {
                            "key": "anim consequat culpa nisi aliquip",
                            "value": {}
                        },
                        {
                            "key": "nulla irure dolor laboris dolor",
                            "value": {}
                        },
                        {
                            "key": "do aliqua anim laboris cupidatat",
                            "value": {}
                        }
                    ]
                },

On using the format that @xsor-hbo provided, it worked fine for me. Thank you.