google-wallet / rest-samples

Samples for the Google Wallet REST APIs
https://developers.google.com/wallet/
Apache License 2.0
277 stars 119 forks source link

Add message in pass always gives error regarding the message type #21

Closed Eleftheria-99 closed 2 years ago

Eleftheria-99 commented 2 years ago

Hello, I am trying to use this endpoint : https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject/addmessage, in order to send a message to the user that has added the pass ij the GPay. I am building the message body like this : message: { kind: "walletobjects#walletObjectMessage", header: header, body: body, // displayInterval: { // kind: "walletobjects#timeInterval", // start: { // date: start_date // }, // end: { // date: end_date // } // }, id: "message_id", messageType: { type: "string", enum: ["NOTIFICATION_EXPIRY"] } } and I am always getting this error :

  code: 400,
   errors: [
     {
         message: "Invalid value at 'add_message_request.message' (message_type), Starting an object on a scalar field",
         reason: 'invalid'
     }
  ] 

Is there an other way to use enum in json ?

Eleftheria-99 commented 2 years ago

I found a solution, it needs an enum , therefore you put 1 or 2 as number, 1 is the value for TEXT, 2 is the value for EXPIRY_NOTIFICATION

ncalteen commented 2 years ago

Hello!

Thank you for submitting this issue as well as providing your workaround. If you can, would you be able to provide the relevant code snippet where you are sending this message? I'd like to review to see what we can do to make this easier to prevent.

ncalteen commented 2 years ago

Hello,

Following up on this issue. I did some local testing and found the following.

The message POST body should follow the below format (note that messageType is a string value in this case.

{
  "message": {
    "header": string,
    "body": string,
    "displayInterval": {
      "start": {
        "date": "2022-09-01T00:00:01.00Z"
      },
      "end": {
        "date": "2022-09-05T00:00:01.00Z"
      }
    },
    "id": string,
    "messageType": "EXPIRATION_NOTIFICATION"
  }
}

The possible values for messageType are listed here. As you have noticed, the values do map to integers as well.

I hope this solves your issue. If you have other related questions please feel free to reopen this issue or create a new one.