# Xena

{% hint style="info" %}
For a complete overview of the Xena API, please go to <https://xena.biz/api-doc/>
{% endhint %}

## How the create a partner

A partner in Xena can be used as a creditor, debtor and/or employee. The idea behind this is to avoid duplicate data and to give our customers a better overview of all of their business with a specific partner. If a partner is a creditor, it will have a *customer context* connected. If a partner is a debtor, it will have a *supplier context* connected. A partner can have more than one context. When you make a lookup on a specific partner, you will get info about the contexts associated.

```javascript
GET https://my.xena.biz/Api/Fiscal/{fiscalId}/Partner/{partnerId}
{
	...
	"SupplierId": {Supplier context id},
	"CustomerId": {customer context id},
	"ResourceId": {resource context id},
	...
}
```

This is important to understand when you create a new partner. If you use the default endpoint, the partner will be created without any contexts.

{% hint style="info" %}
There are two ways to creating a partner. The first method requires two API calls. The second method can only create a customer or supplier but only requires one API call.
{% endhint %}

## Create a partner without any context

<mark style="color:green;">`POST`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/Partner`

Create a basic partner without any customer or supplier context. See the full dto here:\
<https://github.com/EG-BRS/Xena.Contracts/blob/development/src/Xena.Contracts/Domain/PartnerDto.cs>

#### Path Parameters

| Name     | Type   | Description                                        |
| -------- | ------ | -------------------------------------------------- |
| FiscalId | string | Id of the fiscal you want to create the partner in |

#### Request Body

| Name                     | Type    | Description |
| ------------------------ | ------- | ----------- |
| DefaultDeliveryAddressId | string  |             |
| Address                  | object  |             |
| ReferenceUserId          | integer |             |
| Attention                | string  |             |
| PartnerType              | string  |             |
| PhoneNumber              | string  |             |
| Note                     | string  |             |
| GLNNumber                | string  |             |
| OrgNumber                | string  |             |
| SupplierId               | integer |             |
| CustomerId               | integer |             |
| ResourceId               | integer |             |

{% tabs %}
{% tab title="200 " %}

```
{
	"Version": 1,
	"IsDeactivated": false,
	"FiscalSetupId": 97190,
	"CreatedAt": "2019-11-26T10:25:53.307Z",
	"AccountNumber": 10229,
	"Address": {
		"City": "Aarhus",
		"CountryName": null,
		"PlaceName": "string",
		"Street": "string",
		"Zip": "8000",
		"Name": "string",
		"Description": "string - string, 8000 Aarhus",
		"CountryDisplayName": null
	},
	"ReferenceFiscalSetupId": null,
	"ReferenceUserId": null,
	"Attention": "string",
	"PartnerType": "xena_partnertype_company",
	"PartnerTypeTranslated": "Company",
	"PhoneNumber": "string",
	"Note": "string",
	"URL": null,
	"GLNNumber": "string",
	"OrgNumber": "string",
	"SupplierId": null,
	"CustomerId": null,
	"ResourceId": null,
	"DefaultDeliveryAddressId": null,
	"ShortDescription": "10229",
	"LongDescription": "10229 - string",
	"Tags": [],
	"Id": 520618279
}
```

{% endtab %}
{% endtabs %}

This will create a new partner in Xena. In Xena, the partner can be converted to a customer, supplier or/and employee. If you want to add a context you can use the following endpoint.

## Create a partner context

<mark style="color:green;">`POST`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/PartnerContext`

Create a supplier or customer context for a given partner.

#### Request Body

| Name         | Type    | Description                                               |
| ------------ | ------- | --------------------------------------------------------- |
| ContextType  | string  | ContextType\_Customer or ContextType\_Supplier            |
| PartnerId    | integer | Id of the partner                                         |
| InvoiceEmail | string  | The email that will be suggested when creating an invoice |

{% tabs %}
{% tab title="200 " %}
{% tabs %}
{% tab title="Supplier context" %}

```
{
	"Version": 1,
	"IsDeactivated": false,
	"FiscalSetupId": 97190,
	"CreatedAt": "2019-11-26T12:52:50.89Z",
	"ContextType": "ContextType_Supplier",
	"PartnerId": 365830428,
	"TermsOfPayment": {
		"Offset": 15,
		"DueType": "xena_running_month",
		"Description": "Running month + 15 days"
	},
	"CurrencyAbbreviation": "DKK",
	"InvoiceEmail": "",
	"OfferReportLayoutId": null,
	"DeliveryReportLayoutId": null,
	"InvoiceReportLayoutId": null,
	"ConfirmationReportLayoutId": null,
	"PriceGroupId": null,
	"Culture": "da-DK",
	"DefaultArticleGroupId": null,
	"DefaultLedgerTagId": null,
	"DefaultVatId": null,
	"DefaultLedgerAccount": null,
	"PaymentMeansType": null,
	"PaymentMeansTypeTranslated": "",
	"Account": null,
	"AccountIdentifier": null,
	"AccountLabelTranslated": "",
	"AccountIdentifierLabelTranslated": "",
	"GroupPayments": false,
	"DefaultPaymentMessage": null,
	"PartnerName": null,
	"DefaultVatAbbreviation": null,
	"PriceGroupDescription": null,
	"ArticleGroupDescription": null,
	"LedgerTagNumber": null,
	"LedgerTagDescription": null,
	"OfferReportLayoutName": null,
	"DeliveryReportLayoutName": null,
	"InvoiceReportLayoutName": null,
	"ConfirmationReportLayoutName": null,
	"CurrencyDescription": "Danish Krone",
	"ContextDescription": "Supplier",
	"CultureDisplayName": "Danish (Denmark)",
	"DefaultBookkeepingText": "",
	"Id": 520693898
}
```

{% endtab %}

{% tab title="Customer context" %}

```
{
	"Version": 1,
	"IsDeactivated": false,
	"FiscalSetupId": 97190,
	"CreatedAt": "2019-11-26T12:54:12.233Z",
	"ContextType": "ContextType_Customer",
	"PartnerId": 516783821,
	"TermsOfPayment": {
		"Offset": 8,
		"DueType": "xena_nett",
		"Description": "Net + 8 days"
	},
	"CurrencyAbbreviation": "DKK",
	"InvoiceEmail": "",
	"OfferReportLayoutId": null,
	"DeliveryReportLayoutId": null,
	"InvoiceReportLayoutId": null,
	"ConfirmationReportLayoutId": null,
	"PriceGroupId": null,
	"Culture": "da-DK",
	"DefaultArticleGroupId": null,
	"DefaultLedgerTagId": null,
	"DefaultVatId": null,
	"DefaultLedgerAccount": null,
	"PaymentMeansType": null,
	"PaymentMeansTypeTranslated": "",
	"Account": null,
	"AccountIdentifier": null,
	"AccountLabelTranslated": "",
	"AccountIdentifierLabelTranslated": "",
	"GroupPayments": false,
	"DefaultPaymentMessage": null,
	"PartnerName": null,
	"DefaultVatAbbreviation": null,
	"PriceGroupDescription": null,
	"ArticleGroupDescription": null,
	"LedgerTagNumber": null,
	"LedgerTagDescription": null,
	"OfferReportLayoutName": null,
	"DeliveryReportLayoutName": null,
	"InvoiceReportLayoutName": null,
	"ConfirmationReportLayoutName": null,
	"CurrencyDescription": "Danish Krone",
	"ContextDescription": "Customer",
	"CultureDisplayName": "Danish (Denmark)",
	"DefaultBookkeepingText": "",
	"Id": 520619084
}
```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

## Create a partner as a customer and/or supplier

<mark style="color:green;">`POST`</mark> `https://my.xena.biz/Api/Fiscal/{fiscal}/Partner/Search`

To avoid making two requests when creating a customer or supplier, this endpoint can be used.

#### Request Body

| Name                          | Type    | Description                                                                                                                       |
| ----------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------- |
| CustomerTermsOfPaymentOffset  | integer | Days or months the customer have to pay the invoice                                                                               |
| CustomerTermsOfPaymentDueType | string  | xena\_cash, xena\_nett, xena\_running\_month or xena\_prepaid                                                                     |
| SupplierTermsOfPaymentOffset  | integer | Days or months on supplier payment terms                                                                                          |
| SupplierTermsOfPaymentDueType | string  | xena\_cash, xena\_nett, xena\_running\_month or xena\_prepaid                                                                     |
| SendInvite                    | boolean | Leave this as false                                                                                                               |
| Provider                      | integer | Leave this as null                                                                                                                |
| ProviderId                    | integer | Leave this as null                                                                                                                |
| PartnerType                   | string  | <p>xena\_partnertype\_person if the partner is a private customer.<br>xena\_partnertype\_company if the partner is a company.</p> |
| Email                         | string  | Customer mail                                                                                                                     |
| Attention                     | string  | Partner att                                                                                                                       |
| OrgNumber                     | string  | Company registration number (CVR in DK)                                                                                           |
| GLNNumber                     | string  | Number used for electronic invoicing                                                                                              |
| Name                          | string  | Partner name                                                                                                                      |
| PhoneNumber                   | string  | Partner phone number                                                                                                              |
| Street                        | string  | Street                                                                                                                            |
| PlaceName                     | string  | Place name                                                                                                                        |
| Zip                           | string  | Postal code                                                                                                                       |
| City                          | string  | City                                                                                                                              |
| CountryName                   | string  | ISO countrycode (DK, NO, SE etc.)                                                                                                 |
| IsCustomer                    | boolean | If this is True then a Customer context will be added to the partner                                                              |
| IsCupplier                    | boolean | If this is True then a Supplier context will be added to the partner.                                                             |

{% tabs %}
{% tab title="200 " %}

```
Teh fu
```

{% endtab %}
{% endtabs %}

The full model can be found here:\
<https://github.com/EG-BRS/Xena.Contracts/blob/development/src/Xena.Contracts/Helpers/PartnerSearchDto.cs>

## How to create an order and add articles

In this section we will show you how to create an order and add an article to that order. This can be done with the following steps:

1. Create the order
2. Find the order task or add an order task
3. Add a line to the order task
4. Update the order line with an article

In the following sections we will describe the needed endpoints.

## Create an order

<mark style="color:green;">`POST`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/Order`

First step is to create a new order.

#### Request Body

| Name         | Type    | Description                                                                                                                                                       |
| ------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| InternalNote | string  | Just the internal note.                                                                                                                                           |
| CreateTask   | boolean | If true an ordertask will be created.                                                                                                                             |
| OrderNumber  | integer | This should be null. Only set this if you know what you are doing! This can be relevant if the order is born with a number in some other system (e.g. a webshop). |
| ProjectId    | integer | Id of the assosiated project. *Only relevant for users of the project module.*                                                                                    |
| PartnerId    | integer | Id of the Customer or Supplier on the order.                                                                                                                      |
| ContextType  | string  | Whether it should be a Sales order (ContextType\_Customer) or Purchase order (ContextType\_Supplier)                                                              |

{% tabs %}
{% tab title="200 " %}

```
{
    "Version": 1,
    "IsDeactivated": false,
    "FiscalSetupId": 98824,
    "CreatedAt": "2019-11-21T18:48:14.583Z",
    "PartnerId": null,
    "OurReference": "Niels Husted",
    "YourReference": "",
    "ContextType": "ContextType_Customer",
    "Address": {
        "City": "",
        "CountryName": "DK",
        "PlaceName": "",
        "Street": "",
        "Zip": "",
        "Name": "",
        "Description": " -  ",
        "CountryDisplayName": "Denmark"
    },
    "DeliveryAddress": null,
    "DeliveryNote": null,
    "OrderNumber": 200009,
    "DateDays": 18221,
    "DeliveryDateDays": null,
    "CurrencyAbbreviation": "DKK",
    "OfferReportLayoutId": null,
    "DeliveryReportLayoutId": null,
    "InvoiceReportLayoutId": null,
    "ConfirmationReportLayoutId": null,
    "OfferReportLayoutName": null,
    "DeliveryReportLayoutName": null,
    "InvoiceReportLayoutName": null,
    "ConfirmationReportLayoutName": null,
    "GLNNumber": null,
    "InternalNote": "",
    "TermsOfPayment": {
        "Offset": 8,
        "DueType": "xena_nett",
        "Description": "Net + 8 days"
    },
    "Culture": "da-DK",
    "ProjectId": null,
    "ResponsibleId": 194833467,
    "ResponsibleName": "Niels Husted",
    "InvoiceEmail": "",
    "PartnerAccountNumber": null,
    "PartnerName": null,
    "PartnerNote": null,
    "PartnerPhoneNumber": null,
    "PartnerType": null,
    "Summary": {
        "Totals": {
            "PriceNettTotal": 0.0,
            "CostTotal": 0.0,
            "DiscountTotalRatio": 0.0,
            "DiscountTotalPct": 0.0,
            "DiscountTotal": 0.0,
            "MarginTotal": 0.0,
            "MarginTotalRatio": 0.0,
            "MarginTotalPct": 0.0,
            "VatEstTotal": 0.0
        },
        "NotInvoicedTotals": {
            "PriceNettTotal": 0.0,
            "CostTotal": 0.0,
            "DiscountTotalRatio": 0.0,
            "DiscountTotalPct": 0.0,
            "DiscountTotal": 0.0,
            "MarginTotal": 0.0,
            "MarginTotalRatio": 0.0,
            "MarginTotalPct": 0.0,
            "VatEstTotal": 0.0
        },
        "IsFullyInvoiced": false,
        "IsFullyDelivered": false,
        "IsFullyConfirmed": false,
        "CanOffer": false,
        "CanDeliver": false,
        "CanInvoice": false,
        "CanPay": false,
        "CanConfirm": false
    },
    "OrderInvoiceNumbers": [],
    "DepartmentId": null,
    "DepartmentDescription": null,
    "BearerId": null,
    "BearerDescription": null,
    "PurposeId": null,
    "PurposeDescription": null,
    "IsHeaderReadOnly": false,
    "OrderStatusId": 196093425,
    "OrderStatusName": "Oprettet",
    "OrderStatusColor": "#eac100",
    "ProjectDescription": null,
    "ProjectNumber": null,
    "OrderDeliveryStatus": "SalesOrderDeliveryStatus_NotApplicable",
    "CultureDisplayName": "Danish (Denmark)",
    "LastInvoicedDateDays": null,
    "SupplierInvoiceDateDays": null,
    "SupplierInvoiceNumber": null,
    "SupplierPaymentId": null,
    "Id": 518338659
}
```

{% endtab %}

{% tab title="302 Beskrivelse xxx" %}
{% tabs %}
{% tab title="OK" %}

```
{
ok json
}
```

{% endtab %}

{% tab title="Error" %}

```
{
error json
}
```

{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
Save the Id - you will need it later.
{% endhint %}

You can find the full model [here](https://github.com/EG-BRS/Xena.Contracts/blob/development/src/Xena.Contracts/Domain/OrderDto.cs)

Articles/lines are not added directly to the order but to an *order task*. One order can have several order tasks. The next step is to get the tasks and add articles to them.

## Get order tasks

<mark style="color:blue;">`GET`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/Order/{orderId}/OrderTask?ForceNoPaging=true&Page=0&PageSize=100&ShowDeactivated=false`

First you need to find the order task that you want to add the article to. If `CreateTask` was `true` when you created the order then the order will have one task already. To find the Id of that order task you need to get the list of order tasks. You will get a `PagedResultSet` with a list of `OrderTaskDTO` in Entities property from the endpoint.

#### Path Parameters

| Name            | Type    | Description                                              |
| --------------- | ------- | -------------------------------------------------------- |
| ShowDeactivated | boolean | Leave this as false                                      |
| Page            | integer | Page number                                              |
| ForceNoPaging   | boolean | If you set this as True then you will deactivate pageing |
| PageSize        | integer | Page size                                                |
| orderId         | string  | Internal order id                                        |

{% tabs %}
{% tab title="200 " %}

```
{
    "Count": 1,
    "Entities": [{
        "Version": 1,
        "IsDeactivated": false,
        "FiscalSetupId": 98824,
        "CreatedAt": "2019-11-25T18:37:10.673Z",
        "OrderId": 520562489,
        "OrderContextType": "ContextType_Customer",
        "PrintDetails": false,
        "Details": "",
        "Description": "",
        "OrderTaskStatusId": 196020703,
        "Totals": {
            "PriceNettTotal": 0.0,
            "CostTotal": 0.0,
            "DiscountTotalRatio": 0.0,
            "DiscountTotalPct": 0.0,
            "DiscountTotal": 0.0,
            "MarginTotal": 0.0,
            "MarginTotalRatio": 0.0,
            "MarginTotalPct": 0.0,
            "VatEstTotal": 0.0
        },
        "Address": {
            "City": "",
            "CountryName": "DK",
            "PlaceName": "",
            "Street": "",
            "Zip": "",
            "Name": "",
            "Description": " -  ",
            "CountryDisplayName": "Denmark"
        },
        "DeliveryAddress": null,
        "OrderTaskStatusName": "Igangværende",
        "OrderTaskStatusColor": "#9cce6f",
        "OrderNumber": 200015,
        "Index": 1,
        "SubscriptionId": null,
        "IsInvoiced": false,
        "IsDelivered": false,
        "IsConfirmed": false,
        "IsReadonly": false,
        "Abbreviation": "200015-1",
        "ProjectId": null,
        "ProjectClosedDateDays": null,
        "AppointmentCount": 0,
        "IsPlanned": false,
        "Id": 520556331
    }]
}
```

{% endtab %}
{% endtabs %}

## Find an order task

<mark style="color:green;">`POST`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/OrderTask`

If there are no ordertasks on the order or you want to create a new one, you can use this endpoint.

#### Path Parameters

| Name    | Type    | Description                                         |
| ------- | ------- | --------------------------------------------------- |
| OrderId | integer | Id for the order you want to create an ordertask on |

{% tabs %}
{% tab title="200 Xena will return this model to you:" %}

```
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You should save the Id.
{% endhint %}

## Create an order task line

<mark style="color:green;">`POST`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/OrderLine`

Now you are ready to add an article to the order task. To do this, you will need the id of the article and to create an *order line*. Here, we assume you got an article id. Start by creating a new order task line.

#### Request Body

| Name        | Type   | Description |
| ----------- | ------ | ----------- |
| OrderTaskId | string |             |

{% tabs %}
{% tab title="200 You should save the data since you will need it when updating the line with the article id." %}

```
{
	"Version": 1,
	"IsDeactivated": false,
	"FiscalSetupId": 98824,
	"CreatedAt": "2019-11-25T19:05:54.163Z",
	"OrderId": 520562489,
	"OrderContextType": "ContextType_Customer",
	"PrintDetails": false,
	"Details": "",
	"Description": "",
	"OrderTaskStatusId": 196020703,
	"Totals": {
		"PriceNettTotal": 0.0,
		"CostTotal": 0.0,
		"DiscountTotalRatio": 0.0,
		"DiscountTotalPct": 0.0,
		"DiscountTotal": 0.0,
		"MarginTotal": 0.0,
		"MarginTotalRatio": 0.0,
		"MarginTotalPct": 0.0,
		"VatEstTotal": 0.0
	},
	"Address": {
		"City": "",
		"CountryName": "DK",
		"PlaceName": "",
		"Street": "",
		"Zip": "",
		"Name": "",
		"Description": " -  ",
		"CountryDisplayName": "Denmark"
	},
	"DeliveryAddress": null,
	"OrderTaskStatusName": "Igangværende",
	"OrderTaskStatusColor": "#9cce6f",
	"OrderNumber": 200015,
	"Index": 2,
	"SubscriptionId": null,
	"IsInvoiced": false,
	"IsDelivered": false,
	"IsConfirmed": false,
	"IsReadonly": false,
	"Abbreviation": "200015-2",
	"ProjectId": null,
	"ProjectClosedDateDays": null,
	"AppointmentCount": 0,
	"IsPlanned": false,
	"Id": 520556332
}
```

{% endtab %}
{% endtabs %}

## Update an order task line

<mark style="color:orange;">`PUT`</mark> `https://my.xena.biz/Api/Fiscal/{fiscalId}/OrderLine/{orderlineId}`

To update the line, make the this request. The important fields are `ArticleId`, `Quantity` and `Description`.

#### Path Parameters

| Name        | Type    | Description                             |
| ----------- | ------- | --------------------------------------- |
| orderlineId | integer | Id of the line order you want to update |

{% tabs %}
{% tab title="200 " %}

```
{
	"Version": 2,
	"IsDeactivated": false,
	"FiscalSetupId": 98824,
	"CreatedAt": "2019-11-25T19:18:42.527Z",
	"LocationId": null,
	"OrderInvoiceTaskId": null,
	"OrderTaskId": 520556332,
	"OrderId": 520562489,
	"ProjectId": null,
	"Index": 0,
	"ArticleId": 195803359,
	"InvoiceDateDays": null,
	"CostEach": 0.00000,
	"Description": "Ydelser sats 1",
	"PriceEach": 0.00000,
	"Quantity": 1.00000,
	"UnitId": 195796629,
	"PayerId": null,
	"PayerAccountNumber": null,
	"UnitAbbreviation": "timer",
	"ArticleNumber": "yde1",
	"Totals": {
		"PriceNettTotal": 0.00000,
		"CostTotal": 0.00000,
		"DiscountTotalRatio": 0.0,
		"DiscountTotalPct": 0.0,
		"DiscountTotal": 0.00000,
		"MarginTotal": 0.00000,
		"MarginTotalRatio": 0.0,
		"MarginTotalPct": 0.0,
		"VatEstTotal": 0.00000
	},
	"ArticleGroupId": 195796691,
	"ArticleVariantId": null,
	"ArticleGroupDescription": "Ydelser",
	"ArticleHasInventoryManagement": false,
	"ArticleHasVariants": false,
	"ArticleInternalNote": null,
	"ArticleIsBundle": false,
	"ArticleVariantAbbreviation": null,
	"ArticleWeight": null,
	"LocationAbbreviation": null,
	"ArticleStatus": null,
	"OrderDeliveryTransactionId": null,
	"ArticleMappingId": null,
	"ArticleMappingQuantity": null,
	"PartnerArticleNumber": null,
	"IsConfirmed": false,
	"ArticleAbbreviation": "yde1",
	"IsDelivered": false,
	"ArticleIsDeactivated": false,
	"AverageCostPrice": null,
	"EstimatedCostTotal": 0.00000,
	"OrderLineStatusColor": null,
	"OrderLineStatusName": null,
	"HasLinkedLines": false,
	"Id": 520557490
}
```

{% endtab %}
{% endtabs %}

## How to create an invoice

\[Coming up]
