This line in the script above by Q:
api.Entity(fPrimary).Data(fHeaderField[f]).Update(fData);
Will update your data BUT BE CAREFUL it will overwrite any changes to custom field data you have made inside of SambaPOS. So you have everything you need for Updates if that what you wish to do.