# Add a new plant to the store POST https://api.plantstore.dev/v3/plant Content-Type: application/json Reference: https://plantstore.dev/api-reference/plant-store-api/plants/add-plant ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Add a new plant to the store version: endpoint_plant.addPlant paths: /plant: post: operationId: add-plant summary: Add a new plant to the store tags: - - subpackage_plant parameters: [] responses: '200': description: Plant successfully added content: application/json: schema: $ref: '#/components/schemas/PlantResponse' '405': description: Invalid input content: {} requestBody: description: Details of the plant to add content: application/json: schema: $ref: '#/components/schemas/Plant' components: schemas: PlantStatus: type: string enum: - value: available - value: pending - value: sold Plant: type: object properties: name: type: string category: type: string tags: type: array items: type: string status: $ref: '#/components/schemas/PlantStatus' PlantResponse: type: object properties: id: type: integer name: type: string status: type: string tags: type: array items: type: string ``` ## SDK Code Examples ```python Successful Plant Addition import requests url = "https://api.plantstore.dev/v3/plant" headers = {"Content-Type": "application/json"} response = requests.post(url, headers=headers) print(response.json()) ``` ```javascript Successful Plant Addition const url = 'https://api.plantstore.dev/v3/plant'; const options = {method: 'POST', headers: {'Content-Type': 'application/json'}, body: undefined}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Successful Plant Addition package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.plantstore.dev/v3/plant" req, _ := http.NewRequest("POST", url, nil) req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby Successful Plant Addition require 'uri' require 'net/http' url = URI("https://api.plantstore.dev/v3/plant") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' response = http.request(request) puts response.read_body ``` ```java Successful Plant Addition HttpResponse response = Unirest.post("https://api.plantstore.dev/v3/plant") .header("Content-Type", "application/json") .asString(); ``` ```php Successful Plant Addition request('POST', 'https://api.plantstore.dev/v3/plant', [ 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Successful Plant Addition var client = new RestClient("https://api.plantstore.dev/v3/plant"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); IRestResponse response = client.Execute(request); ``` ```swift Successful Plant Addition import Foundation let headers = ["Content-Type": "application/json"] let request = NSMutableURLRequest(url: NSURL(string: "https://api.plantstore.dev/v3/plant")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` ```python Add a Fern Plant import requests url = "https://api.plantstore.dev/v3/plant" payload = { "name": "Fern", "category": "Indoor", "tags": ["green", "leafy"], "status": "available" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Add a Fern Plant const url = 'https://api.plantstore.dev/v3/plant'; const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"name":"Fern","category":"Indoor","tags":["green","leafy"],"status":"available"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Add a Fern Plant package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.plantstore.dev/v3/plant" payload := strings.NewReader("{\n \"name\": \"Fern\",\n \"category\": \"Indoor\",\n \"tags\": [\n \"green\",\n \"leafy\"\n ],\n \"status\": \"available\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby Add a Fern Plant require 'uri' require 'net/http' url = URI("https://api.plantstore.dev/v3/plant") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = 'application/json' request.body = "{\n \"name\": \"Fern\",\n \"category\": \"Indoor\",\n \"tags\": [\n \"green\",\n \"leafy\"\n ],\n \"status\": \"available\"\n}" response = http.request(request) puts response.read_body ``` ```java Add a Fern Plant HttpResponse response = Unirest.post("https://api.plantstore.dev/v3/plant") .header("Content-Type", "application/json") .body("{\n \"name\": \"Fern\",\n \"category\": \"Indoor\",\n \"tags\": [\n \"green\",\n \"leafy\"\n ],\n \"status\": \"available\"\n}") .asString(); ``` ```php Add a Fern Plant request('POST', 'https://api.plantstore.dev/v3/plant', [ 'body' => '{ "name": "Fern", "category": "Indoor", "tags": [ "green", "leafy" ], "status": "available" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Add a Fern Plant var client = new RestClient("https://api.plantstore.dev/v3/plant"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"Fern\",\n \"category\": \"Indoor\",\n \"tags\": [\n \"green\",\n \"leafy\"\n ],\n \"status\": \"available\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Add a Fern Plant import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "name": "Fern", "category": "Indoor", "tags": ["green", "leafy"], "status": "available" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.plantstore.dev/v3/plant")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```