I dunno... since the sun is directly at the center of the global coordinate system, I don't bother... I just use oapiGetGlobalPos() (well, actually, I've just used it for vessels, so I use VESSEL2::GetGlobalPos()).
I guess if you need to find the radius of the sun or something... yeah, I think oapiGetObjectByName("sun") should work. (Hmmm... I wonder if the sun always has the same index...)