Jump to content
  • 0

Node js


bentleyj68

Question

5 answers to this question

Recommended Posts

  • 0

In case someone is looking to connect to the CASPIO API using NodeJS, here is the code sample to get the authentication token.

const https = require('https');
const querystring = require('querystring');

const data = querystring.stringify({
	"grant_type": "client_credentials",
    "client_id": "[INSERT CLIENT ID HERE]",
    "client_secret": "[INSERT CLIENT SECRET HERE]"
});

const options = {
	protocol: 'https:',
	host: '[INSERT CASPIO ACCOUNT HERE].caspio.com',
    path: '/oauth/token',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    }
};

const req = https.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();

 

Link to comment
Share on other sites

  • 0
On 12/10/2019 at 11:39 AM, douvega said:

In case someone is looking to connect to the CASPIO API using NodeJS, here is the code sample to get the authentication token.

const https = require('https');
const querystring = require('querystring');

const data = querystring.stringify({
	"grant_type": "client_credentials",
    "client_id": "[INSERT CLIENT ID HERE]",
    "client_secret": "[INSERT CLIENT SECRET HERE]"
});

const options = {
	protocol: 'https:',
	host: '[INSERT CASPIO ACCOUNT HERE].caspio.com',
    path: '/oauth/token',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    }
};

const req = https.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();

 

query params is legacy, but does not work either way.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...