That data should be in the backups the either iTunes or iCloud makes. Just restore form the last backup
For how to restore:
Use iTunes to restore your iPhone, iPad, or iPod to factory settings
To restore from backup see:
Restore your device from an iCloud or iTunes backup - Apple Support
If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
You can redownload most iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store