-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Can you provide examples on how to parse webhook request payload. We are using webhookPayloadFromJSON.
I am trying to use it in our webhook, but it fails every time. Seems like the problem is with webhook payload or underlying validation schema. Schema expects values to be optional, but they return null. Union does not work as expected. See example below.
This is test webhook from Shippo portal.
This is webhook payload we received
{
"event": "transaction_created",
"test": true,
"data": {
"object_state": "VALID",
"status": "SUCCESS",
"object_created": "2025-09-02T14:16:59.927Z",
"object_updated": "2025-09-02T14:17:02.115Z",
"object_id": "f0c8f73923b44ee1b2cef3b0037ea281",
"object_owner": "[email protected]",
"test": true,
"rate": "f775fb0e03b347daa14355e1626649b2",
"tracking_number": "1ZXXXXXXXXXXXXXXXX",
"tracking_status": "UNKNOWN",
"eta": null,
"tracking_url_provider": "omitted...",
"label_url": "omitted...",
"commercial_invoice_url": null,
"messages": [
{
"source": "UPS",
"code": "121943",
"text": "Invalid Date. Changed to today's date"
}
],
"order": null,
"metadata": "",
"parcel": "4999144a37ca47c4a24f474709748e34",
"billing": {
"payments": []
}
}
}and this is our code for processing
const validationResult = webhookPayloadFromJSON(body);
console.log("validationResult ", validationResult );This is the output we receive:
{
"ok": false,
"error": {
"SDKValidationError": Failed to parse 'WebhookPayload' from JSON: [
{
"code": "invalid_union",
"unionErrors": [
{
"issues": [
{
"code": "invalid_type",
"expected": "string",
"received": "undefined",
"path": [
"data",
"carrier"
],
"message": "Required"
},
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"data",
"eta"
],
"message": "Expected string, received null"
},
{
"code": "invalid_type",
"expected": "string",
"received": "object",
"path": [
"data",
"messages",
0
],
"message": "Expected string, received object"
},
{
"code": "invalid_type",
"expected": "array",
"received": "undefined",
"path": [
"data",
"tracking_history"
],
"message": "Required"
},
{
"code": "invalid_type",
"expected": "object",
"received": "string",
"path": [
"data",
"tracking_status"
],
"message": "Expected object, received string"
},
{
"received": "transaction_created",
"code": "invalid_literal",
"expected": "track_updated",
"path": [
"event"
],
"message": "Invalid literal value, expected \"track_updated\""
}
],
"name": "ZodError"
},
{
"issues": [
{
"code": "invalid_type",
"expected": "string",
"received": "object",
"path": [
"data"
],
"message": "Expected string, received object"
},
{
"received": "transaction_created",
"code": "invalid_literal",
"expected": "batch_created",
"path": [
"event"
],
"message": "Invalid literal value, expected \"batch_created\""
}
],
"name": "ZodError"
},
{
"issues": [
{
"code": "invalid_type",
"expected": "string",
"received": "object",
"path": [
"data"
],
"message": "Expected string, received object"
},
{
"received": "transaction_created",
"code": "invalid_literal",
"expected": "batch_purchased",
"path": [
"event"
],
"message": "Invalid literal value, expected \"batch_purchased\""
}
],
"name": "ZodError"
},
{
"issues": [
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"data",
"commercial_invoice_url"
],
"message": "Expected string, received null"
},
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"data",
"eta"
],
"message": "Expected string, received null"
}
],
"name": "ZodError"
},
{
"issues": [
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"data",
"commercial_invoice_url"
],
"message": "Expected string, received null"
},
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"data",
"eta"
],
"message": "Expected string, received null"
},
{
"received": "transaction_created",
"code": "invalid_literal",
"expected": "transaction_updated",
"path": [
"event"
],
"message": "Invalid literal value, expected \"transaction_updated\""
}
],
"name": "ZodError"
}
],
"path": [],
"message": "Invalid input"
}
]
}
}adamknipfer
Metadata
Metadata
Assignees
Labels
No labels