Messaging App Extension -- Receiving a message

I’m trying to implement the message receiving flow.

I have devised a curl command which sends the necessary authorization method and message data to my express server, which then in turn submits the post request.

Now, when I run this curl in my terminal it works and the message appears on my Pipedrive message inbox. However, when I try to send this http request over the javascript program which handles new message events in real time, I get an error regarding my payload.

Here are my program logs:

Incoming request: POST /api/v1/channels/messages/receive
Headers: {"connection":"upgrade","host":"<host-address>","content-length":"311","user-agent":"curl/7.88.1","accept":"*/*","authorization":"Bearer <my-oauth-token>","content-type":"application/json"}
Body: {"id":"<message-id>","sender_id":"pipedrive8","conversation_id":"<my-unique-room-id>","channel_id":"<my-unique-channel-id>","created_at":"2024-01-27T17:15:47.438Z","message":"test message","status":"sent","attachments":[],"reply_by":null}
Access Token being sent to Pipedrive: <my-oauth-token>
Request data being sent to Pipedrive: {
  id: '<message-id>',
  sender_id: 'pipedrive8',
  conversation_id: '<my-unique-room-id>',
  channel_id: '<my-unique-channel-id>',
  created_at: '2024-01-27T17:15:47.438Z',
  message: 'test message',
  status: 'sent',
  attachments: [],
  reply_by: null
}
Pipedrive response: {
  success: false,
  error: 'Invalid payload to create a message',
  error_info: 'Please check the reference docs in https://developers.pipedrive.com/docs/api/v1',
  additional_data: { code: 'INVALID_RECEIVE_MESSAGE_PAYLOAD' }
}
Incoming request: POST /api/v1/channels/messages/receive
Headers: {"connection":"upgrade","host":"<host-address>","content-length":"311","user-agent":"curl/7.88.1","accept":"*/*","authorization":"Bearer <my-oauth-token>","content-type":"application/json"}
Body: {"id":"<message-id>","sender_id":"pipedrive8","conversation_id":"<my-unique-room-id>","channel_id":"<my-unique-channel-id>","created_at":"2024-01-27T17:15:47.438Z","message":"test message","status":"sent","attachments":[],"reply_by":null}
Access Token being sent to Pipedrive: <my-oauth-token>
Request data being sent to Pipedrive: {
  id: '<message-id>',
  sender_id: 'pipedrive8',
  conversation_id: '<my-unique-room-id>',
  channel_id: '<my-unique-channel-id>',
  created_at: '2024-01-27T17:15:47.438Z',
  message: 'test message',
  status: 'sent',
  attachments: [],
  reply_by: null
}
Pipedrive response: {
  success: true,
  data: {
    id: '<message-id>',
    sender_id: 'pipedrive8',
    conversation_id: '<my-unique-room-id>',
    channel_id: 'fc57c0e5-1b3c-4a64-ad62-d40bf5adc5d0',
    created_at: '2024-01-27T17:15:47.438Z',
    message: 'test message',
    status: 'sent',
    attachments: [],
    reply_by: null
  },
  additional_data: {}
}

As you can see, the requests are identical, but the Pipedrive response differs based on the method used. Any ideas as to why this might be the case? I’m sorry if the question is not clear enough.

Alternatively, I tried posting messasge received events via axios but that also failed, so I did my best to mimic the headers. I’ve also tried using api_token in my request URL instead of OAuth 2.0 token in the header for authorization but that produced another error.

Hey, please check created_at value you are sending with JavaScript, looks like the date you are sending is in the future. Could be caused by timezone - you should send an UTC date, otherwise your time might be ahead.