How can I retrieve,add data using Quickbase API and javascript - javascript

I am very new to Quickbase.
I want to query the quickbase using javascript to get a table records and also insert to it.
How should I do this?
Any help is highly appreciated.

To improve #rtpHarry's answer, the JavaScript SDK he is referencing has seen better days. It hasn't been updated in 2 years, and doesn't work in IE11.
Now this is a shameless plug, full disclosure, I am the author of this module;
But Node-QuickBase is much, much easier to use and works both in the browser and on the server - no code change.
Here is an example:
Within Nodejs:
var QuickBase = require('quickbase');
var quickbase = new QuickBase({
realm: 'www',
appToken: '*****'
});
quickbase.api('API_Authenticate', {
username: '*****',
password: '*****'
}).then(function(result){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
}).then(function(result){
return result.table.records;
});
}).map(function(record){
return quickbase.api('API_EditRecord', {
dbid: '*****',
rid: record[3],
fields: [
{ fid: 12, value: record[12] }
]
});
}).then(function(){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
});
}).then(function(result){
console.log(result);
}).catch(function(err){
console.error(err);
});
Within the Browser:
<script type="text/javascript" src="quickbase.browserify.min.js"></script>
<script type="text/javascript">
var quickbase = new QuickBase({
realm: 'www',
appToken: '*****'
});
quickbase.api('API_Authenticate', {
username: '*****',
password: '*****'
}).then(function(result){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
}).then(function(result){
return result.table.records;
});
}).map(function(record){
return quickbase.api('API_EditRecord', {
dbid: '*****',
rid: record[3],
fields: [
{ fid: 12, value: record[12] }
]
});
}).then(function(){
return quickbase.api('API_DoQuery', {
dbid: '*****',
clist: '3.12',
options: 'num-5'
});
}).then(function(result){
console.log(result);
}).catch(function(err){
console.error(err);
});
</script>

Before you begin you need to set up a user in QuickBase.
In order for you to use the API you need to have a developer key.
There is a JavaScript SDK that you can use which is available on GitHub. This will shield you from the details of the API.
However, this doesn't let you use this inside any random webpage if that's what you're attempting:
HTML pages using QuickBaseClient.js must be hosted within QuickBase
applications as file attachments or as text (code) pages because web
browsers only allow JavaScript code to access the web site the
JavaScript originated from.
If you do want do that then there are workarounds.

Related

what is the use of resize:detect azure chatbot node js

I would like to know why we have resize:detect option in renderwebchat function for azure chat bot.Can someone explain me whats the outcome or whats the use of this option.
window.WebChat.renderWebChat({
renderMarkdown: markdownIt.render.bind(markdownIt),
directLine: window.WebChat.createDirectLine({
token: '#ViewData["DirectLineToken"]'
}),
user: {
id: 'test#xx.com,test#xx.com',
name: 'You',
OverrideBlockAccess: '#ViewData["OverrideBlockAccess"]',
LoggedInUserEmail: '#Html.Raw(ViewData["LoggedInUserEmail"])',
UserEmail: '#Html.Raw(ViewData["UserEmail"])'
},
bot: { id: 'HPICEBoTAPP' },
resize: 'detect',
userId: '#Html.Raw(ViewData["UserEmail"])',
styleOptions: styleOptions
}
You can see the properties that can be passed to renderWebChat here: https://github.com/microsoft/BotFramework-WebChat/blob/master/docs/API.md
Notice that there is no user, bot, or resize property.

WooCommerce Nodejs Wrapper returns undefined

I am learning to work with the WooCommerce API and I am trying to modify the payment address and the shipping address of a user, but I get this error all the time and I do not understand what I am doing wrong.
The error:
TypeError: undefined is not a function
This is my code:
var WooCommerceAPI = require("woocommerce-api");
var api = new WooCommerceAPI({
url: 'https://site.es/',
consumerKey: 'ck_xxxx',
consumerSecret: 'cs_xxxx',
wpAPI: true,
version: 'wc/v3'
});
const data = {
first_name: "James",
billing: {
first_name: "James",
postcode: "99502",
},
shipping: {
first_name: "James",
postcode: "99502",
}
};
api.putAsync('customers/33', data).then(function(result) {
console.log(result);
});
I would really appreciate any help, because really, I don't know what's wrong. I have read a lot about this and I don't see the error.
Regards.
You are using an outdated version of the library. Use the following one in which all the methods are promisified by default - so, you don't have to perpend "Async" any more.
https://github.com/woocommerce/woocommerce-rest-api-js-lib
const WooCommerceRestApi = require("#woocommerce/woocommerce-rest-api").default;
const api = new WooCommerceRestApi({
url: "http://example.com",
consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
version: "wc/v3"
});
api.put("customers/33", data)
.then((response) => {
...

How to combine two `hello.init` into one?

I am trying to use hello.js init API to sign in Microsoft Graph later. The code below is how I am doing now and it works.
repo
However, is there a way to combine these two hello.init into one? Thanks
hello.init({
msft: {
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
}
});
hello.init({
msft: myAppId
}, {
redirect_uri: window.location.href
});
I got the answer from the creator of hello.js Andrew Dodson on GitHub.
hello.init ({msft:appid}) is short for hello.init ({msft:{id:appid}})
so you just need to define an id prop on your definition and it'll all
work. Fyi this is undocumented and may change in the future.
So in my case, the solution is
hello.init({
msft: {
id: myAppId,
oauth: {
version: 2,
auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
},
scope_delim: ' ',
form: false
},
},
{ redirect_uri: window.location.href }
);

Using html-pdf with dynamic data

Currently I am testing html-pdf module to generate pdfs from html. And I have successfully generated one. But the issue is that the text/data in the html is fixed at the moment.
What I am trying to do is have an html form on the front-end which the user fills and then generate a pdf which includes the content the user typed.
What I have done so far:
app.post('/pdf',function(req, res) {
pdf.create(html, options).toFile('./businesscard.pdf', function(err, res) {
if (err) return console.log(err);
console.log(res);
});
});
Is this possible using html-pdf? Any help will be greatly appreciated.
Unfortunately, html-pdf module can't handle the dynamic data. You can take a look at the phantomjs which does the screen capture.
In fact, html-pdf module uses "phantomjs" at background. However, it uses the small feature of phantomjs.
You can check dynamic-html-pdf
Just follow the steps:
Install using this command npm install dynamic-html-pdf --save
Create html template
Create pdf with below code:
var fs = require('fs');
var pdf = require('dynamic-html-pdf');
var html = fs.readFileSync('template.html', 'utf8');
pdf.registerHelper('ifCond', function (v1, v2, options) {
if (v1 === v2) {
return options.fn(this);
}
return options.inverse(this);
})
var options = {
format: "A3",
orientation: "portrait",
border: "10mm"
};
//Your dynamic data
var users = [
{
name: 'aaa',
age: 24,
dob: '1/1/1991'
},
{
name: 'bbb',
age: 25,
dob: '1/1/1995'
},
{
name: 'ccc',
age: 24,
dob: '1/1/1994'
}
];
var document = {
type: 'buffer', // 'file' or 'buffer'
template: html,
context: {
users: users
},
path: "./output.pdf" // it is not required if type is buffer
};
pdf.create(document, options)
.then(res => {
console.log(res)
})
.catch(error => {
console.error(error)
});
I was finding solution for the same and got around one.
https://medium.com/free-code-camp/how-to-generate-dynamic-pdfs-using-react-and-nodejs-eac9e9cb4dde
you can checkout this work around done in the blog.
He simply called a function that returns an HTML string and he use backticks for dynamic data.

Creating an envelope from a template returning "UNSPECIFIED_ERROR"

When I try to create an envelope from a template I get a response of:
{ errorCode: 'UNSPECIFIED_ERROR',
message: 'Non-static method requires a target.' }
Here's what I'm doing so far:
First I login, which returns
{ loginAccounts:
[ { name: '*****',
accountId: '*****',
baseUrl: 'https://demo.docusign.net/restapi/v2/accounts/******',
isDefault: 'true',
userName: '***** ********',
userId: '*******-*****-*****-*****-*********',
email: '********#*******.com',
siteDescription: '' } ] }
So then I take the baseUrl out of that response and I attempt to create the envelope. I'm using the hapi framework and async.waterfall of the async library, so for anyone unfamiliar with either of these my use of the async library uses the next callback to call the next function which in this case would be to get the url for the iframe, and with our usage of the hapi framework AppServer.Wreck is roughy equivalent to request:
function prepareEnvelope(baseUrl, next) {
var createEntitlementTemplateId = "99C44F50-2C97-4074-896B-2454969CAEF7";
var getEnvelopeUrl = baseUrl + "/envelopes";
var options = {
headers: {
"X-DocuSign-Authentication": JSON.stringify(authHeader),
"Content-Type": "application/json",
"Accept": "application/json",
"Content-Disposition": "form-data"
},
body : JSON.stringify({
status: "sent",
emailSubject: "Test email subject",
emailBlurb: "My email blurb",
templateId: createEntitlementTemplateId,
templateRoles: [
{
email: "anemailaddress#gmail.com",
name: "Recipient Name",
roleName: "Signer1",
clientUserId: "1099", // TODO: replace with the user's id
tabs : {
textTabs : [
{
tabLabel : "acct_nmbr",
value : "123456"
},
{
tabLabel : "hm_phn_nmbr",
value : "8005882300"
},
{
tabLabel : "nm",
value : "Mr Foo Bar"
}
]
}
}
]
})
};
console.log("--------> options: ", options); // REMOVE THIS ====
AppServer.Wreck.post(getEnvelopeUrl, options, function(err, res, body) {
console.log("Request Envelope Result: \r\n", JSON.parse(body));
next(null, body, baseUrl);
});
}
And what I get back is:
{ errorCode: 'UNSPECIFIED_ERROR',
message: 'Non-static method requires a target.' }
From a little googling it look like 'Non-static method requires a target.' is a C# error and doesn't really give me much indication of what part of my configuration object is wrong.
I've tried a simpler version of this call stripping out all of the tabs and clientUserId and I get the same response.
I created my template on the Docusign website and I haven't ruled out that something is set up incorrectly there. I created a template, confirmed that Docusign noticed the named form fields, and created a 'placeholder' templateRole.
Here's the templateRole placeholder:
Here's one of the named fields that I want to populate and corresponding data label:
As a side note, I was able to get the basic vanilla example working without named fields nor using a template using the docusign node package just fine but I didn't see any way to use tabs with named form fields with the library and decided that I'd rather have more fine-grained control over what I'm doing anyway and so I opted for just hitting the APIs.
Surprisingly when I search SO for the errorCode and message I'm getting I could only find one post without a resolution :/
Of course any help will be greatly appreciated. Please don't hesitate to let me know if you need any additional information.
Once I received feedback from Docusign that my api call had an empty body it didn't take but a couple minutes for me to realize that the issue was my options object containing a body property rather than a payload property, as is done in the hapi framework.

Categories

Resources