juzibot / xiaoju

17 stars 2 forks source link

send message api error messageType is not integer #15

Closed tianlu1677 closed 5 years ago

tianlu1677 commented 5 years ago
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://ex-api.botorange.com/message/send?token=xxx",
  "method": "POST",
  "headers": {
    "content-type": "application/x-www-form-urlencoded"
  },
  "data": {
    "chatId": "5d270146bd6faa1c4e0c0a24",
    "token": "xxxx",
    "messageType": 1,
    "payload[text]": "我们"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

When I use postman to send message I got this error.

{
  "error": "Validation Failed",
  "detail": [
    {
      "message": "should be an integer",
      "code": "invalid",
      "field": "messageType"
    }
  ]
}
windmemory commented 5 years ago

The messageType needs to be an integer. I think you need to check your post method, it might mess up with the data type, and changed it to be a string.

Try to change content-type to be application/json

tianlu1677 commented 5 years ago

Becase when you receiver params,it always string. I guess you should parse string to integer.

I try Content-Type 'application/json', or form-data. Could you give me a simple example? Thanks. @windmemory

windmemory commented 5 years ago

It is not params, it should be body, because this is a post request.

windmemory commented 5 years ago

type needs to be application json. You can start a dev server and post the message youself to your server, and see if the data type you sent is right.

tianlu1677 commented 5 years ago

Thank you. I success. We should data.to_json and content_type: 'application/json'