# Diamant Connector

### Get Method

The Method Retrieves the data specified with **dataType** (like Address, CostCenter and so on). The **searchParams** and **fieldMatch** JSON properties are valid for all methods, but the fields mentioned in it are depending on the datatype used. For example: **postcode** is a valid **searchParam** for addresses, but not for cost centers.

The Get method will return the data it fetched from Diamant, so you get an array of JSON objects. The fieldMatch prameter will tell the brixxbox to change field names, so that it is more useful in an brixxbox environment.

#### Example Usages Get

This will retrieve all addresses from diamant. Field names are the original diamand field names

```javascript
 let result = await brixxApi.businessBrixx({
     functionName:"Diamant",
     methodName: "Get",
     company: "9018",
     dataType: "Address",
 });
 console.log(result)
```

\
This will retrieve all addresses with Postcode 61118 from diamant and return the result. Only the fields "key" and "Name1" will be returned.

```javascript
 let result = await brixxApi.businessBrixx({
     functionName:"Diamant",
     methodName: "Get",
     dataType: "Address",
     searchParams:{
         postcode: "61118"
     },  
     usedFields:["key", "Name1"]

 });
 console.log(result)
```

### Write to Diamant

This code will write an address to Diamant

```javascript
let result = brixxApi.businessBrixx({
   functionName: "Diamant",
   methodName: "Save",
   dataType: "Address",
   fields: {
      key: "12345",
      addresstype: "F",
      name1: "John Doe",
      street: "Elmstreet 123",
      postcode: "12345",
      town: "Berlin",
   },
});
```

### ImportTable Method

This method allows you to retrieve the data and insert it into the database. Query parameters work the same and are optional but you must user fieldMatch to assign diamant names to brixxbox field names

#### Example Usages Import Insert

This will retrieve all addresses from diamant and insert it into the table **address** the table will be wiped right before the import.

```javascript
 let result = await brixxApi.businessBrixx({
     functionName:"Diamant",
     methodName: "ImportTable",
     dataType: "Address",
     tableName: "address",
     wipeTable: true,
     fieldMatch:{
         postcode: "adrZip",
         name1: "adrName"
     }, 
 });
 console.log(result)
```

#### Example Usages Import Upsert

This will retrieve all addresses from diamant and update the records with the same id as in fieldMatch.

```javascript
 let result = await brixxApi.businessBrixx({
     functionName:"Diamant",
     methodName: "ImportTable",
     dataType: "Address",
     tableName: "address",
     upsert: true,
     wipeTable: true,
     fieldMatch:{
         key: "adrKey,id",
         postcode: "adrZip",
         name1: "adrName"
     }, 
 });
 console.log(result)
```

### Supported dataTypes

More types can be added at request.

Request Data

* Address (Adressen)
* CostCenter (Kostenstellen)
* GenLedgAccount (Sachkonten)
* CostObject (Kostenträger)
* PrimCostElement (Primärkostenarten)
* Project (Projekte)
* Company (Mandanten)
* Customer(Konten)
* Vendor (Vendor)
* Posting (Buchungen)

Transctions

* [OpenStack](https://brixxbox.gitbook.io/brixxbox-documentation/client-api-reference/functions/businessbrixx/diamant-connector/diamant-openstack)
* [Transaction](https://brixxbox.gitbook.io/brixxbox-documentation/client-api-reference/functions/businessbrixx/diamant-connector/diamant-transaction)
* [CloseStack](https://brixxbox.gitbook.io/brixxbox-documentation/client-api-reference/functions/businessbrixx/diamant-connector/diamant-closestack)
