> For the complete documentation index, see [llms.txt](https://api-docs.everreal.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://api-docs.everreal.co/endpoints/properties/properties-mutation.md).

# Properties 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 property was imported previously, this mutation will updated the resource, otherwise will create the property.
{% endhint %}

```graphql
type Mutation {
    upsertProperty(property: PropertyInput!)
    deleteProperty(externalId: String!)  
}
```

Here are details on the capabilities of different mutations

* The `upsertProperty`  mutation is used to create or update a property in Everreal system and property 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 `deleteProperty`  mutation is used to delete the property relation with the external integration source, doing this will not delete the property but instead it will remain as a detached property from integration and can be modified using Everreal.

### Schema Definition

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

```graphql
input PropertyInput {
  meta: MetaInformation!
  address: AddressInput!
  id: String #you can pass the id to change the externalId of the property
  externalPropertyId: String! #externalId by which the property will be identified
  ownerId: String #when ownershipType=INDIVIDUAL you should either pass externalOwnerId or ownerId where ownerId is Everreal generated Id
  externalOwnerId: String  #when ownershipType=INDIVIDUAL you should either pass externalOwnerId or ownerId where ownerId is Everreal generated I
  name: String!
  type: PROPERTY_TYPE!
  subtype: PROPERTY_TYPE!
  category: PROPERTY_CATEGORY!
  noOfStories: Int # The total number of floors of the building
  yearBuilt: Int
  ownershipType: PROPERTY_OWNERSHIP_TYPE! #when passed as MULTIPLE you dont need to pass ownerId or externalOwnerId
  responsibilityType: PROPERTY_RESPONSIBILITY_TYPE
  responsibleUserId: String
  propertyGroupId: String
  externalPropertyGroupId: String
  descriptions: PropertyDescriptionInput
}

input AddressInput {
  streetName: String!
  streetNumber: String!
  zipCode: String!
  city: String!
  country: String!
  location: GeoLocationInput
  placeId: String
}


input PropertyDescriptionInput {
  object: String
  amenities: String
  location: String
  other: String
}

input GeoLocationInput {
  lat: Float!
  lng: Float!
}

input MetaInformation {
  source: String!
}

```

> If you don't have a value for a required field that is an enum, then pass the default value, for `PROPERTY_OWNERSHIP_TYPE`  if passed `INDIVIDUAL` then it should contain ownerId.

{% hint style="info" %}
When Owner or ResponsibleUser is changed in property the value will be inherited to the units attached to property and owner, unitResponsible will be updated respectively.\
\
Also, When OwnershipType and ResponsibilityUserType is changed to `MULTIPLE,`the value of the owner and responsible users will not be cleared in unit level instead retains previous value.
{% endhint %}

<table><thead><tr><th width="150">Enum</th><th>Default</th><th width="234.64078899395986">Possible Values</th></tr></thead><tbody><tr><td><code>PROPERTY_TYPE</code></td><td><code>BUILDING</code></td><td><code>BUILDING</code> | <code>LAND</code></td></tr><tr><td><code>PROPERTY_CATEGORY</code></td><td><code>RESIDENTIAL_AND_COMMERCIAL</code></td><td><code>RESIDENTIAL</code> | <code>COMMERCIAL</code> | <br><code>RESIDENTIAL_AND_COMMERCIAL</code></td></tr><tr><td><code>PROPERTY_OWNERSHIP_TYPE</code></td><td><code>MULTIPLE</code></td><td><code>INDIVIDUAL</code> | <code>MULTIPLE</code></td></tr><tr><td><code>PROPERTY_RESPONSIBILITY_TYPE</code></td><td><code>MULTIPLE</code></td><td><code>INDIVIDUAL</code>| <code>MULTIPLE</code></td></tr></tbody></table>

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

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

```graphql
mutation {
  upsertProperty(
    property: {
      meta: { source: "INTEGRATION_SOURCE" }
      name: "Munich Appartment"
      type: BUILDING
      externalPropertyId: "9098/501" 
      ownerId: "b8559500-bb35-11ec-a64e-4b00ff3d25d5" 
      externalOwnerId: "981/2"d
      category: RESIDENTIAL
      subtype: BUILDING
      noOfStories: 10
      address: {
        city: "Ludwigshafen a. Rhein"
        country: "DE"
        streetNumber: "44 - 68"
        streetName: "Hoher Weg"
        zipCode: "67067"
        location: { lat: 52.5705570, lng: 6.14847399999933 }
      }
      ownershipType: INDIVIDUAL 
    }
  ) {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  upsertProperty(\r\n    property: {\r\n      meta: { source: "INTEGRATION_SOURCE" }\r\n      name: "Hohe 12"\r\n      type: BUILDING\r\n      externalPropertyId: "9098/50"\r\n      category: RESIDENTIAL\r\n      subtype: BUILDING\r\n      address: {\r\n        city: "Ludwigshafen a. Rhein"\r\n        country: "DE"\r\n        streetNumber: "44 - 68"\r\n        streetName: "Hoher Weg"\r\n        zipCode: "67067"\r\n        location: { lat: 52.5705570, lng: 6.14847399999933 }\r\n      }\r\n      ownershipType: MULTIPLE\r\n    }\r\n  ) {\r\n    id\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 %}
