How I add product attributes and variants in WordPress using rest api?

I'm trying to create a product using WordPress RestApi.

I'm following this documentation but in NodeJS I use the type as variable but it will push only simple product and I'm using category id but in my product category no product found.

I'm Drooping the sample code

 for (let i = 0; i < result.length; i++) { //loping data

  api.post("products", {   //woo api
    name: result[i].product_name,
    type: "variable",   
    stock_status: "instock",
    price: result[i].product_price,
    regular_price : result[i].product_price,
    sale_price : "",
    sku: result[i].product_sku,
    size: result[i].product_size,
    color: result[i].product_color,
    images: [
      {
        src: result[i].preview_image1
      },
      {
        src: result[i].preview_image2
      },
      {
        src: result[i].preview_image3
      }
    ],
    categories: [
      {
        id: 200
      }
    ],
    attributes: [
      {
        id: 2,
        position: 0,
        visible: true,
        variation: true,
        options: [
          "Black",
          "Green"
        ]
      },
      {
        name: "Size",
        position: 0,
        visible: false,
        variation: true,
        options: [
          "S",
          "M"
        ]
      }
    ],
    default_attributes: [
      {
        id: 2,
        option: "Black"
      },
      {
        name: "Size",
        option: "S"
      }
    ]

  })
    .then((response) => {
      // Successful request
    console.log("post data response")
      console.log("Response Data:", response.data);
    })
    .catch((error) => {
      // Invalid request, for 4xx and 5xx statuses
      console.log("post data error response")
      console.log("Response Data:", error.response.data);
    })
    .finally(() => {
      // Always executed.
    });



}

I think there is something wrong in the above code.