I've found a simple way to do it without needing any code at all.
Open the Network panel in your browser
Select Fetch/XHR in the filters
Navigate to Integration > Microsoft Dynamics in the Admin panel in Marketo
Click "Edit" under Field Sync Details
Back in the Network panel a request named "getFieldsForSelection" will appear
Select it and hit "Preview"
Right-click on "entityFields" and select "Copy object"
Paste into an empy JSON file
All of the synced fields have the "selected" key marked as "true".
... View more