# How to call the platform.api.get() in user.session.post.post\_process?

**URL:** <https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277>\
**Category:** Server-Side Scripting\
**Created:** [February 27, 2016, 7:39am UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277 "2016-02-27T07:39:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamfactorydev](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dreamfactorydev](https://community.dreamfactory.com/u/dreamfactorydev)\
**Post date:** [February 27, 2016, 7:39am UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277/1 "2016-02-27T07:39:02Z")

</div>

I’m trying to append the **venue\_id** with user/session returned resource. I have used the following script in my **user.session.post.post\_process**

var lodash = require(“lodash.min.js”);

```
//throw platform.session.session_token;
var x = '"X-Dreamfactory-Session-Token:"'+ platform.session.session_token +'"';
//throw x;
var options = {
"HEADERS": ["Content-type: application/json", x]
};
    var venue = platform.api.get('treat_well/_table/tw_venue',options);
    var id = venue.content.resource[0].venue_id;
throw id;

```

But it throws

> Cannot read property ‘0’ of undefined

I tried the following script in elsewhere except this **user.session.post.post\_process** , It’s working

```
var lodash = require("lodash.min.js");
    var venue = platform.api.get('treat_well/_table/tw_venue');
    var id = venue.content.resource[0].venue_id;
throw id;

```

I thought in user/session that there might be session-token header is missed that’s why i have appended the header as follwing in user/session

```
var x = '"X-Dreamfactory-Session-Token:"'+ platform.session.session_token +'"';
//throw x;
var options = {
"HEADERS": ["Content-type: application/json", x]
};

```

What’s the mistake that i have missed in user/session post\_process  
Please help me

---

<div class="post-metadata">

**Author:** ![Mike\_Harvey](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/mike_harvey/32/572_2.png) [@Mike\_Harvey](https://community.dreamfactory.com/u/Mike_Harvey)\
**Post date:** [February 27, 2016, 11:57am UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277/2 "2016-02-27T11:57:23Z")

</div>

You need to get the user session first:

`var session = platform.api.get('user/session'); var_dump(session); //dump all to df log for debugging var token = session.content.session_token; //sets var to the token string var_dump("dumping session token");//dump token to log for debugging var_dump(token); var x = '"X-Dreamfactory-Session-Token:"'+ token +'"'; var options = { "HEADERS": ["Content-type: application/json", x] };`  
var\_dump(options);//dump debug options

`

---

<div class="post-metadata">

**Author:** ![dreamfactorydev](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dreamfactorydev](https://community.dreamfactory.com/u/dreamfactorydev)\
**Post date:** [February 27, 2016, 12:10pm UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277/3 "2016-02-27T12:10:03Z")

</div>

@Mike_Harvey Why not we use the **platform.session.session\_token** to get the current user token ?  
If i try your scripts too when i call the

```
var venue = platform.api.get('treat_well/_table/tw_venue',options);
throw venue.content.resource[0].venue_id

```

It still gives the error as

> Cannot read property ‘0’ of undefined

Why it’s happening there?

---

<div class="post-metadata">

**Author:** ![dreamfactorydev](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dreamfactorydev](https://community.dreamfactory.com/u/dreamfactorydev)\
**Post date:** [February 27, 2016, 12:15pm UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277/4 "2016-02-27T12:15:21Z")

</div>

Can you say how to debug the scripting execution in DSP? Just i want to check what’s the error is returning while the execution of **platform.api.get(‘treat\_well/\_table/tw\_venue’,options);**?

It seems that some header or something gets failure while calling

> platform.api.get(‘treat\_well/\_table/tw\_venue’,options); in user/session post\_process.

**But this api is working when i call in elsewhere except the user/session…**

---

<div class="post-metadata">

**Author:** ![Mike\_Harvey](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/mike_harvey/32/572_2.png) [@Mike\_Harvey](https://community.dreamfactory.com/u/Mike_Harvey)\
**Post date:** [February 27, 2016, 4:34pm UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277/5 "2016-02-27T16:34:27Z")

</div>

You can use the **platform.session,session\_token** provided you are logged in. I have done a simple test to dump the platform and event objects in the user.session post event and they return null which means you are in fact not logged in (yet) during a user/session post event. Any other post event after session, you’re probably fine. But in this case I think it’s a chicken/egg thing:

var\_dump(event) returned:  
`[27-Feb-2016 16:24:30 UTC] REST Exception #404 > Could not find a service for dreamfactory`

and var\_dump(platform) returned:  
`[27-Feb-2016 15:40:11 UTC] REST Exception #400 > Bad request. No token or api key provided.`

**If you are attempting to append a param to the session response** , you will need to log in first (get a session then pass session and api\_key to your table call. But since the session you want to modify doesn’t exist during the event, i’m not sure how you would extend it. Good question though (if it’s even possible). I’ve found nothing else on how to do this. Knowing this, I would append the session var after login in a separate call.

As for logging and debugging:  
From your dreamfactory install folder to can tail storage/logs/dreamfactory.log. On Bitnami Windows for example its:

C:\Bitnami\dreamfactory-2.1.0-4\apps\dreamfactory\htdocs\storage\logs\dreamfactory.log

var\_dumps and errors typically are logged in dreamfactory.log (unless you have significantly customized your install). While debugging i would **var\_dump** and not **throw** until you are sure you are retrieving what you want, and check the log. That is my preference as I have seen that using throw interferes with var\_dumps or debugging output in the log (probably due to event propagation between v8js and php). A DF engineer may have more clarification on this.

Instead of throwing, do this to see what your _venue.content.resource_ is returning (assuming you are logged in):

`var_dump(venue.content.resource);`

If you don’t see values in your array in the log, that would be the reason for your error.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![dreamfactorydev](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@dreamfactorydev](https://community.dreamfactory.com/u/dreamfactorydev)\
**Post date:** [February 27, 2016, 6:05pm UTC](https://community.dreamfactory.com/t/how-to-call-the-platform-api-get-in-user-session-post-post-process/2277/6 "2016-02-27T18:05:01Z")

</div>

Yes bro var\_dump and dreamfactory log are helped to recover from troubles. I have the issue in the following link can you figure out it?

> [@Accessing the custom field in record level access filtering of role tab](https://community.dreamfactory.com/t/accessing-the-custom-field-in-record-level-access-filtering-of-role-tab/2279):
>
> Is it possible to add extra fields (venue\_id) in the record level access filtering in role tab (venue\_id = {user.venue\_id}) if so then how about the procedures to accomplish it? I have tried in user/session post.post\_process scripting , appended the venue\_id with returned response. But it’s not worked for me. I want to achieve this context if you have any other way I’ll be appreciated by it. Thanks.
