# Owners Mutation

### Mutation Types

{% hint style="info" %}
Mutations are responsible to insert or update a specific register, the operation insert or update is defined by **`externalId`**, in case this owner was imported previously, this mutation will updated the resource, otherwise will create the property.
{% endhint %}

```graphql
type Mutation {
    upsertOwner(owner:OwnerInput!)  
    deleteOwner(externalId: String!)  
}
```

Here are details on the capabilities of different mutations

* `The upsertOwner`  mutation is used to create or update an owner in Everreal system and owners added to the system cannot be modified by Everreal and if needs to be modified it should be done via the same endpoint itself.
* The `deleteOwner`  mutation is used to delete the owner relation with the external integration source, doing this will not delete the owner but instead it will remain as a detached owner from integration and can be modified using Everreal.

### Schema Definition

{% hint style="warning" %}
&#x20;items with **!** notation are required
{% endhint %}

```graphql
input OwnerInput {
  meta: MetaInformation!
  externalOwnerId: String! #externalId by which the owner is identified
  firstName: String!
  lastName: String!
  companyName: String
  email: String!
  phoneNo: String
  address: PersonalAddress
  bankDepositInformation: BankDepositInformation
  bankInformation: BankIformation
  customFieldValues: [CustomFieldValueInput]
}

input PersonalAddress {
  streetName: String
  streetNumber: String
  zipCode: String
  city: String
  country: String
}

input BankDepositInformation {
  iban: String
  bic: String
  bankName: String
  accountHolderName: String
}

input BankIformation {
  bankName: String
  bankAddress: String
  bic: String
  iban: String
}

input MetaInformation {
  source: String! # source should be the integration source, so logo is visible in everreal
}
```

Below we are providing a full example how to create or update an owner, all this information is not required, only the ones that was using **!** notation previously.

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

```graphql
mutation {
  upsertOwner(
    owner: {
      meta: { source: "INTEGRATION_SOURCE" }
      externalOwnerId: "91001+002242"
      firstName: "Ivana"
      lastName: "Maric"
      email: "ivana.maric@everreal.com"
      companyName: "Everreal Gmbh"
      phoneNo: "+49 123 1231 1237"
      address: {
        streetName: "Villenallee"
        streetNumber: "21"
        zipCode: "40211"
        city: "Düsseldorf"
        country: "DE"
      }
    }
  ) {id}
}
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer ....");
myHeaders.append("Content-Type", "application/json");

var graphql = JSON.stringify({
  query: "mutation {\r\n  upsertOwner(\r\n    owner: {\r\n      meta: { source: \"INTEGRATION_SOURCE\" }\r\n      externalOwnerId: \"91001+002242\"\r\n      firstName: \"Ivana\"\r\n      lastName: \"Maric\"\r\n      email: \"ivana.maric@everreal.com\"\r\n      companyName: \"Everreal Gmbh\"\r\n      phoneNo: \"+49 123 1231 1237\"\r\n      address: {\r\n        streetName: \"Villenallee\"\r\n        streetNumber: \"21\"\r\n        zipCode: \"40211\"\r\n        city: \"Düsseldorf\"\r\n        country: \"DE\"\r\n      }\r\n    }\r\n  ) {\r\n    id\r\n  }\r\n}\r\n\r\n",
  variables: {}
})
var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: graphql,
  redirect: 'follow'
};

fetch("http://{subdomain}.everreal.co/api/reporting/graphql", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error))
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-docs.everreal.co/endpoints/owners/owners-mutation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
