Question

Photo of Ben Wiley

0

How to use the REST API to modify a person

I'm working on a project that uses the Rock REST API.  My goal at the moment (baby steps) is to update a person's nickname.  The OData video doesn't seem to address PUT/POST/PATCH, just GET.  Also, I see the official documentation is coming soon.

I am using a rest client to GET api/People/3.  I get JSON as expected.

Now to update that nickname:  I've tried POST, PUT, and PATCH to api/People/3 with {"NickName": "Newnickname"} in the body.  Doing this I get a 400.

I've also tried copying the entire JSON object from the GET response, changing the nickname value, and then sending it all back again with PUT, POST, and PATCH.  Doing any of these this I get a 500.

What is the proper way to update an entity through the API?  Is there a way to update one (or a small subset of) attributes?

 

NOTE: I am not using .NET, so I don't have direct access to the Rock entity type classes.

 

UPDATE: I was able to modify a new person's nickname that did not have a Suffix.  I did this by PUT to api/People/:id with the entire JSON document received by GET to the same endpoint and then changing the nickname field.  But then I added a suffix to that person through the web client.  The GET request sends a nested JSON object for SuffixValue.  I tried the PUT with the nested object and also tried removing the SuffixValue object altogether (leaving the seperate SuffixValueId attribute), but got a 500 for everything I tried.

  • Photo of David Turner

    2

    To update a record in Rock, you would use the PUT endpoint ( e.g. api/people/3 ) and include the object in the body ( the POST is used to add new records ). This most difficult thing right now is knowing what the object should look like since the GET will return several additional "virtual" properties that should not be included when doing a PUT/POST ( we're working on ways to make this easier to determine ).  This is an example of what the person object should look like

    {
        "IsSystem": false,
        "RecordTypeValueId": 1,
        "RecordStatusValueId": 3,
        "RecordStatusReasonValueId": null,
        "ConnectionStatusValueId": 65,
        "ReviewReasonValueId": null,
        "IsDeceased": false,
        "TitleValueId": null,
        "FirstName": "Theodore",
        "NickName": "Teddy",
        "MiddleName": null,
        "LastName": "Decker",
        "SuffixValueId": null,
        "PhotoId": 36,
        "BirthDay": 10,
        "BirthMonth": 2,
        "BirthYear": 1977,
        "Gender": 1,
        "MaritalStatusValueId": 143,
        "AnniversaryDate": null,
        "GraduationYear": 1994,
        "GivingGroupId": 51,
        "Email": "ted@rocksoliddemochurch.com",
        "IsEmailActive": true,
        "EmailNote": null,
        "EmailPreference": 0,
        "ReviewReasonNote": null,
        "InactiveReasonNote": null,
        "SystemNote": null,
        "ViewedCount": null,
        "PrimaryAliasId": null,
        "Id": 2,
        "Guid": "8fedc6ee-8630-41ed-9fc5-c7157fd1eaa4",
        "ForeignId": null
    }

    You also need to make sure that your request has the Content-Type=application/json header.

  • Photo of David Stevens

    1

    Nic, we've implemented a PATCH method and pushed it to core.  It's in the develop branch now and would probably be in the next release.

  • Photo of Nic De Vries

    0

    Any updates or new information on this? Thanks.

  • Photo of Nic De Vries

    0

    Super quick response. Thank you!