# Property Group Mutation

### Mutation Types

{% hint style="info" %}
**upsertPropertyGroup**: Mutation is responsible for inserting or updating 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 {
  upsertPropertyGroup(propertyGroup: PropertyGroupInput!): PropertyGroup!
}
```

Here are details on the capabilities of different mutations

* The `upsertPropertyGroup` the mutation is used to create or update a property group in the 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.

### Schema Definition

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

```graphql
input PropertyGroupInput {
  name: String
  externalPropertyGroupId: String!
  descriptions: PropertyGroupDescriptionInput
}


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

```

> `externalPropertyGroupId` is required field, this is the `key` or the `id` which is used by the 3d party system(data synchronize between 3rd party)&#x20;

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 {
  upsertPropertyGroup(
    propertyGroup: {
        name: "Ray - PG1"
        externalPropertyGroupId: "RPG-1"
        descriptions:{
            object: "Sample - Object"
            amenities: "Sample - Amenities"
            location: "Sample - Location"
            other: "Sample - Other"
        }
    }
  ) { 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 {\n  upsertPropertyGroup(\n    propertyGroup: {\n        name: \"Ray - PG1\"\n        externalPropertyGroupId: \"RPG-1\"\n        descriptions:{\n            object: \"Sample - Object\"\n            amenities: \"Sample - Amenities\"\n            location: \"Sample - Location\"\n            other: \"Sample - Other\"\n        }\n    }\n  ) { id }\n}",
  variables: {}
})
var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: graphql,
  redirect: 'follow'
};

fetch("https://acme-qa.everreal-dev.co/api/reporting/graphql", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

{% endtab %}
{% endtabs %}
