Forum Discussion

Peter_Taraldsen's avatar
Peter_Taraldsen
Contributor
4 years ago

Issues with batched queries

Hi, 
I'm trying to create a batch request fetching the latest posts in a users favorite areas, the number of unread messages and the number of notifications.

I have had some partial success so far but I've run into two issues:

I can't find any documentation on how to do ordering in a json query.

I can't constrain the query for notification_feed to a specific user in api/v2 as I could in api/v1. Is there any other good solutions for getting the notification count for a user

[
    {
        "query":{
            "messages": {
                "fields": [ "id""subject""teaser""body""view_href""post_time""conversation.featured""conversation.style""conversation.last_post_time""conversation.last_post_time_friendly""author.id""author.href""author.view_href""author.login""author.avatar.message""board.id""board.title""board.parent_category.title""metrics""kudos.sum(weight)" ],
                "constraints": [ {"category.id": {"in": ["<<category1>>",   <<category2>>"]}}, {"depth": {"="0}} ],
                "limit"5
            }
        }
    },
    {
        "query":{
            "inbox_notes": {
                "fields": ["id""is_read"],
                "constraints": [ {"user.id": {"=" : "<<id>>"}}, {"unread_only": {"="true}}]
            }
        }
    },
    {
        "query":{
            "notification_feeds": {
                "fields": ["id"]
            }
        }
    }
]
  • SuzieH's avatar
    SuzieH
    4 years ago

    Peter_Taraldsen I suspect that you're right about the notification counts being returned only for the user making the call. I wonder if there is something you can do by making the call with a session key for a different user. We have an example of this in Create subscriptions for another user

    This might be too heavy to do within the /batch endpoint tho -- if even possible... Keep performance in mind. AdamN TysonN thoughts?

    Requirements

    • You must have access to a user account with Switch to another user permission.
    • You must make your request using Session Key Authentication.


    Basic Steps

    • Create a session key for yourself using a Community account with the Switch to another user permission.
    • Create a second session key for the subscriber using your retrieved session key.
    • Make your query using the second session key.

     

4 Replies

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    4 years ago

    Hi Peter_Taraldsen I'm reaching out to Engineering for an answer on this. I'm not finding an example for sorting in our external or internal docs either.

    [Edit] I found an example buried in The Community API v2 request in a table under the Request body format for JSON-based queries section. Please let me know if this helps.

    AshishKe Does your team know of a solution for getting the notification count for a user with API v2 so that he doesn't need to make a separate call to v1?

     

  • Yes, the "sorts" worked perfectly 🙂 thanks SuzieH  . Now I just need to know how to do get the Notification counts for the users. I assume since there are no constraints available the endpoint only returns the notification feed for the authorized user making the call.

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    4 years ago

    Peter_Taraldsen I suspect that you're right about the notification counts being returned only for the user making the call. I wonder if there is something you can do by making the call with a session key for a different user. We have an example of this in Create subscriptions for another user

    This might be too heavy to do within the /batch endpoint tho -- if even possible... Keep performance in mind. AdamN TysonN thoughts?

    Requirements

    • You must have access to a user account with Switch to another user permission.
    • You must make your request using Session Key Authentication.


    Basic Steps

    • Create a session key for yourself using a Community account with the Switch to another user permission.
    • Create a second session key for the subscriber using your retrieved session key.
    • Make your query using the second session key.

     

  • TedV's avatar
    TedV
    Khoros Alumni (Retired)
    4 years ago

    Hi @Peter_Taraldsen,

     

    If one of the replies successfully answered your question, would you mind marking it as an accepted solution, please?

     

    Thanks!