Forum Discussion

raZorTT's avatar
raZorTT
Icon for Cirrostratus rankCirrostratus
Jun 05, 2019
Solved

REST API add records to data group (v14.1.)

Hi,

 

I'm trying to update the records in a data group via the REST API, but when I use the following BODY in the PUT

 

{
    "records": [
        {
            "name": "test",
            "data": "data"
        }
    ]
}

 

I get the following error

 

{
    "code": 400,
    "message": "0107074b:3: Unable to change data group (/Common/testdg) type.  Must remove existing entries first.",
    "errorStack": [],
    "apiError": 3
}

Any thoughts appreciated.

 

Cheers,

Simon

4 Replies

  • Thanks, Dario

    That was very useful

    I managed to get the records to add using the PATCH method described in the article

    To add a string record I had to use the following querystring, where test is the name of the record and stuff being the value

    /mgmt/tm/ltm/data-group/internal/~Common~testdg?options=records add { test { data stuff } }

    That returned the expected result

    {
        "kind": "tm:ltm:data-group:internal:internalstate",
        "name": "testdg",
        "partition": "Common",
        "fullPath": "/Common/testdg",
        "generation": 184,
        "selfLink": "https://localhost/mgmt/tm/ltm/data-group/internal/~Common~testdg?options=records+add+%7B+test+%7B+data+stuff+%7D+%7D&ver=14.1.0.3",
        "type": "string",
        "records": [
            {
                "name": "test",
                "data": "stuff"
            }
        ]
    }

    Would still be interested to hear if using the PUT method is a known issue??

    Cheers,

    Simon

    • The behavior of PUT/PATCH was changed lastly (new releases).

       

      The relation between tmsh and icontrol is similar to this:

      GET - list/show

      POST - create

      PUT - update

      PATCH - modify

      DELETE - delete

       

  • Looks like I should have paid more attention to the error.

    I noticed it was complaining about trying to change the type, so adding the type:string to the JSON body resolved my issue.

    {
        "type":"string",
        "records": [
            {
                "name": "test",
                "data": "stuff"
            },
            {
                "name": "testing",
                "data": "more stuff"
            }
        ]
    }