PushMessage always return 400 Bad Request
I am using Line official account for free plan. I have enabled message API and EchoApplication is working fine. I am trying to use PushMessage api from LineMessagingService but I always get return 400 Bad Request with invalid property 'to', here is full detail.
: {"to":"xxxx","messages":[{"type":"text","text":"hello"}]} : --> END POST (61-byte body) : <-- 400 Bad Request https://api.line.me/v2/bot/message/push (209ms) : Server: nginx : Content-Type: application/json;charset=UTF-8 : X-Line-Request-Id: 22701bcd-d412-4515-a16e-ea3c20956532 : X-Content-Type-Options: nosniff : X-XSS-Protection: 1; mode=block : X-Frame-Options: DENY : Content-Length: 85 : Expires: Sun, 06 Nov 2016 05:11:35 GMT : Cache-Control: max-age=0, no-cache, no-store : Pragma: no-cache : Date: Sun, 06 Nov 2016 05:11:35 GMT : Connection: close : {"message":"The property, 'to', in the request body is invalid (line: -, column: -)"}
Note: for user id 'xxxx" I have tried to use my personal line id which got from LINE application and also this account already added my Line official account.
here is code section
private void pushTextMessage() { System.out.println("push text message:"); Message textMessage = new TextMessage("hello"); PushMessage pushMessage = new PushMessage("xxxx", textMessage); lineMessagingService.pushMessage(pushMessage); try { final BotApiResponse apiResponse = lineMessagingService.pushMessage(pushMessage).execute().body(); } catch (Exception e) { System.out.println(e.getMessage()); }
So I am not sure that
- Did I supply the wrong userId? if so where/how should I get a userId to supply the property 'to'
- How/which api should I use for sending message to all users who have added my LINE official account as friend. Because push message api still require to supply only 1 userId/time. Documents also said that it can send to rooms or groups but how do I get those IDs? This is just like LINE@ manager which is able to compose a message then send to friends at once.
I think the right userId should be grabbed from JSON object which contains events generated on the LINE platform, not from the LINE application, as well as groups or rooms. Even I have not tried this yet but I am closing this issue. In case the userID that grabbed from JSON object does not work, this issue could be re-open again.
Thanks.
I have the same problem but i can't find the right userID. Where have you found the ID of the receiver? And is it a number or a String?
Thanks.