Partial version of migration to api. Still not working.
Some fixes in namespaces, but still a work in progress.