Via OctoPrint

Check the Marlin documentation – https://marlinfw.org/docs/gcode/M303.html

Nice guide linked – https://all3dp.com/2/3d-printer-pid-tuning/

Here is the command I use

M303 E0 S210 C5

M303 = gcode for PID tune

E0 = 1st extruder

S210 = nozzle temperature 210

C5 = 5 cycles

Now use the output set the new values. In my case, the values were

Recv: #define DEFAULT_Kp 18.70
Recv: #define DEFAULT_Ki 1.32
Recv: #define DEFAULT_Kd 66.19

The command to set these values is 
M301 P18.7 I1.32 D66.19

Now use M500 to save the configuration

M500

PID Tune the Bed

M303 E-1 S60 C10 U1

U1 replaces your existing PID values for your heat bed