# Understanding PATCH syntax when constructing update requests

**URL:** <https://community.f5.com/t/understanding-patch-syntax-when-constructing-update-requests/53389>\
**Category:** Technical Forums\
**Tags:** icontrolrest, devops\
**Created:** [June 19, 2017, 3:44am UTC](https://community.f5.com/t/understanding-patch-syntax-when-constructing-update-requests/53389 "2017-06-19T03:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devnullNZ](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@devnullNZ](https://community.f5.com/u/devnullNZ)\
**Post date:** [June 19, 2017, 3:44am UTC](https://community.f5.com/t/understanding-patch-syntax-when-constructing-update-requests/53389/1 "2017-06-19T03:44:09Z")

</div>

Would love to see some practical examples of syntax use when using the iControl REST API.

I’m trying to modify a datagroup data value via the API, but failing. Using Postman, successfully auth’d, sending PATCH [https://dev-lb1.lab.int/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup](https://dev-lb1.lab.int/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup){“records”:[“name”:“default”, “data”:“virt\_host2”]}

Test is to modify the data value, from “virt\_host1” to “virt\_host2” Then take this and turn it into an ansible task.

The syntax surrounding defining what I’m changing is unclear, and so far I’ve only managed to test exceptions

---

<div class="post-metadata">

**Author:** ![devnullNZ](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@devnullNZ](https://community.f5.com/u/devnullNZ)\
**Post date:** [June 26, 2017, 3:14am UTC](https://community.f5.com/t/understanding-patch-syntax-when-constructing-update-requests/53389/2 "2017-06-26T03:14:00Z")

</div>

In other words, what I’m looking for is the correct syntax for this part:

{“records”:[“name”:“default”, “data”:“virt\_host2”]}

I’ve tried as just a normal key, value pair, but it doesn’t like that either… So when passing a PATCH back to the F5, how should these variables be presented?

---

<div class="post-metadata">

**Author:** ![Satoshi\_Toyosa1](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@Satoshi\_Toyosa1](https://community.f5.com/u/Satoshi_Toyosa1)\
**Post date:** [July 11, 2017, 3:17am UTC](https://community.f5.com/t/understanding-patch-syntax-when-constructing-update-requests/53389/3 "2017-07-11T03:17:11Z")

</div>

I believe you are missing curly brackets around the name/value object. i.e.,

```tcl
{"records":[{"name":"default", "data":"virt_host2"}]}

```

Example:

- Getting the datagroup (equivalent to

```tcl
curl -sku admin: https:///mgmt/tm/ltm/data-group/internal/images

{ kind: 'tm:ltm:data-group:internal:internalstate',
  name: 'images',
  fullPath: 'images',
  generation: 299,
  selfLink: 'https://localhost/mgmt/tm/ltm/data-group/internal/images?ver=11.6.1',
  type: 'string',
  records: [{ name: 'ext1', data: '.ppm' }]
}

```

- Modify (equivalent to

```tcl
curl -sku admin: https:///mgmt/tm/ltm/data-group/internal/images \
  -X PATCH -H "Content-type: application/json" \
  -d '{"records":[{"name": "ext1", "data":".png"}]}'

{ kind: 'tm:ltm:data-group:internal:internalstate',
  name: 'images',
  fullPath: 'images',
  generation: 306,
  selfLink: 'https://localhost/mgmt/tm/ltm/data-group/internal/images?ver=11.6.1',
  type: 'string',
  records: [{ name: 'ext1', data: '.png' }]
}

```

---

<div class="post-metadata">

**Author:** ![devnullNZ](https://avatars.discourse-cdn.com/v4/letter/d/b77776/32.png) [@devnullNZ](https://community.f5.com/u/devnullNZ)\
**Post date:** [August 6, 2017, 11:45pm UTC](https://community.f5.com/t/understanding-patch-syntax-when-constructing-update-requests/53389/4 "2017-08-06T23:45:47Z")

</div>

Updating this in case anyone else gets stuck fetching & changing datagroups with ansible. Playbook snippet comparing datagroup values and changing when necessary:

```tcl
- name: get data via REST api
    uri:
      url: "https://{{ inventory_hostname }}/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup"
      method: GET
      force_basic_auth: yes
      user: "{{ f5_admin_user }}"
      password: "{{ f5_admin_password }}"
      validate_certs: no
    register: result
    tags:
      - always

  - name: save current datagroup info
    set_fact:
      current_data="{{ result.json['records'][0]['data'] }}"
    tags:
      - always

  - name: Change data
    uri:
      url: "https://{{ inventory_hostname }}/mgmt/tm/ltm/dataGroup/internal/~Common~mtest-routing-datagroup"
      method: PATCH
      force_basic_auth: yes
      user: "{{ f5_admin_user }}"
      password: "{{ f5_admin_password }}"
      validate_certs: no
      body: {"records":[{"name": "default", "data":"{{ desired_data }}"}]}
      body_format: json
      status_code: 200
    when: not current_data == desired_data
    changed_when: not current_data == desired_data
    tags:
    - always

```
