No announcement yet.

Create entity with assigned user and delete followers by API

  • Filter
  • Time
  • Show
Clear All
new posts

  • Create entity with assigned user and delete followers by API

    Hello! I've created a custom entity and set up throught API an assigned user, but I don't want that user to be a follower of that entity (unless he does it manually after).
    My http call goes to: "myespourl/api/v1/myEntity/Entity_Id/followers" with method "DELETE" and without payload.
    Response is code 404, any other http request is working fine. Permissions for the role and api user are: "Follower Management Permission" to Al​​l and myEntity permissions full access. Any help is wellcome!

  • #2
    Hi fernando.giacomino,

    Please try to use the following HTTP request: myespourl/api/v1/myEntity/Entity_Id/subscription, with DELETE method and without payload.
    Perhaps it will suit you.


    • #3
      Thanks lazovic! That route works perfect. I copy "/followers" route from webbrowser console when manually delete followers.


      • lazovic
        lazovic commented
        Editing a comment
        Please keep in mind that my solution is not absolutely correct and it is better not to use it too often, only when creating a record, as you are doing now.

    • #4
      But no, http delete was ok, code 200, but actually no change was made on entity followers list.


      • #5
        Some testing: if I make a PUT with that route "/subcription" and {'isFollowed':false} as payload, api adds the api user as follower! If then I make a DELETE to that route, take off the api user from the followers list, but no wipe out other followers.


        • #6

          Please see the following screenshot:

          Click image for larger version

Name:	image.png
Views:	167
Size:	22.3 KB
ID:	90312

          This is a screenshot of Send HTTP Request Action in Workflow (a feature from the Advanced Pack extension) that removes the User from the list of followers of the record he/she created.
          As you can see, the DELETE method with the filled payload is being used here. This solution works great, I tested it.

          So, in this case, I suggest that you familiarize yourself with the Advanced Pack extension and Workflows, if you do not already have it, on the demo or cloud version of EspoCRM, or if your service for sending requests allows you to use the DELETE method with a filled payload, use it.​


          • lazovic
            lazovic commented
            Editing a comment
            Now I'm working on deleting all followers.

        • #7
          I wish to buy advanced pack, love workflows and bpm, but euro exchange rate right now in our country is too high. Anyway, that action works, clean that user from followers, but sends an error response: TypeError: Cannot read properties of undefined (reading 'id')


          • fernando.giacomino
            fernando.giacomino commented
            Editing a comment
            Sorry, with that data works fine. Sending DELETE to "myEspoUrl/api/v1/myEntity/myEntityId/followers" with payload {'id': 'currentFollowerUserId'} I receive response 'true'. Thanks for the help!

        • #8

          It's good that you made it work.

          Just in case, I show the screenshots of actions in Workflow that remove all followers (actions must be placed in a set order, as in the screenshots):

          Click image for larger version  Name:	image.png Views:	0 Size:	44.9 KB ID:	90325
          Click image for larger version  Name:	image.png Views:	0 Size:	22.6 KB ID:	90326

          Execute Formula Script Code:
          $getResponce = json\retrieve($_lastHttpResponseBody, 'list');
          $getResponceEncode = json\encode($getResponce);
          $i = 0;
          $followersIds = list();
          $i < array\length($getResponce),
          $followersIds = array\push($followersIds, json\retrieve($getResponceEncode, string\concatenate('', $i, '.id'))
          $i = $i + 1;
          Last edited by lazovic; 04-05-2023, 05:50 PM.