# Update a Single Object

## Partial Update on an Object

This function updates a single object of the given type and with the given ID. If no object with the specified object exists yet, an error is returned.

{% hint style="info" %}
The ID **must be a valid** [**UUID**](http://en.wikipedia.org/wiki/Universally_unique_identifier), and **must be lowercase**. For example, `550e8400-e29b-41d4-a716-446655440000` is a valid UUID.

When updating objects using the JourneyApps API, use the UUIDs returned by JourneyApps (in the `id` field of each object) when you [retrieve objects.](https://docs.journeyapps.com/reference/backend-api/api-reference/retrieve-all-objects)
{% endhint %}

<table><thead><tr><th width="513">Relative URL</th><th>HTTP Request Method</th></tr></thead><tbody><tr><td><code>/api/v4/</code><em><code>backend-deployment-id</code></em><code>/objects/</code><em><code>model</code></em><code>/</code><em><code>object-id</code></em><code>.json</code></td><td>PATCH</td></tr></tbody></table>

{% hint style="info" %}

* Replace *`model`* with the type of object that you wish to update (as defined in your app's Data Model).
* Replace *`object-id`* with the ID of the specific object.
  {% endhint %}

### Parameters

The parameters must be specified in the same way as for creating new objects. Please refer to the same section in [Creating a New Object](https://docs.journeyapps.com/reference/backend-api/api-reference/create-a-new-object) and to the [Field Representation](https://docs.journeyapps.com/reference/backend-api/api-reference/field-representation) section.

{% hint style="info" %}
For updating more than one object in a request, refer to the [Batch Operations](https://docs.journeyapps.com/reference/backend-api/api-reference/batch-operations-v4-api) section.
{% endhint %}

### Response

The response includes the single updated object. The format of the object is the same as for [Retrieving all Objects](https://docs.journeyapps.com/reference/backend-api/api-reference/retrieve-all-objects).

### Example

{% hint style="info" %}
**BASE-URL**

The below examples contain a `BASE-URL` placeholder. Please refer to the [HTTP Endpoints](https://docs.journeyapps.com/reference/introduction#http-endpoints) section to get the base URL relevant to your deployment.
{% endhint %}

In this example, we update only the *status* field of a *task* object:

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

```http
PATCH BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks/198c990e-f1bf-11e1-8d7d-001cc01904e3.json

task[status]=1
```

{% endtab %}

{% tab title="curl" %}
{% hint style="success" %}
The `-X` parameter to curl allows you to use a specific HTTP request method.
{% endhint %}

```shell
curl "BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks/198c990e-f1bf-11e1-8d7d-001cc01904e3.json" \
    -u "533bda53027894f69b001055:7Ajj5htRY1uzw7b4w23V" \
    -X PATCH \
    -d "task[status]=1"
```

{% endtab %}

{% tab title="ruby" %}

```ruby
require 'rest-client'
journey = RestClient::Resource.new "BASE-URL/api/v4", "533bda53027894f69b001055", "7Ajj5htRY1uzw7b4w23V"
journey["533bda53027894f69b001055/objects/tasks/198c990e-f1bf-11e1-8d7d-001cc01904e3.json"].patch :task=>{:status=>1}
```

{% endtab %}
{% endtabs %}

Response:

{% code title="json" %}

```json
{
  "id": "198c990e-f1bf-11e1-8d7d-001cc01904e3",
  "type": "task",
  "updated_at": "2015-02-10T12:03:28Z",
  "display": "Task 1",
  "name": "Task 1",
  "instructions": null,
  "status": {
    "key": 1,
    "display": "Closed"
  },
  "category_id": null
}
```

{% endcode %}

## Replacing an Object in its Entirety

This function replaces a single object of the given type with the given ID. If no object with the specified ID exists yet, a new object is created with the given ID.

{% hint style="info" %}
The ID **must be a valid** [**UUID**](http://en.wikipedia.org/wiki/Universally_unique_identifier), and **must be lowercase**. For example, `550e8400-e29b-41d4-a716-446655440000` is a valid UUID.

When updating objects using the JourneyApps API, use the UUIDs returned by JourneyApps (in the `id` field of each object) when you [retrieve objects.](https://docs.journeyapps.com/reference/backend-api/api-reference/retrieve-all-objects)
{% endhint %}

<table><thead><tr><th width="518">Relative URL</th><th>HTTP Request Method</th></tr></thead><tbody><tr><td><code>/api/v4/</code><em><code>backend-deployment-id</code></em><code>/objects/</code><em><code>model</code></em><code>/</code><em><code>object-id</code></em><code>.json</code></td><td>PUT</td></tr></tbody></table>

{% hint style="info" %}

* Replace *`model`* with the type of object that you wish to update (as defined in your app's Data Model).
* Replace *`object-id`* with the ID of the specific object.
  {% endhint %}

### Parameters

The parameters must be specified in the same way as for creating new objects. Please refer to the same section in [Creating a New Object](https://docs.journeyapps.com/reference/backend-api/api-reference/create-a-new-object) and to the [Field Representation](https://docs.journeyapps.com/reference/backend-api/api-reference/field-representation) section.

{% hint style="info" %}
For updating more than one object in a request, refer to the [Batch Operations](https://docs.journeyapps.com/reference/backend-api/api-reference/batch-operations-v4-api) section.
{% endhint %}

### Response

The response includes the single updated object. The format of the object is the same as for [Retrieving all Objects](https://docs.journeyapps.com/reference/backend-api/api-reference/retrieve-all-objects).

### Example

{% hint style="info" %}
**BASE-URL**

The below examples contain a `BASE-URL` placeholder. Please refer to the [HTTP Endpoints](https://docs.journeyapps.com/reference/introduction#http-endpoints) section to get the base URL relevant to your deployment.
{% endhint %}

In this example, we set only the `name` field of a `task` object. The other fields are cleared.

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

```http
PUT BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks/198c990e-f1bf-11e1-8d7d-001cc01904e3.json

task[name]=Task%201
```

{% endtab %}

{% tab title="curl" %}
{% hint style="success" %}
The `-X` parameter to curl allows you to use a specific HTTP request method.js
{% endhint %}

```shell
curl "BASE-URL/api/v4/533bda53027894f69b001055/objects/tasks/198c990e-f1bf-11e1-8d7d-001cc01904e3.json" \
    -u "533bda53027894f69b001055:7Ajj5htRY1uzw7b4w23V" \
    -X PUT \
    -d "task[name]=Task%201"
```

{% endtab %}

{% tab title="ruby" %}

```ruby
require 'rest-client'
journey = RestClient::Resource.new "BASE-URL/api/v4", "533bda53027894f69b001055", "7Ajj5htRY1uzw7b4w23V"
journey["533bda53027894f69b001055/objects/tasks/198c990e-f1bf-11e1-8d7d-001cc01904e3.json"].put :task=>{:name=>"Task 1"}
```

{% endtab %}
{% endtabs %}

Response:

{% code title="json" %}

```json
{
  "id": "198c990e-f1bf-11e1-8d7d-001cc01904e3",
  "type": "task",
  "updated_at": "2015-02-10T12:01:25Z",
  "display": "Task 1",
  "name": "Task 1",
  "instructions": null,
  "status": null,
  "category_id": null
}
```

{% endcode %}
