# Add an API POST https://api.example.com/v1/plants Content-Type: application/json This is a sample endpoint. If you've added your OpenAPI spec, your API reference is building now. Check GitHub Actions and refresh when complete. Reference: https://docs.askelephant.ai/api-reference/plant-store-api/plants/add-plant ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Add an API version: endpoint_plants.addPlant paths: /plants: post: operationId: add-plant summary: Add an API description: >- This is a sample endpoint. If you've added your OpenAPI spec, your API reference is building now. Check GitHub Actions and refresh when complete. tags: - - subpackage_plants parameters: [] responses: '201': description: Plant successfully added content: application/json: schema: $ref: '#/components/schemas/PlantResponse' '400': description: Invalid input content: {} requestBody: description: Plant to add content: application/json: schema: $ref: '#/components/schemas/PlantRequest' components: schemas: PlantRequestWateringFrequency: type: string enum: - value: daily - value: weekly - value: biweekly - value: monthly PlantRequestSunlight: type: string enum: - value: direct - value: indirect - value: shade PlantRequest: type: object properties: name: type: string description: Display name for the plant species: type: string description: Scientific name of the plant wateringFrequency: $ref: '#/components/schemas/PlantRequestWateringFrequency' description: How often the plant needs water sunlight: $ref: '#/components/schemas/PlantRequestSunlight' description: Sunlight requirements required: - name - species PlantResponseWateringFrequency: type: string enum: - value: daily - value: weekly - value: biweekly - value: monthly PlantResponseSunlight: type: string enum: - value: direct - value: indirect - value: shade PlantResponse: type: object properties: id: type: string description: Unique identifier for the plant name: type: string description: Display name for the plant species: type: string description: Scientific name of the plant wateringFrequency: $ref: '#/components/schemas/PlantResponseWateringFrequency' sunlight: $ref: '#/components/schemas/PlantResponseSunlight' createdAt: type: string format: date-time description: When the plant was added ``` ## SDK Code Examples ```python Boston Fern created import requests url = "https://api.example.com/v1/plants" headers = {"Content-Type": "application/json"} response = requests.post(url, headers=headers) print(response.json()) ``` ```javascript Boston Fern created const url = 'https://api.example.com/v1/plants'; 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 Boston Fern created package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.example.com/v1/plants" 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 Boston Fern created require 'uri' require 'net/http' url = URI("https://api.example.com/v1/plants") 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 Boston Fern created import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/v1/plants") .header("Content-Type", "application/json") .asString(); ``` ```php Boston Fern created request('POST', 'https://api.example.com/v1/plants', [ 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Boston Fern created using RestSharp; var client = new RestClient("https://api.example.com/v1/plants"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); IRestResponse response = client.Execute(request); ``` ```swift Boston Fern created import Foundation let headers = ["Content-Type": "application/json"] let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/plants")! 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 Jade Plant created import requests url = "https://api.example.com/v1/plants" headers = {"Content-Type": "application/json"} response = requests.post(url, headers=headers) print(response.json()) ``` ```javascript Jade Plant created const url = 'https://api.example.com/v1/plants'; 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 Jade Plant created package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.example.com/v1/plants" 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 Jade Plant created require 'uri' require 'net/http' url = URI("https://api.example.com/v1/plants") 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 Jade Plant created import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/v1/plants") .header("Content-Type", "application/json") .asString(); ``` ```php Jade Plant created request('POST', 'https://api.example.com/v1/plants', [ 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Jade Plant created using RestSharp; var client = new RestClient("https://api.example.com/v1/plants"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); IRestResponse response = client.Execute(request); ``` ```swift Jade Plant created import Foundation let headers = ["Content-Type": "application/json"] let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/plants")! 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 Boston Fern import requests url = "https://api.example.com/v1/plants" payload = { "name": "Boston Fern", "species": "Nephrolepis exaltata", "wateringFrequency": "daily", "sunlight": "indirect" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Add a Boston Fern const url = 'https://api.example.com/v1/plants'; const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"name":"Boston Fern","species":"Nephrolepis exaltata","wateringFrequency":"daily","sunlight":"indirect"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Add a Boston Fern package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/v1/plants" payload := strings.NewReader("{\n \"name\": \"Boston Fern\",\n \"species\": \"Nephrolepis exaltata\",\n \"wateringFrequency\": \"daily\",\n \"sunlight\": \"indirect\"\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 Boston Fern require 'uri' require 'net/http' url = URI("https://api.example.com/v1/plants") 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\": \"Boston Fern\",\n \"species\": \"Nephrolepis exaltata\",\n \"wateringFrequency\": \"daily\",\n \"sunlight\": \"indirect\"\n}" response = http.request(request) puts response.read_body ``` ```java Add a Boston Fern import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/v1/plants") .header("Content-Type", "application/json") .body("{\n \"name\": \"Boston Fern\",\n \"species\": \"Nephrolepis exaltata\",\n \"wateringFrequency\": \"daily\",\n \"sunlight\": \"indirect\"\n}") .asString(); ``` ```php Add a Boston Fern request('POST', 'https://api.example.com/v1/plants', [ 'body' => '{ "name": "Boston Fern", "species": "Nephrolepis exaltata", "wateringFrequency": "daily", "sunlight": "indirect" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Add a Boston Fern using RestSharp; var client = new RestClient("https://api.example.com/v1/plants"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"Boston Fern\",\n \"species\": \"Nephrolepis exaltata\",\n \"wateringFrequency\": \"daily\",\n \"sunlight\": \"indirect\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Add a Boston Fern import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "name": "Boston Fern", "species": "Nephrolepis exaltata", "wateringFrequency": "daily", "sunlight": "indirect" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/plants")! 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() ``` ```python Add a Jade Plant import requests url = "https://api.example.com/v1/plants" payload = { "name": "Jade Plant", "species": "Crassula ovata", "wateringFrequency": "weekly", "sunlight": "direct" } headers = {"Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript Add a Jade Plant const url = 'https://api.example.com/v1/plants'; const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"name":"Jade Plant","species":"Crassula ovata","wateringFrequency":"weekly","sunlight":"direct"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go Add a Jade Plant package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/v1/plants" payload := strings.NewReader("{\n \"name\": \"Jade Plant\",\n \"species\": \"Crassula ovata\",\n \"wateringFrequency\": \"weekly\",\n \"sunlight\": \"direct\"\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 Jade Plant require 'uri' require 'net/http' url = URI("https://api.example.com/v1/plants") 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\": \"Jade Plant\",\n \"species\": \"Crassula ovata\",\n \"wateringFrequency\": \"weekly\",\n \"sunlight\": \"direct\"\n}" response = http.request(request) puts response.read_body ``` ```java Add a Jade Plant import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/v1/plants") .header("Content-Type", "application/json") .body("{\n \"name\": \"Jade Plant\",\n \"species\": \"Crassula ovata\",\n \"wateringFrequency\": \"weekly\",\n \"sunlight\": \"direct\"\n}") .asString(); ``` ```php Add a Jade Plant request('POST', 'https://api.example.com/v1/plants', [ 'body' => '{ "name": "Jade Plant", "species": "Crassula ovata", "wateringFrequency": "weekly", "sunlight": "direct" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp Add a Jade Plant using RestSharp; var client = new RestClient("https://api.example.com/v1/plants"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"Jade Plant\",\n \"species\": \"Crassula ovata\",\n \"wateringFrequency\": \"weekly\",\n \"sunlight\": \"direct\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift Add a Jade Plant import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "name": "Jade Plant", "species": "Crassula ovata", "wateringFrequency": "weekly", "sunlight": "direct" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/plants")! 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() ```