REST API - update person interests

Hi,

I'm trying to set/remove interests on the personinterest table using REST API.

From what I can tell there are no person/contact-interest endpoints.

So I'm guessing i somehow have to set this directly on the Person endpoint.

Looking here it seems to at least exist:

https://community.superoffice.com/documentation/sdk/SO.NetServer.Web.Services/html/v1PersonEntity_PatchPersonEntity.htm

I found a similar question here that never got answered (pretty much same but in my case it's Person).

https://community.superoffice.com/en/developer/forum/rooms/topic/netserver-api-group/web-services/how-to-add-contactinterest-with-rest/

 

So I guess the question is:
Does anyone have any example JSON to put/patch interests on a person object.

RE: REST API - update person interests

Hi Rikard,

Here is how to set the Interest of a person. You only need the interest Id and the Selected value:

 

PATCH /api/v1/Person/8

[
  {  
    "op": "add",
    "path": "Interests",
    "value": [
      {     
        "Id": "4",
        "Selected": true
      }
    ]
  }
]

Hope this helps!

Av: Tony Yates 3. sep 2019

RE: REST API - update person interests

Hi Tony,

Cheers, exactly what i was after.

Av: Rikard Fredlund 3. sep 2019

RE: REST API - update person interests

I'm guessing there is no way to mass update interests?

For example if I want to remove a certain interest from every single person.

Or is there any way to send an array containing the same but with "false" to whole Person endpoint instead of a specific person?
(I managed to delete, a bit weird to use patch + "op": "add" + "Selected": false to delete, but it works :), but only for a specific person for example api/v1/Person/5 )

 

What I'm after is that I first want to remove a certain interest from everyone. Then with some logic i want to set it back to the persons who fill certain criterias. And instead of doing thousands of calls to the same endpoint but with different person_id's I would prefer to make one big bulk call.

Av: Rikard Fredlund 3. sep 2019

RE: REST API - update person interests

Hi Rikard,

You will be surprised to know that yes, you can bulk update interested in the way you want. 

Please read to understand how this is done in code, and what functional rights are required, in the Bulk Update article

If sticking with the Restful API's, you need to use the /api/v1/BulkUpdate/Agent (POST) API.

Hope this helps!

Av: Tony Yates 3. sep 2019

RE: REST API - update person interests

Hi Tony,

I was indeed surprised by that answer, and happily so!

This will be most helpful and reduce the runtime greatly.

Thanks alot for all the answers, very helpful as always :)

Av: Rikard Fredlund 3. sep 2019

RE: REST API - update person interests

Hi,

I have now tried mass updating interests for Person object (It isn't as simple as it looks at first glance :)).

But I just can't seem to get it to work.

I first tried /api/v1/Agents/BulkUpdate/GetAvailableFields with the following JSON:
{
  "Tablename": "person"
}

Then i get back the following which i feel like i should be able to use:

{
        "CanSupportMultiUse": false,
        "DefaultShowInGui": true,
        "DefaultShowInSelector": true,
        "IsActive": false,
        "Key": "removeInterest",
        "ValueType": "single",
        "Mandatory": false,
        "EncodedDisplayName": "[SR_BULKUPDATE_FIELDVALUE_REMOVEINTERESTS]",
        "EncodedDisplayDescription": "[SR_BULKUPDATE_FIELDVALUE_REMOVEINTERESTS_TOOLTIP]",
        "IconHint": "Person",
        "ControlInfos": [
            {
                "TableRight": null,
                "FieldProperties": {},
                "Type": "removeInterests",
                "Label": null,
                "Dimension": 0,
                "ListProviderName": "PersInt",
                "ListProviderExtraInfo": null,
                "ListProviderPrimaryKeyName": null,
                "ListLeadText": null
            }
        ],
        "EncodedDataCaption": "[SR_BULKUPDATE_DATACAPTION_REMOVEINTERESTS]",
        "EncodedDataCaptionDescription": "[SR_BULKUPDATE_DATACAPTION_REMOVEINTERESTS_TOOLTIP]",
        "CurrentOperationType": null,
        "Values": [],
        "DisplayValues": [],
        "OperationInfos": [
            {
                "TableRight": null,
                "FieldProperties": {},
                "Key": "removeItems",
                "EncodedDisplayName": "[SR_BULKUPDATE_OPERATION_REMOVEITEMS]",
                "EncodedLeadTexts": null
            }
        ]
    }

I then try to update using:
Values[4]
But i only get:

{
  "Error": true,
  "ErrorType": "NullReferenceException",
  "Message": "Object reference not set to an instance of an object.",
  "ErrorSource": "SuperOffice.Services.Implementation"
}

(Not sure this is the correct way to select person_id's, or if it should somehow be in the JSON)
api/v1/Agents/BulkUpdate/ExecuteByEntityIds?$select=person.person_id&$filter=person.person_id gt 0

I just can't seem to figure out exactly how i should do this.

Are there any simple examples on how to do this. Specifically:
Update two separate person_id's with remove interests [4,8]
(or any other bulk update where i could derive it from)?

 

Av: Rikard Fredlund 26. sep 2019

RE: REST API - update person interests

Hi Rikard,

You are on the right track. The inclusion of the ODATA select statement at the top of the documentation is misleading. Please see the Request Body section of the documentation.

Because it is such a complex topic (dataflow and structures) I also cannot stress enough to read the whole article to understand the concepts involved. Do NOT just bang out the API's and hope you get it right.

Best regards.

 

 

Av: Tony Yates 26. sep 2019

RE: REST API - update person interests

As the documentation is quite scarce it's hard not to bang out the API's and hope I get it right :).

If I look the RequestBody for:

http://support.yourdomain.84r08.com/Sales/api/v1/Agents/BulkUpdate/ExecuteByEntityIds

I can see that this is needed:
FieldValueInfos: (array)
TableName: (string)
Context: (string)
Ids: (string)

After reading the article a few times alot of questions arise.
(What I want to do for this example is to remove the interest with pinterest_idx = 6 on the person with person_id = 5)
TableName: To me there are two options:
Person or Person.Interest.
I'm guessing it should be Person but I'm not sure...
Context: If I understand this one correctly, it can be whatever, just a friendly name for the operation?
Id's: This I feel should be the Id's i want the operation to update (in my case person_id = 5. "Ids": "5"

Now come the complex part with the FieldValueInfos...
Looking at the documentation there seem to be alot of info I don't need to use here. But after testing it seem at least some values are required (this is a test environment, so no problems testing :) ).

And after looking at the article i want to use the "Person.RemoveInterest" from "BulkUpdateSystem.PersonFieldValueKeys"

Where I'm currently banging my head is the following JSON.
For me this says, update the Id's (5) by removing the interest (6). ControlInfos and OperationInfos I don't think I need to use, but they seem to be required to get to send the request.

{
  "FieldValueInfos": [
    {
      "Key": "RemoveInterest",
      "ControlInfos": [
        {},
        {}
      ],

      "Values": [
        "6"
      ],

      "OperationInfos": [
        {},
        {}
      ]
    }
  ],
  "TableName": "Person",
  "Context": "whateverUpdate",
  "Ids": "5"
}

Would be quite useful with a bit more information and actual descriptions on the fields, and a "real" updating example instead of towards the made up tables :).

Av: Rikard Fredlund 30. sep 2019

RE: REST API - update person interests

Rikard:
Just a thought. As the Web Client Bulk Update-feature is using the REST API, it should be possible to set up a Bulk Update in the Web Client according to the specification that you are interested in to setup via the API and then monitor the whole Bulk Update process to see how the data is formatted and sent.

I don't know how far you can come with the Dev Tools in Chrome, but I often use Telerik Fiddler for this kind of monitoring. Sometimes you will have to be a bit creative if you are forced to use a HTTPS endpoint, but in this case I suppose you are able to let the site use HTTP for easier monitoring. Or you can just set up your own dev environment in a virtual machine to do this kind of analysis

I have thought of doing this myself, so that's because I had it fresh in mind. :)

/Marcus

Av: Marcus Svenningsson 1. okt 2019

RE: REST API - update person interests

That was a good idea Marcus, i was so sure Web used NetServer directly (not sure why), but as you stated it actually uses REST API.

With that in mind i made a selection bulk update on my labserver and with some F12 magic in the browser i could see the Network Post Request.

I now have it working on how to remove interests from Person object :).

I call the following BulkUpdate with the following JSON Body:
(And it removes interests 6,5 from the person_id 5.
It can probably be stripped down a bit, but might as well post the entire body).

http://support.yourdomain.84r08.com/Sales/api/v1/Agents/BulkUpdate/ExecuteByEntityIds

{
  "FieldValueInfos": [
  	{
      "CanSupportMultiUse": false,
      "DefaultShowInGui": true,
      "DefaultShowInSelector": true,
      "IsActive": true,
      "Key": "removeInterest",
      "ValueType": "single",
      "Mandatory": false,
      "EncodedDisplayName": "Intresse - ta bort",
      "EncodedDisplayDescription": "Ta bort intressen ...",
      "IconHint": "Person",
      "ControlInfos": [
        {
          "TableRight": null,
          "FieldProperties": {},
          "Type": "removeInterests",
          "Label": null,
          "Dimension": 0,
          "ListProviderName": "PersInt",
          "ListProviderExtraInfo": null,
          "ListProviderPrimaryKeyName": null,
          "ListLeadText": null
        }
      ],
      "EncodedDataCaption": "Intressen ...",
      "EncodedDataCaptionDescription": "Välj intressen som ska tas bort, i listan",
      "CurrentOperationType": "removeItems",
      "Values": [ "6", "5" ],
      "DisplayValues": [ "Decision Maker" ],
      "OperationInfos": [
        {
          "TableRight": null,
          "FieldProperties": {},
          "Key": "removeItems",
          "EncodedDisplayName": "Ta bort poster",
          "EncodedLeadTexts": null,
          "name": "Ta bort poster",
          "Name": "Ta bort poster",
          "id": "removeItems"
        }
      ],
      "TheKey": "removeInterest",
      "selected": false
    }
  ],
  "TableName": "person",
  "Context": "bulkupdatedialogpersons",
  "Ids": 5
  }

Big thanks to Tony and also to Marcus who tipped me over the edge towards the solution. Hopefully this can be useful for someone else in the future.

Av: Rikard Fredlund 1. okt 2019