grpc error: packets.SubmitCustomerRequest.details: object expected - protocol-buffers

I just created a proto file like this
service Customer {
rpc SubmitCustomer(SubmitCustomerRequest) returns (SubmitCustomerResponse) {}
}
message SubmitCustomerRequest {
string name = 1;
map<string, google.protobuf.Any> details = 2;
}
message SubmitCustomerResponse {
int64 id = 1;
}
The code itself works when I called this from the client. But, I'm having trouble with testing it directly from bloomrpc or postman.
{
"name": "great name",
"details": {
"some_details": "detail value",
"some_int": 123
}
}
it throws me this error when I tried to hit it
.packets.SubmitCustomerRequest.details: object expected
I think I'm aware that the problem is with the details syntax format when I hit it on postman, but I'm not sure what the correct format is supposed to be. I've tried modifying it with any other possible format and none works either.

Related

/* in transcoding from HTTP to gRPC

rpc CreateBook(CreateBookRequest) returns (Book) {
option (google.api.http) = {
post: "/v1/{parent=publishers/*}/books"
body: "book"
};
}
message CreateBookRequest {
// The publisher who will publish this book.
// When using HTTP/JSON, this field is automatically populated based
// on the URI, because of the `{parent=publishers/*}` syntax.
string parent = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = {
child_type: "library.googleapis.com/Book"
}];
Book book = 2 [(google.api.field_behavior) = REQUIRED];
string book_id = 3;
}
I don't understand post: "/v1/{parent=publishers/*}/books"
I thought publishers was a field in CreateBookRequest, then it populates to http, so it is something like this
post: "/v1/parent=publishers_field_value/books"
But publishers is not a field in CreateBookRequest
No, publishers is part of the expected value of the parent field. So suppose you have a protobuf request like this:
{
"parent": "publishers/pub1",
"book_id": "xyz"
"book": {
"author": "Stacy"
}
}
That can be transcoded by a client into an HTTP request with:
Method: POST
URI: /v1/publishers/pub1/books?bookId=xyz (with the appropriate host name)
Body:
{
"author": "Stacy"
}
If you try to specify a request with a parent that doesn't match publishers/*, I'd expect transcoding to fail.
That's in terms of transcoding from protobuf to HTTP, in the request. (That's the direction I'm most familiar with, having been coding it in C# just this week...)
In the server, it should just be the opposite - so given the HTTP request above, the server should come up with the original protobuf request including parent="publishers/pub1".
For a lot more information on all of this, see the proto defining HttpRule.

Updating meta fields in Shopify with GrapQL

I've never used GraphQL before so I am really lacking knowledge on how to go about this. I'm wanting to update product meta fields on Shopify and it appears this is the only way. What I've done so far is really fumbling...
My JSON is:
{
"input": {
"id": "gid://shopify/Product/749521178847",
"metafields": [
{
"id": "gid://shopify/Metafield/2223333",
"value": "Training Grounds"
}
]
}
}
I've minified this to:
{"input":{"id":"gid://shopify/Product/749521178847","metafields":[{"id":"gid://shopify/Metafield/2223333","value":"The Training Grounds"}]}}
And am then using an HTTP request to:
https://MYSTORE.myshopify.com/api/2021-10/graphql.json?query={"input":{"id":"gid://shopify/Product/749521178847","metafields":[{"id":"gid://shopify/Metafield/2223333","value":"The Training Grounds"}]}}
I get the error:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
I don't know if any of this is correct. If it is, I don't know if ?query= is the right variable to pass it through on.
I recommend you start using Postman, thunder client, or similar to write your graphql queries first, you will learn a lot about how graphql works and the error msgs will be a lot more useful.
To easily connect with Shopify on this stage, go to a store and create a private app, now you can use this for authenticating your API calls.
After that the Shopify graphql works on POST, you can't write your request on GET mode.
It needs to be a POST and you are missing type of operation mutation in this case and what it is.
Postman has https://www.postman.com/lively-moon-541169/workspace/purego-apis/example/16545848-bf0d1589-09b1-4ec6-ba63-a65a56b500eb examples of how to do the calls which can help you.
Also you can check GraphiQL app on shopify to test all the queries before making the programmatic queries
Updating an existing metafield:
mutation {
metafieldsSet(metafields: [
{namespace: "YOURNAMESPACE", ownerId: "gid://shopify/Customer/CUSTOMER_ID", type: "single_line_text_field", key: "YOURKEY", value: "THIS IS NEW VALUE"}
]) {
metafields {
key
value
}
userErrors {
field
message
}
}
}
Creating new metafield:
mutation {
customerUpdate(input: {
id: "gid://shopify/Customer/CUSTOMER_ID",
metafields: [
{key: "newkey", value: "some value", type: "single_line_text_field", namespace: "some namespace"},
]
}) {
userErrors {
field
message
}
}
}

Protobuf oneof JSON syntax issue

I have a proto which is something like (not the exact case but very similair)
message football {
repeated TeamDetails teamInfo= 1;
}
message TeamDetails {
string position = 1;
map<string, points> params = 2;
}
message points {
oneof value {
string string_value = 1;
double number_value = 2;
int32 int_value = 3;
}
}
and I have a few questions about this;
Is my oneof here okay and usable?
I keep getting an issue when trying to run the following JSON to the end point, I'm not sure what I'm doing wrong
"teamInfo": [
{
"position":"7th",
"params": {"Manchester United": 51}
}
]
gives me
"Error getting request data: bad input: expecting start of JSON object: '{' ; instead got 51"
I get the same error even after adding quotes around the 51, and if I replace the 'points' in the proto with <string, string> it would successfully work for the same JSON (but I don't want a string everytime, hence I'm trying to use the oneof but I'm getting this issue)
Please try:
"teamInfo": [
{
"position":"7th",
"params": {"Manchester United": { "int_value": 51 } }
}
]
The type of params is map<string, points> but your JSON has the equivalent of map<string, int32>. That's valid JSON but it's not the equivalent of the proto type.
Because points is oneof i.e. string (or) double (or) int32, I think you need to replace (any) oneof with a generic JSON object that can represent multiple (possible) types i.e. {...} and, in this case, you want the int32 field called int_value.

Associate File in Parse.Cloud

I am uploading an image through REST API and getting an answer as below
{
"url": "http://files.parsetfss.com/346a0978-68c7-4d08-a446-62f7422469e7/tfss-8b131ff0-5fd0-4dce-92e8-b7b94da5db9e-pic.jpg",
"name": "tfss-8b131ff0-5fd0-4dce-92e8-b7b94da5db9e-pic.jpg"
}
I want to associate this image to a Promotion object. I also have a Location object which has an array of Promotions. Here is my code:
function promiseToAddPromotionToLocation (locationID, promotion) {
var query = new Parse.Query("Location");
return query.get(locationID).then(function (location) {
var promotionObject = promotionObjectFromJSON(promotion);
location.add("promotions", promotionObject);
return location.save();
}, function (error) {
return Parse.Promise.error(error);
});
}
function promotionObjectFromJSON (promotion) {
var Promotion = Parse.Object.extend("Promotion");
var promotionObject = new Promotion();
if ("message" in promotion) {
promotionObject.set("message", promotion.message);
}
//This causes an error: Uncaught Tried to save an object containing an unsaved file.
if ("photo") {
promotionObject.set("photo", promotion.photo);
}
return promotionObject;
}
When I comment out the part of setting photo, it saves the promotion properly, but when I try to set the file, it gives an error saying Uncaught Tried to save an object containing an unsaved file. How can I solve this problem?
By the way promiseToAddPromotionToLocation is called with the parameters below:
{
"locationID": "fvOiAsoogc",
"promotion":{
"message":"Some text",
"photo":{"name": "tfss-8b131ff0-5fd0-4dce-92e8-b7b94da5db9e-pic.jpg", "__type": "File"}
}
}
The reason was that I was passing the file info without url. Associating file docs show that it only needs name and type. However, this is wrong. It also needs the url. This question in Parse forum reveals it.

WebApi 2.1 Model validation works locally, but does not show missing fields when run on the server

We are using WebApi v2.1 and validating ModelState via a filter applied in the WebApiConfig class.
Fields specified as required are not listed on the error message when we run on the server (Win Server 2008R2), but they work perfectly when we run locally (on IISExpress).
The request is correctly rejected locally and on the server, but the server response does not show the missing fields.
For Example:
Given a Local request that lacks the required abbreviation and issuerName fields, the response shows as expected:
{
"message": "The request is invalid.",
"modelState": {
"value": [
"Required property 'abbreviation' not found in JSON. Path '', line 18, position 2.",
"Required property 'issuerName' not found in JSON. Path '', line 18, position 2."
]
}
When the same request is sent to the server, the response shows:
{
"message": "The request is invalid.",
"modelState": {
"value": [
"An error has occurred.",
"An error has occurred."
]
}
}
Our filter is the following:
public class ValidateModelStateAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
if (!actionContext.ModelState.IsValid)
{
actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, actionContext.ModelState);
}
}
}
Our data model class is decorated with the DataContract attribute, and the required fields are attributed like so:
[DataMember(IsRequired=true)]
public string IssuerName
The server is more restrictive about sending errors down ot the client. Try setting the IncludeErrorDetails flag on your httpconfiguration to verify that this is the underlying issue.
In general though turning this flag on is not the best idea, and you will want to serialize the errors down differently.
For more info:
http://blogs.msdn.com/b/youssefm/archive/2012/06/28/error-handling-in-asp-net-webapi.aspx

Resources