flatten api