# Add Location Definitions POST https://api.trebellar.app/api/v2/locations Content-Type: application/json Reference: https://docs.trebellar.app/api-reference/api-resources/assets/add-locations ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: API version: 1.0.0 paths: /api/v2/locations: post: operationId: add-locations summary: Add Location Definitions tags: - subpackage_assets parameters: - name: X-Trebellar-Api-Key in: header required: true schema: type: string responses: '200': description: Locations added successfully content: application/json: schema: $ref: '#/components/schemas/AddLocationsResponse' '500': description: Internal Server Error content: application/json: schema: $ref: '#/components/schemas/ErrorSchema' requestBody: content: application/json: schema: $ref: '#/components/schemas/AddLocationsRequest' servers: - url: https://api.trebellar.app components: schemas: AddLocationsRequestLocationsItemsType: type: string enum: - region - sub-region - area - city - site - campus title: AddLocationsRequestLocationsItemsType AddLocationsRequestLocationsItemsStatus: type: string enum: - active - archived default: active title: AddLocationsRequestLocationsItemsStatus AddLocationsRequestLocationsItems: type: object properties: id: type: string name: type: string type: $ref: '#/components/schemas/AddLocationsRequestLocationsItemsType' parentId: type: string status: $ref: '#/components/schemas/AddLocationsRequestLocationsItemsStatus' required: - name - type title: AddLocationsRequestLocationsItems AddLocationsRequest: type: object properties: locations: type: array items: $ref: '#/components/schemas/AddLocationsRequestLocationsItems' required: - locations description: Request to add one or more location definitions title: AddLocationsRequest LocationDefinitionType: type: string enum: - region - sub-region - area - city - site - campus title: LocationDefinitionType LocationDefinitionStatus: type: string enum: - active - archived default: active title: LocationDefinitionStatus LocationDefinition: type: object properties: id: type: string name: type: string type: $ref: '#/components/schemas/LocationDefinitionType' parentId: type: string status: $ref: '#/components/schemas/LocationDefinitionStatus' required: - id - name - type description: A location definition within the organization hierarchy title: LocationDefinition AddLocationsResponse: type: object properties: data: type: array items: $ref: '#/components/schemas/LocationDefinition' required: - data description: Response after adding location definitions title: AddLocationsResponse ErrorSchema: type: object properties: code: type: number format: double message: type: string error: type: string details: type: object additionalProperties: description: Any type required: - code - message description: Common Error Schema title: ErrorSchema securitySchemes: apiKey: type: apiKey in: header name: X-Trebellar-Api-Key bearerAuth: type: http scheme: bearer ``` ## SDK Code Examples ```typescript import { TrebellarApiClient } from "@trebellar/api-sdk"; async function main() { const client = new TrebellarApiClient({ apiKey: "YOUR_API_KEY_HERE", }); await client.assets.addLocations({ locations: [ { name: "US West", type: "region", }, { name: "US East", type: "region", }, ], }); } main(); ``` ```python from trebellar import TrebellarApi from trebellar.assets import AddLocationsRequestLocationsItem client = TrebellarApi( api_key="YOUR_API_KEY_HERE", ) client.assets.add_locations( locations=[ AddLocationsRequestLocationsItem( name="US West", type="region", ), AddLocationsRequestLocationsItem( name="US East", type="region", ) ], ) ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.trebellar.app/api/v2/locations" payload := strings.NewReader("{\n \"locations\": [\n {\n \"name\": \"US West\",\n \"type\": \"region\"\n },\n {\n \"name\": \"US East\",\n \"type\": \"region\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Trebellar-Api-Key", "") 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 require 'uri' require 'net/http' url = URI("https://api.trebellar.app/api/v2/locations") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["X-Trebellar-Api-Key"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"locations\": [\n {\n \"name\": \"US West\",\n \"type\": \"region\"\n },\n {\n \"name\": \"US East\",\n \"type\": \"region\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.trebellar.app/api/v2/locations") .header("X-Trebellar-Api-Key", "") .header("Content-Type", "application/json") .body("{\n \"locations\": [\n {\n \"name\": \"US West\",\n \"type\": \"region\"\n },\n {\n \"name\": \"US East\",\n \"type\": \"region\"\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://api.trebellar.app/api/v2/locations', [ 'body' => '{ "locations": [ { "name": "US West", "type": "region" }, { "name": "US East", "type": "region" } ] }', 'headers' => [ 'Content-Type' => 'application/json', 'X-Trebellar-Api-Key' => '', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.trebellar.app/api/v2/locations"); var request = new RestRequest(Method.POST); request.AddHeader("X-Trebellar-Api-Key", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"locations\": [\n {\n \"name\": \"US West\",\n \"type\": \"region\"\n },\n {\n \"name\": \"US East\",\n \"type\": \"region\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "X-Trebellar-Api-Key": "", "Content-Type": "application/json" ] let parameters = ["locations": [ [ "name": "US West", "type": "region" ], [ "name": "US East", "type": "region" ] ]] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.trebellar.app/api/v2/locations")! 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() ```