Date management in custom apps

Hi,
I’m working on a Custom App to be reviewed for global publication.
In best practice docs, it says we should parse and format dates in payloads.
ref: https://docs.integromat.com/apps/best-practices/processing-of-input-parameters#date-parameters

In my case (a subscription/payment management app), I have multiple dates at different places in the payload. Did someone find a way to format/parse multiple dates without having to rewrite the entire payload (which is also a bad practice accord to the docs).

Note: the API technically accepts ISO-8601 date format so I don’t really to to format/parse it but I’m curious on how to do it.

sample simplified payload:

{
  "data": {
    "payer": {
      "email": "john.doe@example.com",
      "country": "FRA",
      "firstName": "John",
      "lastName": "Doe"
    },
    "items": [
      {
        "name": "Adhésion football",
        "priceCategory": "Fixed",
        "qrCode": "MjI3MDc6NjM4NTYyMDkwMzQwODk4MzM1",
        "id": 22707,
        "amount": 6000,
        "type": "Payment",
        "state": "Processed"
      }
    ],
    "payments": [
      {
        "cashOutState": "Transfered",
        "paymentReceiptUrl": "https://www.helloasso-sandbox.com/associations/bordeauxchess/checkout/paiement-attestation/22707",
        "id": 15222,
        "amount": 1000,
        "date": "2024-07-10T11:50:48.8859116+02:00",
        "paymentMeans": "Card",
        "installmentNumber": 1,
        "state": "Authorized",
        "meta": {
          "createdAt": "2024-07-10T11:50:34.0898335+02:00",
          "updatedAt": "2024-07-10T11:50:48.9171637+02:00"
        },
        "refundOperations": []
      },
      {
        "id": 15223,
        "amount": 2000,
        "date": "2024-09-25T00:00:00+02:00",
        "paymentMeans": "Card",
        "installmentNumber": 2,
        "state": "Pending",
        "meta": {
          "createdAt": "2024-07-10T11:50:34.0898335+02:00",
          "updatedAt": "2024-07-10T11:50:49.1033333+02:00"
        },
        "refundOperations": []
      },
      {
        "id": 15224,
        "amount": 2000,
        "date": "2024-10-25T00:00:00+02:00",
        "paymentMeans": "Card",
        "installmentNumber": 3,
        "state": "Pending",
        "meta": {
          "createdAt": "2024-07-10T11:50:34.0898335+02:00",
          "updatedAt": "2024-07-10T11:50:49.11+02:00"
        },
        "refundOperations": []
      },
      {
        "id": 15225,
        "amount": 1000,
        "date": "2024-11-25T00:00:00+01:00",
        "paymentMeans": "Card",
        "installmentNumber": 4,
        "state": "Pending",
        "meta": {
          "createdAt": "2024-07-10T11:50:34.0898335+02:00",
          "updatedAt": "2024-07-10T11:50:49.1133333+02:00"
        },
        "refundOperations": []
      }
    ],
    "amount": {
      "total": 6000,
      "vat": 0,
      "discount": 0
    },
    "id": 22707,
    "date": "2024-07-10T11:50:49.0890389+02:00",
    "formSlug": "default",
    "formType": "Checkout",
    "organizationName": "bordeauxchess",
    "organizationSlug": "bordeauxchess",
    "organizationType": "Association1901Rig",
    "organizationIsUnderColucheLaw": false,
    "checkoutIntentId": 24768,
    "meta": {
      "createdAt": "2024-07-10T11:50:34.0898335+02:00",
      "updatedAt": "2024-07-10T11:50:49.0890389+02:00"
    },
    "isAnonymous": false,
    "isAmountHidden": false
  },
  "eventType": "Order",
  "metadata": {
    "id": 75698555
  }
}

Finally start finding a solution for request bodies - same idea should apply to responses:

	"body": {
		"{{...}}": "{{omit(parameters, 'metadata', 'payer')}}",
		"payer": {
			"{{...}}": "{{omit(parameters.payer, 'dateOfBirth')}}",
			"dateOfBirth": "{{formatDate(parameters.payer.dateOfBirth, 'YYYY-MM-DD')}}"
		}
	},
1 Like