Writing the JSON for a patch request

I am writing a package for KoBo API. I can’t figure out the JSON structure needed to make a PATCH/POST/PUT request.

url <- "https://kf.kobotoolbox.org/api/v2/assets/a9QFAkQ2jKPTp8uDwCbC9q/data/bulk/"
payload <- "[
    {
        "_id": 157174689,
        "formhub/uuid": "d0f06b3a0cce4a4f9c69de7fb6c10f20",
        "start": "2022-05-16T14:14:41.374+07:00",
        "end": "2022-05-16T14:15:28.520+07:00",
        "text": "KLJKL",
        "drop_down": "option_1",
        "number": "9",
        "__version__": "v2URgFgrQowD6KUBPoix49",
        "meta/instanceID": "uuid:24e16054-30ce-4ca1-a4a4-e0dca81d03a6",
        "_xform_id_string": "a9QFAkQ2jKPTp8uDwCbC9q",
        "_uuid": "24e16054-30ce-4ca1-a4a4-e0dca81d03a6",
        "_attachments": [],
        "_status": "submitted_via_web",
        "_geolocation": [
            null,
            null
        ],
        "_submission_time": "2022-05-16T06:15:59",
        "_tags": [

        ],
        "_notes": [

        ]
    },
    {
        "_id": 157174691,
        "formhub/uuid": "d0f06b3a0cce4a4f9c69de7fb6c10f20",
        "start": "2022-05-16T14:15:28.611+07:00",
        "end": "2022-05-16T14:15:36.486+07:00",
        "text": "K",
        "__version__": "v2URgFgrQowD6KUBPoix49",
        "meta/instanceID": "uuid:25472215-51bf-4d35-8597-1f266fa0ce9b",
        "_xform_id_string": "a9QFAkQ2jKPTp8uDwCbC9q",
        "_uuid": "25472215-51bf-4d35-8597-1f266fa0ce9b",
        "_attachments": [

        ],
        "_status": "submitted_via_web",
        "_geolocation": [
            null,
            null
        ],
        "_submission_time": "2022-05-16T06:15:59",
        "_tags": [

        ],
        "_notes": [

        ],
        "group_rp0bl44/group_question_1": "klj",
        "group_rp0bl44/group_question_2": "u"
    }
]"

PATCH(url, body = payload, content_type = "json" ....)

This payload is similar as the output of the GET /data API:


response <- httr::GET(...)
response <- jsonlite::fromJSON(
                          httr::content(
                              response,
                              "text"
                          )
                       )

Here is the parsed response:

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "_id": 157174689,
            "formhub/uuid": "d0f06b3a0cce4a4f9c69de7fb6c10f20",
            "start": "2022-05-16T14:14:41.374+07:00",
            "end": "2022-05-16T14:15:28.520+07:00",
            "text": "kljkl",
            "drop_down": "option_1",
            "number": "9",
            "__version__": "v2URgFgrQowD6KUBPoix49",
            "meta/instanceID": "uuid:24e16054-30ce-4ca1-a4a4-e0dca81d03a6",
            "_xform_id_string": "a9QFAkQ2jKPTp8uDwCbC9q",
            "_uuid": "24e16054-30ce-4ca1-a4a4-e0dca81d03a6",
            "_attachments": [

            ],
            "_status": "submitted_via_web",
            "_geolocation": [
                null,
                null
            ],
            "_submission_time": "2022-05-16T06:15:59",
            "_tags": [

            ],
            "_notes": [

            ],
            "_validation_status": {

            },
            "_submitted_by": null
        },
        {
            "_id": 157174691,
            "formhub/uuid": "d0f06b3a0cce4a4f9c69de7fb6c10f20",
            "start": "2022-05-16T14:15:28.611+07:00",
            "end": "2022-05-16T14:15:36.486+07:00",
            "text": "k",
            "group_rp0bl44/group_question_1": "klj",
            "group_rp0bl44/group_question_2": "u",
            "__version__": "v2URgFgrQowD6KUBPoix49",
            "meta/instanceID": "uuid:25472215-51bf-4d35-8597-1f266fa0ce9b",
            "_xform_id_string": "a9QFAkQ2jKPTp8uDwCbC9q",
            "_uuid": "25472215-51bf-4d35-8597-1f266fa0ce9b",
            "_attachments": [

            ],
            "_status": "submitted_via_web",
            "_geolocation": [
                null,
                null
            ],
            "_submission_time": "2022-05-16T06:15:59",
            "_tags": [

            ],
            "_notes": [

            ],
            "_validation_status": {

            },
            "_submitted_by": null
        }
    ]
}

The first chunk returns status code 415. I guess this is caused by bad JSON format.

There are 2 versions of the API; is the JSON structure the same for both versions? If they are different can I also get a sample for the v1 version?

Ideally, I want to to be able to call all the API functionalities in a single R package. I have to delete/resubmit/edit a lot of submissions and the web UI is inadequate for this.

I also searched for existing packages in CRAN, nothing fits my use case.

Thanks.