Okay
  Public Ticket #3584220
Can't send placeholder user id in header for nested JSON
Closed

Comments

  • Victor Hugo Calderón González started the conversation

    I want to load data from REST API and send the user id to retrieve information related to the user. I created a nested JSON table and try to send the placeholder %CURRENT_USER_ID% in custom headers but when I receive the request the %CURRENT_USER_ID% is not replaced by the user id. This is the right way to do this? Or how to retrieve data related to the user?

    Also I see that I can select GET or POST method but I am not able to send body parameters for POST method. Thank you in advance

    Attached files:  nested_json.png

  •  1,877
    Miloš replied


    Hello,

    To begin, I want to extend my heartfelt apologies for the delayed reply, 

    which is due to an unexpectedly high volume of inquiries. 

    We truly value your patience during this period.

    -


    When it comes to using our Placeholders such as %CURRENT_USER_ID%  , %CURRENT_POST_ID% and others, it is not possible to use them like that in the Custom Headers as "key and value" pairs.

    As we explained on this Documentation for Nested JSON, this is how the Custom Headers function in our Plugin :

    In Custom Headers, you can enter the key name and the key value (for example mostly used API key authentication) or additional parameters in headers that are going to be used to access the data within the API. 

    Under the first key/value pair, there is an “Add row” button with which you can insert more header parameters.

    They function as pairs, so if you plan on using Custom Headers, you will need to populate both fields.

    6995460309.png

    9408515366.png

    So, in the Custom Headers values, you need to insert some API like key value pairs, it is not possible to use any of our dynamic Placeholders here.

    Please check this Documentation, that explains some basics how you can use our Placeholders. They are used to filter the Tables.



    3. Here is an example, if you already have a Nested JSON table loaded with some data and you wish to filter the Table to only load rows for the currently logged User ID :


    We have a workaround for non-editable ( linked to a file source) tables, 

    to restrict only showing the rows for the currently logged-in user.

    I will show you an example with a Table linked from Excel, but you can use the same 'logic' for JSON tables.

    - First, you would have to add a custom "user_id" column on the source Data side, which you can hide if needed in our plugin from the front-end. 

    We will add a predefined filter value to it, using a PlaceHolder "Current User ID";

    - Check that the filter type is set as "Text", as shown on this screenshot.

    8249361981.png

    - Here is how an example table linked to a source file looks before we make any changes, with visible filters above the table.

    7932387639.png

    And now, when we set the pre-filter, with Administrator logged in ( In our case, the user ID is 1), we only see rows matching that user ID.

    3633379684.png

    - (If you need more detailed information about using Place Holders in wpDataTables, here is our documentation about that https://wpdatatables.com/documentation/table-features/using-placeholders/);

    - The user_ID filter is still visible, which means, if someone changes/deletes this value, they could see the whole table.

    We will hide it from the front-end with some custom CSS added in the "Customize" section of the main table settings.

    - It should be easy to do, depending on your knowledge of HTML and CSS.

    You have to find the correct selector using the browser inspector tool, add the style "display:none" property to it, and it will disappear from the front-end.

    On our example table, the custom CSS is :

    #table_1_5_filter_sections  {
        display:none; }

    5537273103.png

    - Now, the user_ID filter is gone from the front-end.

    8120839900.png

    - Optionally, you can hide the user_id column from the front-end, if needed, either using the column settings tab or the "column list" button from the back end Admin area.

    1618300341.png

    - If you need more details about this, don't hesitate to contact us further.


    2. The Body Parameter :

    At the moment, we only have the built-in 'out of the box' option to add Header's in the Nested JSON authentication,

    and our developers are now aware that we have users who need the 'body' option to be added,

    so we will do our best to work on adding this as soon as possible.

    I just can't promise an exact ETA on it.

    If you wish to affect the development speed for that option, please feel free to search on our suggestions page

     to see if someone may be already suggested this feature. If you can't see it, feel free to add your suggestion there,  and as more people vote, the feature will move higher on the priority list.

    You can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    but you can certainly follow our changeLog page if you'd like ( it is also available in the plugin dashboard), where we state any changes/new features/bug fixes during updates;

    and our newsletter, so you're informed about new features, bug fixes, freebies, etc.

    -

    If you have coding skills ( or your own developer) and wish to achieve this now, there is a way with a custom solution.

    You can input the "body" through this filter:

    wpdatatables_filter_nested_json_endpoint_args

    In $endPointArgs  you can 'pack' the 'body' as we did for the Headers.

    ( a reference with more details here)

    So, with that filter, you can 'construct/pack' the 'body' along with the 'headers'.


    I hope that helps.

    Please note that using hooks requires certain level of programming skills and included support refers only to advice.



    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables