Invalid request body format when trying to reply to user. chatbot app

Zoom Apps Configuration

Ruby on Rails

Description

No matter what I try, I always get a BadRequest reply from the server when replying to a message from our chatbot. Never have managed to make it work.

Error?

RestClient::BadRequest (400 Bad Request)

and on Postman:

{
“code”: 7001,
“message”: “Invalid request body format.”,
“result”: false
}

Troubleshooting Routes

  • I added all the info to have a publishable URL, which is apparently needed to use production client id and secret.
  • I tested locally and on postman.

How To Reproduce

  1. Have a user ask something to the chatbot
  2. Upon request reception, access_token is properly obtained
  3. when sending reply, I get the bad request message. This is the method

def send_chat(chatbot_token)
url = ‘https://api.zoom.us/v2/im/chat/messages

body = {
    'robot_jid': Lalip::Application.credentials.dig(:zoom_app,:bot_jid),
    'to_jid': params[:payload][:toJid],
    'account_id': params[:payload][:accountId],
    'content': {
      'head': {
        'text': 'Your rewritten feedback:'
      },
      'body': [{
        'type': 'message',
        'text': "you said #{params[:payload][:cmd]}"
      }]
    }
  }
  headers = {
    'Content-Type': 'application/json',
    'Authorization': "Bearer #{chatbot_token}"
  }
  response = RestClient.post url, body.to_json, headers
  if response.code == 200
    Rails.logger.debug(response.body)
  else
    Rails.logger.error("Error sending chat. #{response.body}")
  end
end

Welcome :smiley:

Thank you for posting in the Zoom Developer Forum, @anto1 ! To begin, can you confirm if you are encountering this issue only when making a request using Ruby? Have you attempted to make the request in a different programming language or using a tool like Postman? You should also know, Postman can also help with formatting issues as it generates code snippets for each entered request.

Hello,

The issue is the same with postman. I copied the error i got from postman o the request!

I just realized that on this page:

https://marketplace.zoom.us/docs/guides/chatbots/send-edit-and-delete-messages/

You mark the " user_jid" as required. But I do not know my user_jid.

Is this the issue?

@anto1 ,

That may an issue but I do not think it will resolve the Invalid request body format error. This error means you sent data in the incorrect format. I’d recommend using a tool like postman to test making a successful request. I see you used postman and were not successful, can you a share screenshot of how you set up the request?

Sure.

I send a message to the chatbot from zoom. The access token gets created on my server. I take that token and paste it on postman, and add the production jbot id, plus account id and to_jid. Attached three screenshots: the (successful) authorization request, followed by the headers of the send message request and the body + result of the request. Clicking the image will show you the three images

Any updates? Thanks!

still waiting! what else can i try?

Hi @anto1
I recently saw a similar issue in the forum, which was resolved by adding the “user_jid” field in the request body

Can you please give this a try and let me know?
Best,
Elisa

1 Like

It worked. Thanks Elisa. Please update the documentation!

Anto

2 Likes

The documentation page (the forum does not allow me to include links to your documentation, but it’s the page titled Send, edit, and delete messages in the Guides section, URL path /docs/team-chat-apps/send-edit-and-delete-messages/) says Use the account_id or the user_jid not both. Are you saying that we should indeed use both? But I am not sending a message on behalf of an individual user. It’s on behalf of a chatbot associated with my account.

I see our older apps are working fine, but when I try to test a new one with the same code on our side, I am getting this same error.

Hi @hkubov
could you please create a new topic and add as many details as possible about your issue?
This topic has been solved so we have to move the conversation to a new one please

I will not create a new topic because it’s the same problem and it’s barely resolved if your suggestion is to add user_jid in contradiction to your documentation. I think what’s missing (or maybe what I have missed) is an explanation that you should use account_id for Admin-managed apps and user_jid for User-managed apps

Thanks @hkubov
I understand. Thank you for your feedback and I will pass it down to our team