I have checked all the the similar threads and didn't find what I was looking for. I've been struggling with this past few days.
I'm trying to make free/busy request.
Code is the same sometimes it returns calendar with no errors and some times I get the error below{
domain: "global",
reason: "notFound"}
Has anyone run into a similar problem?
googleapis.discover('calendar', 'v3').execute(function(err, client) {
var oauth2Client = new OAuth2Client(clientID, secret, callback);
oauth2Client.credentials = {
access_token: mytoken,
refresh_token: refreshtoken
}
client.calendar.freebusy.query({
"timeMin": day + 'T00:00:00' + finalTimeZone,
"timeMax": nextday + 'T00:00:00' + finalTimeZone,
'timeZone': timezone
}).withAuthClient(oauth2Client).execute(function(err, result) {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
});
result:
{
kind: "calendar#freeBusy",
timeMin: "2013-11-05T08:00:00.000Z",
timeMax: "2013-11-06T08:00:00.000Z",
calendars: {
email#gmail.com: {
errors: [
{
domain: "global",
reason: "notFound"
}
],
busy: [ ]
}
}
}
I got this same error message. In my case was missing the calendar id.
client.calendar.events.insert({
calendarId: 'my calendar id'
}, {
'start': { 'dateTime': '2014-03-03T01:00:00.000Z' },
'end': { 'dateTime': '2014-03-03T09:00:00.000Z' }
})
.withAuthClient(auth)
.execute(function(err, result){
if (err) return callback(err);
callback(null, result);
});
How to discover you calendar id: http://youtu.be/m_ph_hYT_SY
Usually the calendar id is your proper email or you can use the value 'primary'.
Related
there related but without response:
How to fix Error: Require at least one aggregateby? - fitness api
const fitness = google.fitness({ version: 'v1', auth });
fitness.users.dataset.aggregate(
{
aggregateBy: [
{
dataSourceId:
'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps'
}
],
bucketByTime: {
durationMillis: 86400000
},
userId: 'me',
startTimeMillis: 1584891702214,
endTimeMillis: 1584978102214
},
(err, res, aa) => {
if (err) return console.log('The API returned an error: ' + err);
console.log(res.data);
const events = res.data.items;
resolve(events);
}
);
and got
The API returned an error: Error: Require at least one aggregateby
How I can repair that?
solved:
https://github.com/googleapis/google-api-nodejs-client/issues/1749
correct version:
fitness.users.dataset.aggregate(
{
userId: 'me',
resource: {
aggregateBy: [
{
dataSourceId:
'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps'
}
],
bucketByTime: {
durationMillis: 86400000
},
startTimeMillis: 1584891702214,
endTimeMillis: 1584978102214
}
},
(err, res, aa) => {
if (err) return console.log('The API returned an error: ' + err);
console.log(res.data);
const events = res.data.items;
resolve(events);
}
);
I'm having trouble with the pre-authorization described here https://stripe.com/docs/charges#auth-capture.
The auth goes successful (capture params to false), I can store the ID of the carghe on my databse and I can see the uncaptured charge from my Stripe Dashboard.
Problem comes when I try to capture the charge, because it fails with Error: No such charge: <CHARGE_ID>.
Here is the code:
constructor(){
this.stripe = require('stripe')('<sk_test_mysecretkey>');
}
async captureCharge(chargeId) {
try {
/**
* https://stripe.com/docs/api/charges/capture
*/
return this.stripe.charges.capture(chargeId)
.then((charge) => {
return {
error: false,
success: true,
message: 'ChargeSuccesful',
code: 200,
charge: charge,
};
},
(err) => {
console.log("CAPTURE CHARGE ERROR: ", err);
return {
success: false,
error: err.type,
code: err.statusCode,
};
}
);
} catch (e) {
console.log('ERROR CAPTURE', e);
}
}
Even if I try with a POST to https://api.stripe.com/v1/charges/<CHARGE_ID>/capture with auth: Bearer <sk_test_mysecretkey> i get the same error:
{
"error": {
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such charge: <CHARGE_ID>",
"param": "charge",
"type": "invalid_request_error"
}
}
The uncaptured charge still exist on Stripe.
Thanks in advance.
UPDATE
I forgot to say that the charge isn't a simple charge, but it is a split payment with a shared customer. Stripe supports three approaches for processing split payment, I have choosed the direct charges:
async authorizationCharge(amount, merchantStripeId, billId, customerId) {
try {
var fee = 0.25;
/** Pre-Authorization Charge using a shared customer
* https://stripe.com/docs/charges#auth-capture
* https://stripe.com/docs/connect/shared-customers
*/
return this.stripe.tokens
.create(
{ customer: customerId },
{ stripe_account: merchantStripeId }
)
.then((oneTimeToken) => {
return this.stripe.charges
.create(
{
amount: Math.round(amount),
currency: 'eur',
application_fee: fee,
description: 'Bill ID: ' + billId,
source: oneTimeToken.id,
capture: false,
},
{ stripe_account: merchantStripeId }
)
.then((charge) => {
console.log('CHARGE: ', charge);
return {
error: false,
success: true,
code: 200,
charge: charge,
fee: fee,
};
},
(err) => {
// ERROR INFO:
// https://stripe.com/docs/api#error_handling
console.log('ERROR', err);
return {
success: false,
error: err.type,
code: err.statusCode,
};
}
);
},
(err) => {
// ERROR INFO:
// https://stripe.com/docs/api#error_handling
console.log('ERROR', err);
return { success: false, error: err.type, code: err.statusCode };
}
);
} catch (e) {
console.log(e);
}
}
Finally I understood the reason, I did not indicate the connected account (see the updated question).
return this.stripe.charges.capture(chargeId, { stripe_account: merchantStripeId }) <---- CONNECTED ACCOUNT
.then((charge) => {
...
}
I am closely following this documentation And When i try creating the api as they have done. But when i am making a call from postman, I am unable to make get request.
module.exports = {
"get": function (request, response, next) {
try{
var query = {
sql: 'UPDATE EmailVerification SET verified = #completed where id = #unique',
parameters: [
{ name: 'completed', value: request.query.completed,
name: 'unique', value: request.query.unique }
]
};
request.azureMobile.data.execute(query)
.then(function (results) {
console.log(results);
response.json("Verfied successfully");
}).catch(function (err) { console.log(err);
response.send(err);});
}
catch(ex)
{
console.log(ex);
response.send(ex);
}
}
};
And in the postman, I am making the call
https://<appname>.azurewebsites.net/api/emailtoken?completed=true&unique=4a642af0-75be-45dd-bd8d-3c91e93a8b9d
Any lead will be helpful.
Here is the screenshot of the output:
PS: I have updated my question with more details and changes.
You need to change the following lines of code:
parameters: [
{ name: 'completed', value: request.query.completed,
name: 'unique', value: request.query.unique }
]
to:
parameters: [
{ name: 'completed', value: request.query.completed },
{ name: 'unique', value: request.query.unique }
]
I have index not found exception when the first time I run my code for index creation,But second time it working good.
Here is my code
function searchIndex(callback){
client.search({
index: 'postgrescredentials-01',
type: 'credentials',
body: {
query: {
match: {
"username": "postgres"
}
},
}
},function (error, response,status) {
if (error){
console.log("search error: "+error)
}
else {
response.hits.hits.forEach(function(hit){
var ciphertext = hit._source.pswrd
callback(ciphertext)
})
}
});
};
exports.searchIndex = searchIndex;
encryptObj = enpyt.encrypt(password,function(encrypted){
client.index({
index: 'postgrescredentials-01',
id: '101',
type: 'credentials',
body: {
"username": "postgres",
"pswrd": encrypted
}
},function(err,resp,status) {
console.log(resp);
});
console.log("The encrypted password is-->",encrypted)
//Get The Searched Encrypted value
search.searchIndex(function(encryptedValue){
//Get the Decrypted Value
decrypt.decrypt(encryptedValue,function(decryptedValue){
console.log("The decrypted password is-->",decryptedValue);
});
});
})
Any idea why i am getting index not found exception at first time of execution.
I have a service account made in console.developers.google.com and I've added the client ID of said service into admin.google.com for my domain wide delegation under Advanced settings > Authentication > Manage OAuth client access.
Using the Google Nodejs api client and Google Nodejs auth library, I have then created a jwt client using:
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
[
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.appdata',
'https://www.googleapis.com/auth/drive.scripts',
'https://www.googleapis.com/auth/drive.metadata'
],
'user#domain.com'
);
and with
const google = require('googleapis');
const sheets = google.sheets('v4');
const drive = google.drive('v3');
I've run
async.waterfall(
[
(callback) => {
sheets.spreadsheets.create(
{
auth: jwtClient,
resource: {
properties: {
title: 'Testing'
}
}
},
(err, spreadsheet) => {
console.log(spreadsheet);
callback(err, spreadsheet.spreadsheetId)
}
)
},
(spreadsheetId, callback) => {
drive.files.update(
{
auth: jwtClient,
fileId: spreadsheetId,
resource: {
addParents: config.folder
}
},
(err, file) => {
console.log(file);
callback(err, file);
}
)
}
],
(err, results) => {
if (err) {
console.log(err);
res.status(400).send({ error: err.toString() });
} else {
res.status(200).send("It lives!");
}
}
);
My response from the second call for file.update returns 200 and a response of the file:
{ kind: 'drive#file',
id: '<id-here>',
name: 'Testing',
mimeType: 'application/vnd.google-apps.spreadsheet' }
But strangely... the addParents are not reflected in the details of the file on the Drive webapp.
Any ideas. I'm in contact with Google apis support and haven't gotten anywhere in about a week. Many thanks in advance for your help!
The problem is that addParents is a query parameter, not a field in the Files resource. As such, it should be specified as a peer of fileId:
drive.files.update(
{
auth: jwtClient,
fileId: spreadsheetId,
addParents: config.folder
},
...