Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for inbound webhooks that use form data #1998

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

BolajiOlajide
Copy link
Contributor

Closes #1987

This PR adds support for inbound webhooks that send data via form-data. It defaults to JSON when the content type isn't multipart/form-data to avoid introducing a breaking change. As time goes one, we'll want to add support for www-url-encoded.

CleanShot 2024-05-07 at 01 52 44@2x
CleanShot 2024-05-07 at 01 52 38@2x

@CLAassistant
Copy link

CLAassistant commented May 7, 2024

CLA assistant check
All committers have signed the CLA.

@jirevwe
Copy link
Collaborator

jirevwe commented May 15, 2024

Shouldn't the JOSN payload received at the endpoint be this?

{
    "name": "legbegbe",
    "error": "no error",
    "status": "success"
}

@BolajiOlajide
Copy link
Contributor Author

BolajiOlajide commented May 15, 2024

Shouldn't the JOSN payload received at the endpoint be this?

{
    "name": "legbegbe",
    "error": "no error",
    "status": "success"
}

@jirevwe You're right. However, I did it that way because the return type of FormData is actually a map of the structure type Values map[string][]string. I left it that way to preserve the parsing incase something changes, WDYT?

@BolajiOlajide
Copy link
Contributor Author

@jirevwe Updated.

CleanShot 2024-05-17 at 01 51 30@2x
CleanShot 2024-05-17 at 01 51 21@2x

@jirevwe
Copy link
Collaborator

jirevwe commented May 22, 2024

It works but struggles with nested values.

This

curl -L -X POST 'http://localhost:5005/ingest/bRR0NEtU6sw0ZeD3' \
-H 'Authorization: Bearer CO.Ci4jlWTc4gJeWnXZ.NatfMfQM3Ks78Y3Ibm6XKqwCLS1eG35kNwcRe6jd42mOc0EdzBu5JCl9qZHJhSBE' \
-F 'endpoint_id="01HS16E631RTHZ2EN4K54ZFC9H"' \
-F 'data[event_type]="created"' \
-F 'data[name]="digital"' \
-F 'data[email]="Aurelie6@hotmail.com"' \
-F 'data[age]="10"' \
-F 'custom_headers[id]="2aff13ec-a373-4218-9fde-0c1328801291"' \
-F 'custom_headers[timestamp]="2024-03-20T06:56:06.991Z"' \
-F 'custom_headers[x-tenant-id]="xpi"' \
-F 'idempotency_key="test123"' \
-F 'event_type="created"'

comes out as

{
    "data": {
        "data[age]": "10",
        "data[name]": "auxiliary",
        "event_type": "created",
        "data[email]": "Alexa86@gmail.com",
        "endpoint_id": "01HS16E631RTHZ2EN4K54ZFC9H",
        "idempotency_key": "test123",
        "data[event_type]": "created",
        "custom_headers[id]": "2aff13ec-a373-4218-9fde-0c1328801291",
        "custom_headers[timestamp]": "2024-03-20T06:56:06.991Z",
        "custom_headers[x-tenant-id]": "xpi"
    },
    "event_type": "created",
    "endpoint_id": "01HS6EX2KC8FMN8NDTMNKQQN13",
    "custom_headers": {
        "header": "valve"
    }
}

@BolajiOlajide
Copy link
Contributor Author

@jirevwe

Are you sure you're on the correct branch, I tried this using the same payload and I get this:
CleanShot 2024-05-24 at 10 28 13@2x
CleanShot 2024-05-24 at 10 29 11@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request]: Add support for inbound webhooks that use form data
3 participants