# Creating custom node and the getting accesstoken and then making api call on single custom node

**URL:** <https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605>\
**Category:** Developing Nodes\
**Created:** [25 February 2021 08:32 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605 "2021-02-25T08:32:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sudthakur](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Sudthakur](https://discourse.nodered.org/u/Sudthakur)\
**Post date:** [25 February 2021 08:32 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605/1 "2021-02-25T08:32:12Z")

</div>

Hello,

I created the custom node called getMachines  
where I will be supplying the ClientId and ClientSecret in input of the node.  
And after that i will be accessing the accessToken to get the API data.  
After that on the accesstoken want to fetch the machines api.

and this all process should be in one single custom node.

Please help me, how to achieve this solution.

Thanks,  
Sudthakur

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 February 2021 13:55 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605/2 "2021-02-25T13:55:56Z")

</div>

Nobody can help without more information than that. We can't guess the form of the token, how/where it is created, how long it is valid for, how it is renewed, what other requirements the API has, ...

---

<div class="post-metadata">

**Author:** ![Sudthakur](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Sudthakur](https://discourse.nodered.org/u/Sudthakur)\
**Post date:** [26 February 2021 05:29 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605/3 "2021-02-26T05:29:54Z")

</div>

Thanks for asking these question to myself also.

I want authentication through auth0 by grant\_type=client\_credentials, clientId and clientSecret available.  
want to get first the accesstoken by the above information passing through post method.  
And after getting the accesstoken want to fetch the api and get the json data.

Please help me on this, as new to this authentication things and with auth0 also.

and do please let me if more information is needed.

Thanks,  
Sudthakur

---

<div class="post-metadata">

**Author:** ![henrycosta05](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrycosta05/32/36350_2.png) [@henrycosta05](https://discourse.nodered.org/u/henrycosta05)\
**Post date:** [26 February 2021 21:08 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605/4 "2021-02-26T21:08:07Z")

</div>

Hi @Sudthakur,

To achieve that you have more than one option, and security ways.

1. store your keys securelly;

2. create the payload, headers and url as required by documentation

3. make de request

4. finaly get your `access_token`

in my opinion, first of all, store your secrets using **env variables**.  
[https://nodered.org/docs/user-guide/environment-variables](https://nodered.org/docs/user-guide/environment-variables)

After that you can retrive values using **function node**.  
[https://nodered.org/docs/user-guide/writing-functions#env](https://nodered.org/docs/user-guide/writing-functions#env)

OR

Use de **change node** to assign the env variable to required variable as API documentation  
[https://nodered.org/docs/user-guide/nodes#change](https://nodered.org/docs/user-guide/nodes#change)

the next step will be **request call**.  
set url, headers and boddy...  
[https://cookbook.nodered.org/http/#http-requests](https://cookbook.nodered.org/http/#http-requests)

if you done the above activities well, you will be able to receive your access\_token in `msg.payload`

from here, you can make the next request using the same knowledge to get the main information from API.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [26 February 2021 21:14 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605/5 "2021-02-26T21:14:46Z")

</div>

> [@henrycosta05](#):
>
> in my opinion, first of all, store your secrets using **env variables**.

Please remember that environment variables are easily picked out of memory - they are not a secure store. They can reduce exposure but they are not really a security mechanism. For that you need a secure keystore and good isolation between processes.

Having said that, they are probably good enough.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 April 2021 21:15 UTC](https://discourse.nodered.org/t/creating-custom-node-and-the-getting-accesstoken-and-then-making-api-call-on-single-custom-node/41605/6 "2021-04-27T21:15:15Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
