Question

Body Did Not Satisfy Requirements -- Incoming Messages on Custom Channel

  • 11 April 2024
  • 3 replies
  • 22 views

I’m trying to receive incoming messages over a custom channel. I created the custom channel in my Front instance and copied the channel id from the Incoming API Endpoint. In order to test, I added the necessary values on the API docs page and gave it a try:

➜  ~ curl --request POST \
     --url https://api2.frontapp.com/channels/cha_g65ng/incoming_messages \
     --header 'accept: application/json' \
     --header 'authorization: Bearer XXXXX' \
     --header 'content-type: application/json' \
     --data '
{
  "subject": "Sample Subject",
  "body": "Sample Body"
}
'
{"_error":{"status":400,"title":"Bad request","message":"Body did not satisfy requirements","details":["body.sender: missing"]}}

I tried a couple of modifications hoping to back into a solution, but still the same general error:

➜  ~ curl --request POST \
     --url https://api2.frontapp.com/channels/cha_g65ng/incoming_messages \
     --header 'accept: application/json' \
     --header 'authorization: Bearer XXXXX' \
     --header 'content-type: application/json' \
     --data '
{
  "body": {
        "body": "Sample Body",
        "sender": "Tim Kral"
  },
  "subject": "Sample Subject"
}
'
{"_error":{"status":400,"title":"Bad request","message":"Body did not satisfy requirements","details":["body.sender: missing","body.body: should be a string"]}}

And:

➜  ~ curl --request POST \
     --url https://api2.frontapp.com/channels/cha_g65ng/incoming_messages \
     --header 'accept: application/json' \
     --header 'authorization: Bearer XXXXX' \
     --header 'content-type: application/json' \
     --data '
{
  "body": "Sample Body",
  "body_sender": "Tim Kral",
  "subject": "Sample Subject"
}
'
{"_error":{"status":400,"title":"Bad request","message":"Body did not satisfy requirements","details":["body.sender: missing"]}}

Any help is greatly appreciated.


3 replies

Badge +1

Hi @timkral , 

 

To send payloads with nested data structures and attachments, you'll need to set the Content-Type: multipart/form-data header, and send nested structures like so:

curl -X POST 'https://api2.frontapp.com/inboxes/inb_123/imported_messages' \

-H 'Authorization: Bearer API_TOKEN' \

-H 'Content-Type: multipart/form-data' \

--form 'external_id=8gfh9qh7qsadcqw7gfqfh7@mail.example.com' \

--form 'created_at=1619656054' \

--form 'sender[handle]=external.sender@example.com' \

--form 'sender[name]=External Sender' \

--form 'metadata[is_inbound]=true' \

--form 'metadata[is_archived]=false' \

--form 'to[]=front0@example.com' \

--form 'to[]=front1@example.com' \

--form 'body=MESSAGE_BODY' \

--form 'attachments[]=@/Users/me/Photos/cat.jpg' \

--form 'attachments[]=@/Users/me/Photos/dog.jpg'

 

I hope this is helpful - Please let me know if you have any further questions

 

--Molly

Hi @molly ,

 

Thanks for the response. I ended up figuring it out -- posting here in case others run into the same problem.

 

The issue is actually that the error message is confusing in that the term body has multiple meanings. There are actually two body elements -- the body field in the request payload and the body of the HTTP request itself. It finally dawned on me that I was interpreting the error message “body.sender: missing” to mean that I needed to embed a sender field within the body field like so:
{
  "body": {
        "body": "Sample Body",
        "sender": "Tim Kral"
  },
  "subject": "Sample Subject"
}

However, what the error is saying is that a required sender field is missing entirely from the HTTP body itself. So the correct payload needs to look like this:
{
  "body": "Sample Body",
  "subject": "Sample Subject",
  “sender”: {
    “name”: “Tim Kral”,
    “handle”: “timkral”
  }
}

That second payload got me past my issue.

-Tim

Badge +1

oh, this is great info, Tim! Thanks for the update!

Reply