# Update an existing plant PUT https://api.plantstore.dev/v3/plant Content-Type: application/json Reference: https://plantstore.dev/api-reference/plant-store-api/plants/update-plant ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Update an existing plant version: endpoint_plant.updatePlant paths: /plant: put: operationId: update-plant summary: Update an existing plant tags: - - subpackage_plant parameters: [] responses: '200': description: Plant successfully updated content: application/json: schema: $ref: '#/components/schemas/PlantResponse' '400': description: Invalid ID supplied content: {} '404': description: Plant not found content: {} requestBody: description: Updated details of the plant 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 Update import requests url = "https://api.plantstore.dev/v3/plant" headers = {"Content-Type": "application/json"} response = requests.put(url, headers=headers) print(response.json()) ``` ```javascript Successful Plant Update const url = 'https://api.plantstore.dev/v3/plant'; const options = {method: 'PUT', 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 Update package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.plantstore.dev/v3/plant" req, _ := http.NewRequest("PUT", 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 Update 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::Put.new(url) request["Content-Type"] = 'application/json' response = http.request(request) puts response.read_body ``` ```java Successful Plant Update HttpResponse response = Unirest.put("https://api.plantstore.dev/v3/plant") .header("Content-Type", "application/json") .asString(); ``` ```php Successful Plant Update request('PUT', 'https://api.plantstore.dev/v3/plant', [ 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Successful Plant Update var client = new RestClient("https://api.plantstore.dev/v3/plant"); var request = new RestRequest(Method.PUT); request.AddHeader("Content-Type", "application/json"); IRestResponse response = client.Execute(request); ``` ```swift Successful Plant Update 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 = "PUT" 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 Update plant status import requests url = "https://api.plantstore.dev/v3/plant" payload = { "name": "Fern", "category": "Indoor", "tags": ["green", "leafy"], "status": "sold" } headers = {"Content-Type": "application/json"} response = requests.put(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Update plant status const url = 'https://api.plantstore.dev/v3/plant'; const options = { method: 'PUT', headers: {'Content-Type': 'application/json'}, body: '{"name":"Fern","category":"Indoor","tags":["green","leafy"],"status":"sold"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Update plant status 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\": \"sold\"\n}") req, _ := http.NewRequest("PUT", 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 Update plant status 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::Put.new(url) request["Content-Type"] = 'application/json' request.body = "{\n \"name\": \"Fern\",\n \"category\": \"Indoor\",\n \"tags\": [\n \"green\",\n \"leafy\"\n ],\n \"status\": \"sold\"\n}" response = http.request(request) puts response.read_body ``` ```java Update plant status HttpResponse response = Unirest.put("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\": \"sold\"\n}") .asString(); ``` ```php Update plant status request('PUT', 'https://api.plantstore.dev/v3/plant', [ 'body' => '{ "name": "Fern", "category": "Indoor", "tags": [ "green", "leafy" ], "status": "sold" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Update plant status var client = new RestClient("https://api.plantstore.dev/v3/plant"); var request = new RestRequest(Method.PUT); 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\": \"sold\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Update plant status import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "name": "Fern", "category": "Indoor", "tags": ["green", "leafy"], "status": "sold" ] 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 = "PUT" 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() ```