We are attempting to use the Front API Messages -> Import Message.
Â
All of the documentation is shown with using JSON encoding with a note that requests using attachments must use form-data encoding.
Â
We have the following request that is working when using JSON encoding.
curl --location --request POST 'https://api2.frontapp.com/inboxes/inb_INBOX/imported_messages' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer TOKEN' \
--header 'Content-Type: text/plain' \
--data-raw '{
    "sender": {
        "name": "Tester",
        "handle": tester@example.com
    },
    "to": m],
    "body": "Test Message From Agent",
    "external_id": "12345",
    "created_at": 1654708989,
    "type": "sms",
    "metadata": {
        "thread_ref": "777",
        "is_inbound": false,
        "should_skip_rules": true
    },
    "attachments": e]
}'
Â
When executed, we get a 200 – OK message.
Â
However, to get attachments to work, I have to adjust the call to use the form-data encoding. The documentation has a statement about form-data encoding:
Â
File Upload
When you want to send files through the API, your request needs to be sent using the Content-Type HTTP header set to multipart/form-data.
The JSON data you would normally send in the request body needs to be split in multiple form fields (one for each property) named after the property key. If the property is an array, the name should include the index of the data (ie: {"to": )email1@example.com, email1@example.com]} would be split in two fields named toi0], tom1]). https://dev.frontapp.com/reference/introduction#file-upload
Â
With the note above, we understand the syntax of arrays and how to convert those. However, the documentation fails to mention how to convert between nested objects. I would assume that we would use dot-delimitator or append underscores. Neither pattern appears to work.
curl --location --request POST 'https://api2.frontapp.com/inboxes/inb_INBOX/imported_messages' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer TOKEN' \
--form 'sender.name="Tester"' \
--form 'sender.handle=tester@example.com' \
--form 'tor0]=recipient@example.com' \
--form 'body="Test Message from Postman"' \
--form 'external_id="12345"' \
--form 'created_at="1654708989"' \
--form 'type="sms"' \
--form 'metadata_thread_ref="777' \
--form 'metadata_is_inbound="false"' \
--form 'metadata_should_skip_rules="true"'
Â
For sender, I have attempted the dot-notation and for metadata, I have attempted using underscores. Either method retures back the following error:
{
    "_error": {
        "status": 400,
        "title": "Bad request",
        "message": "Body did not satisfy requirements",
        "details":Â
            "body.sender: missing",
            "body.metadata: missing"
        ]
    }
}
Â
What is the correct syntax for sending over nested data structures?