how apply discount buy x and get y using api?

I would like to apply a discount code buy x get y, how could I apply it via api when creating the order?