0

I have programmed some code in accordance with the rest API, to integrate a chat bot to Viber.

The core part of it is -:

$.ajax({
url : url ,
dataType : "jsonp",
type : 'POST',
jsonpCallback: 'fn',
headers: {
    'X-Viber-Auth-Token': '45a53f0fcb325002-41552d1f93cd0d0f-1a8d7fa78758d158'
},
data : {  
    "url": "",
    "event_types": ["delivered", "seen", "failed", "subscribed","unsubscribed", "conversation_started"]  
},
success : function (data) {
    //console.log(data);
},
error : function (data, errorThrown) {
    //console.log(data);
    alert(errorThrown);
}        
});

I am getting a parse error and the parse error is "Uncaught SyntaxError: Unexpected token :". You can visit the code from -: https://manveer695.github.io/hello-world/viberStuff.html and check the errors yourself.

Any syntax error or some other problem? Thanks in advance. :)

  • As the duplicate says, the problem is that the response is not JSONP but you set `dataType: "jsonp"`. You do have some other problems though: JSONP is incompatible with custom HTTP headers and POST requests. – Quentin Mar 18 '17 at 21:56

1 Answers1

0

The server is returning JSON not JSONP, just change your dataType to 'JSON'.

Martina
  • 739
  • 3
  • 13
  • Then how to achieve cross-site feature? As I make a call to a different site i.e. to Viber chat API from github.io. – Manveer Singh Mar 19 '17 at 08:24
  • I don't think this server allows for jsonp. Just follow their guidelines here https://developers.viber.com/api/rest-bot-api/index.html. They require you to have valid ssl certificate: "Setting the webhook will be done by calling the set_webhook API with a valid & certified URL. For security reasons only URLs with valid and official SSL certificate from a trusted CA will be allowed. " Do you have a valid non-self-signed certificate? – Martina Mar 19 '17 at 18:43
  • Yes, I am using https://manveer695.github.io/hello-world/viberStuff.html to call chat API of Viber, which is a https support from github. So I think it is having valid SSL certificate. Just I need to achieve the cross-site feature with JSON. – Manveer Singh Mar 20 '17 at 05:15
  • In your example the 'url' is empty, I assumed you just removed it for the example, you do have https ://manveer695.github.io in there right? The url is required field. It may be that if you pass all paramteres correctly it will return jsonp eventually or it will add your url to the 'safe' list of origins. – Martina Mar 20 '17 at 08:36
  • As I am trying methods constantly, so this is the exact commit for which this question is asked - https://github.com/Manveer695/hello-world/blob/359b7cc7ca2f5e93f602240079a7bc1d60af4993/viberReq.js and I am calling the Viber chat API from - https://manveer695.github.io/hello-world/viberStuff.html – Manveer Singh Mar 20 '17 at 09:36
  • The url should be just the host like this: https ://manveer695.github.io (excuse the space that doesn't belong there, the formatting in comments removes the https if I don't add the space) – Martina Mar 20 '17 at 14:00