# REST API calls
## Header
The provided API Token has to be included in the header with every request to the interface.
```json!
{
"X-API-KEY": "<api-key>",
}
```
## Requests
There are POST and GET requests.
The GET request dont use any **Content-Types**.
The POST request always need the **Content-Type: "application/json; charset=utf-8"**
## Responses
All responses will always be in **Content-Type: "application/json; charset=utf-8"**
## Endpoints
### **GET** /ano/v1.0/regions
This request will return a list of all accessible regions.
#### Response Result
The response **Content-Type** is **"application/json; charset=utf-8"**
```json!
{
"regions": [
{
"name": "0000-00_Test Region",
"cluster_code": "SDISalesCluster_123456789012_1234567890",
"project_number": "dummy-001",
"geo_json": { ...}
},
{
"name": "0000-00_Test Region 2",
"cluster_code": "SDISalesCluster_123456789012_1234567891",
"project_number": "dummy-002",
"geo_json": { ...}
}
]
}
```
### **GET** /ano/v1.0/orders
This request will return a list of all orders from the specified region.
#### Parameter
This request is need of a cluster code to get the orders in this region.
```json!
"cluster_code": "SDISalesCluster_123456789012_1234567890"
```
#### Possible order status codes
The internal_state in Odoo is mapped to the following states:
* **Canceled**, if the state of the order is canceled
* **Open**, if the internal_state is not set
* **In Verification**, if the internal_state is **Bestellt** or **Übergabepunkt**
* **In Preparation**, if the internal_state is **Freigabe** or **Material abgeholt**
* **Done**, if the internal_state is **Abgeschlossen**
```json!
"status_codes": [{
"code": "open",
"name": "Open"
}, {
"code": "verification",
"name": "In Verification"
}, {
"code": "preparation",
"name": "In Preparation"
}, {
"code": "done",
"name": "Done"
}, {
"code": "cancel",
"name": "Canceled"
}]
```
#### Response Result
The response **Content-Type** is **"application/json; charset=utf-8"**
The fields are null, if they are not set. Except for the fields in the partner, which will be "".
The dates are set to the Timezone "Europe/Vienna".
The fields in the customer dictionary are the same fields as the partner dictionary, but they have different values ofcourse.
**Invoiced**:
There are a couple of flags in the orders to implicate what is invoices.
1. The invoiced = true/false flag in the order, which indicates if the order was completely invoiced or not.
2. The qty_invoiced = 0.0 flag, which indicates the invoiced quantity.
3. The invoiced = true/false flag in the homes, which indicated if this specific home was completely invoiced or not.
```json!
{
orders": [
{
"order_name": "0AAA/A00000",
"building_id": "SDIBuilding_123456789012_1234567890",
"customer_acquired": true,
"status": {
"code": "verification",
"name": "In Prüfung"
},
"invoiced": false,
"customer": {
"company_type": "person",
"uid": "ATU12345678",
"anrede": "",
"titel": "",
"firstname": "Vorname",
"lastname": "Nachname",
"date_of_birth": "",
"phone": "0124578963",
"address": "Straße 55",
"zip": "1010",
"city": "Ort",
"country": "AT",
"email": "mail@mail.at"
},
"order_date": "2020-12-11 10:56:16",
"lines": [
{
"product_code": "testp20-3",
"description": "test beschreibung",
"price_unit": 1500.0,
"quantity": 1,
"tax": 20.0,
"home_id": "SDIBuilding_123456789012_1234567890",
"oaid": "alphanr8",
"work_order_id": "SDIInstallationTicket_123456789012_1234567890",
"qty_invoiced": 0.0
}
],
"homes": [
{
"home_id": "SDIHome_123456789012_0",
"oaid": "alphanr8",
"work_order_id": "SDIInstallationTicket_123456789012_1234567891",
"rimo_workorder_state": "Accepted",
"ts_planned": "2020-12-15 10:56:16",
"invoiced": false,
"assembly_company": {
"name": "Assembly Company Name",
"phone": "Phone number"
},
"partner": {
"company_type": "person",
"uid": "",
"anrede": "Herr",
"titel": "",
"firstname": "Max",
"lastname": "Muster",
"date_of_birth": "",
"phone": "789456",
"address": "Some-Address 55",
"zip": "7878",
"city": "City",
"country": "AT",
"email": "email@email.at"
}
},
{
"home_id": "SDIHome_123456789012_1",
"oaid": null,
"rimo_workorder_id": "SDIInstallationTicket_123456789012_1234567892",
"rimo_workorder_state": "Accepted",
"ts_planned": null,
"invoiced": false,
"assembly_company": null,
"partner": null
}
],
}
]
}
```
### **POST** /ano/v1.0/set_customer_acquired
Sets a flag in a specified order that marks the order as acquired
#### Parameter
The **Content-Type** of the request is **"application/json; charset=utf-8"**
The request parameter **orders** is need, which has to be defined as a list to set the acquired flag.
```json!
{
"orders": [
"0AAA/A00000",
"0AAA/A00001"
]
}
```
#### Response Result
The response **Content-Type** is **"application/json; charset=utf-8"**
```json!
{
"customer_acquired": [
"0AAA/A00000",
"0AAA/A00001"
]
}
```
# Search Available Addresses
## Search in Region
**NO API Token**
### **POST** /rimo_addresses/<region_code>
Search for an address in Odoo.
#### Parameter
The **Content-Type** of the request is **"application/json; charset=utf-8"**
```json!
{
"params": {
"term": "Haupt"
}
}
```
#### Response Result
The response **Content-Type** is **"application/json; charset=utf-8"**
The response can have a maximum of 11 records.
```json!
{
"jsonrpc": "2.0",
"id": null,
"result": [
{
"id": 4567,
"full_name": "Hauptstraße 11, 1234, Ort\r",
"external_name": "SDIBuilding_12345678912141_0"
}
]
}
```
## Search in all Regions
The parameters and response is the same, but the request goes to **POST** /rimo_addresses/ instead.