1

I am using python for amazon SNS for publishing push notifications.

    data = { "GCM" : {"data":   {"message": "dummy"  }}}
    jsonData =  json.dumps(data)        

    self.client.publish( TargetArn=targetArn,
        Message= jsonData,
        MessageStructure='json')

Getting the below error.

Invalid parameter: JSON must contain an entry for 'default' or 'GCM'.

Tried sending it as string and various formats. But this is not working out. What's wrong with the publish?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
garg10may
  • 5,794
  • 11
  • 50
  • 91
  • The [boto3 documentation](https://boto3.readthedocs.io/en/latest/reference/services/sns.html#SNS.Client.publish) says "If you want to send different messages for each transport protocol, set the value of the MessageStructure parameter to json and use a JSON object for the Message parameter." However, you are only sending one type of message. Therefore, why are you using the JSON version? Have you tried just sending a string message with a GCM `targetARN`? – John Rotenstein Jun 27 '17 at 00:48
  • String won't work it shows undefined:undefined in push notificaiton. Even using console if I am using raw type it won't work. Working only with json. – garg10may Jun 27 '17 at 07:20

1 Answers1

6

The json strucutre needed by publish had to have \ escaped specifically. Below worked for me. It is important to have a default value and the value of GCM key should again be a json object.

GCM_data = { 'data' : { 'message' : 'dummy'}}

data = { "default" : "test",
         "GCM": json.dumps(GCM_data)
        }
jsonData =  json.dumps(data)
garg10may
  • 5,794
  • 11
  • 50
  • 91