Pass 2 parameters from API to arduino

I can pass 2 parameters to Arduino. This code below is a simple API that I set up in asp.net, via postman I send "a" lights up, "b" turns off led 13.

public string PostLed(Led led)
        {
            Porta.Open();
            String test = Convert.ToString(led.led);
            
            if (test == "a")
            {
                Port.Write(test);
                list.Add(led);
                Port.Close();
                return "ON";
            }else if (teste == "b")
            {
                Port.Write(test);
                list.Add(led);
                Port.Close();
                return "OFF"; 
            } else
            {
                return "Invalid value";
            }
        }

This code below is very simple.

int led = 13;

 void setup()   {

  Serial.begin(9600);

  pinMode(led, OUTPUT);
  
}

void loop()
{
char caracter;
caracter = Serial.read();

if(caracter == 'a')
{
 digitalWrite(led, 1);
 Serial.write("ON");
}
else

if(caracter == 'b')
{
 digitalWrite(led, 0);
 Serial.write("OFF");
} 
}

But what I need to send to my arduino is 2 parameters (port and stage). Port.Write (port, stage). Because I want to send a post to port X, for example. I'll go for about 3 leds on my arduino then I'll send to the postman example: 4, "a". but port 4 does not exist would create the data, but would not light anything, but if I modified with PUT to port 3 would light, and if changing to "b" would erase led 3.

char caracter;
int led2 = 2;
int led3 = 3;
void setup()
{

  Serial.begin(9600);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  Serial.println("Enter the port");
}
void loop()
{
  if (Serial.available())
  { 
      char port = Serial.read();
      switch (port) {
        case '1':
          Serial.write("Enter ON or OFF");
          caracter = Serial.read();
          if(caracter == 'a')
          {
            digitalWrite(led2, HIGH);
            Serial.println("ON");
          }else if(caracter == 'p')
          {
           digitalWrite(led2, LOW);
           Serial.println("OFF");
          } else{
            
            Serial.println("exited");
            }
          
          
        break;
        case '2':
          Serial.println("entrou 12");
          break;
      }
  }
}

I created this code above but I am completely lost for not having practice with arduino programming. I don't know if I can pass two parameters as I explained above. could someone help me with this code?

You need to restructure your code. Currently, your program does not work because serial is very slow; so Serial.read() can return an invalid respond (indicating no more arrival data) while in fact, the next piece of data can arrive 1us later. If this happens, the whole parsing will be messed up. There are two approaches to this: 1) Read the whole data stream before starting to parse it. 2) You can parse individual piece but you need to wit in a while() loop to wait for the next piece.

Have a look at the 3rd example in Serial Input Basics.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

There is also a parse example to illustrate how to extract numbers from the received text.

…R