Unable to get center of the screen coordinates

I have a set of coordinates return from an api. Thereafter, I set camera view with the following codes:

viewer.scene.camera.setView({
		destination:  
                     Cesium.Cartesian3.fromDegrees(103.84958233542338,1.3669641300494784, 100),
		orientation: new Cesium.HeadingPitchRoll(0, 0, 0),
		endTransform: Cesium.Matrix4.IDENTITY
});

Now, I want to get center of the screen and return its coordinates. But I am unable to do so. Any idea why?

var windowPosition = new Cesium.Cartesian2(viewer.container.clientWidth / 2, viewer.container.clientHeight / 2);
      var pickRay = viewer.scene.camera.getPickRay(windowPosition);
      var pickPosition = viewer.scene.globe.pick(pickRay, viewer.scene);
      var pickPositionCartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(pickPosition);
      var apilon = pickPositionCartographic.longitude * (180 / Math.PI);
      var apilat = pickPositionCartographic.latitude * (180 / Math.PI);

The code you posted worked for me. Are you getting an error?

I am getting the error “cartisean is required”. I am not sure is it the Lat and Lon format returned from an api to set the camera position. Thereafter, I would like to use the new camera position to get the center of the screen.

Ok, the reason it doesn’t work in this particular case is the center of the screen is a point in the sky, which has no 3D world position.

If you just need to get the camera position, use viewer.camera.position.

After using viewer.camera.position, how can I convert it back to 2D format for lon& lat to parse into my API URL.

Convert from Cartesian3 to longitude/latitude: https://cesium.com/docs/cesiumjs-ref-doc/Cartographic.html?classFilter=Cartogr#.fromCartesian