Menu

API public_log and $current_contact->id$ behavior

Alexey
2024-10-08
2024-10-09
  • Alexey

    Alexey - 2024-10-08

    Hi, I'm still tryna make my integration correctly and now I'm stuck with the question : who is $current_contact$, when I create a comment via REST API.
    I want to send all the comments to my handler, where I want to send comments created by Agents to one app and comments created by users(via API) - to another...
    It's possible?

    There is my request, where I set the user_id of the comment :

    {    "operation": "core/update",
        "class": "UserRequest",
        "key": "114",
    "comment":"test",
        "fields": {       
            "public_log": {
    "add_item": {
    "message": "new customer comment",
    "user_id": "3"
                       }
            }
        }}
    

    In response, I can see, that the owner of the comment is the correct user :

                            {
                                "date": "2024-10-08 19:54:09",
                                "user_login": "Test User",
                                "user_id": "3",
                                "message": "new customer comment",
                                "message_html": "<p>new customer comment</p>"
                            }
    

    And in web interface - it's showed as a UserId=3 comment.

    But, when I set up a webhook with the following payload :

    {
    "event": "comment_added",
    "ticket_id": "$this->id$",
    "contact": "$this->caller_id$",
    "agent":"$this->agent_id$",
    "current_username": "$current_contact->friendlyname$",
    "new_comment": "$this->head(public_log)$",
    "current_contact_id": "$current_contact->id$"
    }
    

    On my handler I see, that the Current_Contact is still my User.Id =1, instead of 3 :

    {
      "event": "comment_added",
      "ticket_id": "114",
      "contact": "15",
      "agent":"7",
      "current_username": "Admin Admin",
      "new_comment": "new customer comment",
      "current_contact_id": "1"
    }
    
     
  • Alexey

    Alexey - 2024-10-09

    Can someone give me some advice, please?

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2024-10-09

    I'd assume current contact would also be the API user (the one you authenticated with). So that's likely your admin account.

    In the webhook, the current contact is then still the API user.

     
    • Alexey

      Alexey - 2024-10-09

      Thanks for the answer!
      Yeah, but this means I have to create a bunch of users, whom is allowed REST API profile.
      And even if I make it, I get the error :

      {
          "code": 1,
          "message": "Error: Portal user is not allowed"
      }
      

      So, that's only for privileged users in the system, not for portal users....

      Maybe there is an another way to reach out - who is the author of the comment, in payload?

      How can I get the author of the comment?
      $this->head(public_log) returns only text...

      Or only with some "JOIN Condition" in trigger OQL?

       
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2024-10-09

        As a work-around: you could add an extra (hidden) field in the class. During your core/update, you also set this field (e.g. to your user ID 3).

        As a second step, add the same logic when the ticket is manually updated by an agent in the console - so it's set before it's saved to the database and the trigger is executed. It's possible to list the changes; if it's already set (e.g. this method would also be executed during your API call), it should be ignored. Otherwise it will also be reset to your iTop API user ID rather than the agent ID.

        Then in the notification; rely on this field rather than current contact?

         
        👍
        1
  • Alexey

    Alexey - 2024-10-09

    OK, Thank you...Seems like it's the only way to make it. I'll try this one.
    I'll set the field = 3, when comment is added and let it empty, when agent will add the comment.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.