Product advertising API not working - node.js

I just joined as associate program in amazon product advertising api. I am able to run query in scratchpad but while in Coding it is giving error. Please give me any suggestion where I am getting wrong. I am using Node.JS for this.
const OperationHelper = require('apac').OperationHelper;
const opHelper = new OperationHelper({
awsId: '',
awsSecret: '',
assocId: 'tarun123-21'
});
opHelper.execute('ItemSearch', {
'SearchIndex': 'Books',
'Keywords': 'harry potter',
'ResponseGroup': 'ItemAttributes,Offers',
'Service' : 'AWSECommerceService'
}).then((response) => {
console.log("Results object: ", response.result);
console.log("Raw response body: ", response.responseBody);
}).catch((err) => {
console.error("Something went wrong! ", err);
});
It is giving the following error :
Results object: { ItemSearchErrorResponse:
{ '$': { xmlns: 'http://ecs.amazonaws.com/doc/2013-08-01/' },
Error:
{ Code: 'AWS.InvalidAssociate',
Message: 'Your AKIAI7SZEKEZNMFWGJDQ is not registered as an Amazon Assoc
iate. Please register as an associate at https://affiliate-program.amazon.com/gp
/associates/join/landing/main.html.' },
RequestId: 'e860887e-4bf7-4076-bfa9-6d2212324ba4' } }
Raw response body: <?xml version="1.0"?>
<ItemSearchErrorResponse xmlns="http://ecs.amazonaws.com/doc/2013-08-01/"><Error
><Code>AWS.InvalidAssociate</Code><Message>Your AKIAI7SZEKEZNMFWGJDQ is not regi
stered as an Amazon Associate. Please register as an associate at https://affili
ate-program.amazon.com/gp/associates/join/landing/main.html.</Message></Error><R
equestId>e860887e-4bf7-4076-bfa9-6d2212324ba4</RequestId></ItemSearchErrorRespon
se>

As the error suggest you will need Amazon Associate account to access the API. The credentials that you are using seems invalid. You can test your credentials here Amazon Scratch pad

Related

How to get INTERESTS in the "facebook-nodejs-business-sdk"

I am developing an application to consume the facebook api using the package "facebook-nodejs-business-sdk" in version v9.0.
I'm looking for a method to get interests, but I can't find it.
I looked in the examples available in the package, but I can't find anything that allows me to search the search node.
Using the graph api explorer I can see that the code to make these calls with javascript is as follows:
FB.api( '/search','GET', {"type":"adinterest","q":"Golf","limit":"10000","locale":"pt_BR"}, function(response) { // Insert your code here } );
But the application is using the mentioned package and generally has specific methods for calls.
I'm a beginner in programming so I'm lost.
Can someone help me?
Thanks!
I didn't find any reference to this in the SDK but seems you could call the targeting search api by yourself with the following example:
const bizSdk = require('facebook-nodejs-business-sdk');
const access_token = '<the_token>';
const api = bizSdk.FacebookAdsApi.init(access_token);
const showDebugingInfo = true; // Setting this to true shows more debugging info.
if (showDebugingInfo) {
api.setDebug(true);
}
const params = {
'type' : 'adinterest',
'q' : 'Golf',
'limit' : '10000',
'locale' : 'pt_BR',
};
api.call('GET',['search'], params).then((response) => {
console.log(response)
}).catch(error => {
console.log("something bad happened somewhere", error);
});
This code will output something like:
{
data: [
{
id: '6003631859287',
name: 'Golf',
audience_size: 218921,
path: [Array],
description: null,
disambiguation_category: 'Negócio local',
topic: 'News and entertainment'
},
{
id: '6003510075864',
name: 'Golfe',
audience_size: 310545288,
path: [Array],
description: '',
topic: 'Sports and outdoors'
....
Hope this help

AWS SES Error: Email address is not verified

I am trying to send email using aws-sdk ses in nodejs.
While executing the code the response I am getting is:
message:
'Email address is not verified. The following identities failed the check in region US-EAST-1:xxxtestemailxxx#gmail.com',
code: 'MessageRejected'
I have already verified the sender as well as receiver email(destination email in a array).
On SES settings of aws console, it is showing the email is verified. I removed the email and then once again successfully verified it.
Last time(few months back) when I used it, everything was working fine.
Below is the screenshot of my aws console related to SES:
Also when I am sending the test email using aws console, its working fine. This is only happening when I am trying to send email using aws-sdk.
Does anyone knows what is wrong, just to be clear I am also posting the code below:
const send_email = function (email, subject, source, payload) {
console.log(email, subject, source, payload);
let email_param = {
Destination: {
ToAddresses: email
},
// ConfigurationSetName: 'XXXRANDOMTEXT_PLATFORM',
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: payload
}
// Text: {
// Charset: "UTF-8",
// Data: payload
// }
},
Subject: {
Charset: "UTF-8",
Data: subject
}
},
Source: source
};
let send_email = SES.sendEmail(email_param).promise();
send_email
.then(data => {
return true;
})
.catch(error => {
console.log('sending email error:', error);
return false
});
}
If your AWS account is still in the sandbox mode then you have to verify your sender, receiver etc. Go to the prod mod to have access to the full features.

Error "permission type field is required" when attempting to create permission via Google Drive API

I adapted code from the Google Drive API Quickstart for Node.js found here to try and create a new permission on an existing file in Google Drive.
No matter what I change in the code, I always get the same response saying The permission type field is required even though I've specified it via resource as mentioned in documentation for the npm googleapis client library and other examples I've found.
Is this just not working or am I missing something obvious?
Code to update permission
function updateFilePermissions(auth) {
var drive = google.drive({
version: 'v3',
auth: auth
});
var resourceContents = {
role: 'writer',
type: 'user',
emailAddress: 'user#example.com'
};
drive.permissions.create({
resource: resourceContents,
fileId: aValidFileId,
sendNotificationEmail: false,
fields: 'id',
}, function(err, res) {
if (err) {
// Handle error...
console.error(err);
} else {
console.log('Permission ID: ', res.id);
}
});
}
Response from Google Drive API
code: 400,
errors:
[ { domain: 'global',
reason: 'required',
message: 'The permission type field is required.',
locationType: 'other',
location: 'permission.type' } ]
To anyone that's still looking at the answer, it needs to be formatted like this:
{
fileId: fieldID, // String
resource: {
role: putRoleHere, //String
type: putTypeHere //String
}
Google's APIs are using Axios for the HTTP client so it will be auto-stringified for you when using their methods :)
It seems like the sample code for this API produced by the docs is invalid. By analyzing outgoing requests in the devtools Network and a bit of guessing I found out that the resource fields must be placed in the root level alongside the fileId.
response = await gapi.client.drive.permissions.create({
fileId: "18TnwcUzeBGCHpr7UWW-tKjf2H2RKOKx2V2vaQiHR-TA",
emailMessage: "huj sosi",
sendNotificationEmail: false,
role: 'writer',
type: 'user',
emailAddress: 'user#example.com',
})
Considering that docs don't encourage using a specific version of the library, I suppose there was just a random breaking change in it at some point causing the inconsistency in the docs.

NodeJS and Marklogic 9 - how to save a json document to the database?

I'm new to NodeJS and Marklogic, I'm following a tutorial on how to save a json document to the database, but I cannot make it work, is my syntax or code correct?
const marklogic = require('marklogic');
const my = require('./my-connection.js');
const db = marklogic.createDatabaseClient(my.connInfo);
const documents = [
{ uri: '/gs/aardvark.json',
content: {
name: 'aardvark',
kind: 'mammal',
desc: 'The aardvark is a medium-sized burrowing, nocturnal mammal.'
}
},
{ uri: '/gs/bluebird.json',
content: {
name: 'bluebird',
kind: 'bird',
desc: 'The bluebird is a medium-sized, mostly insectivorous bird.'
}
}
];
db.documents.write(documents).result(
function(response) {
console.log('Loaded the following documents:');
response.documents.forEach( function(document) {
console.log(' ' + document.uri);
});
},
function(error) {
console.log('error here');
console.log(JSON.stringify(error, null, 2));
}
);
I'm getting 404 error on /gs paths, Is the folder and json file created when I execute this command or do i have to manually create it?
Thank You!
When you say you are getting a "404 error on /gs paths", I assume you're saying you cannot read back the documents you inserted. (It would be nice to see the full error).
If you're not authenticating as a user with admin privileges, you need to make sure the documents are readable. The default permissions (which is what are used here since there's no explicit perms) are rest-reader:read and rest-writer:update. You can read more about these roles here:
http://docs.marklogic.com/guide/node-dev/intro#id_70898

braintree + NodeJS gives an "authentication Error "

I'm trying to build a payment gateway library using braintree's NodeJS library, I'm making an ajax call from front end with the card data.
Client-Side
var card_data = {
type: "AmEx",
number: "3XXXXXXXXXXXXXX",
expire_month: "XX",
expire_year: "201X",
cvv2: "XXX",
name: "sandeep",
price : "200",
currency : "USD"
};
Ajax call,
$.ajax({
method: "GET",
url: "http://localhost:3000/paymentPath_braintree",
data: card_data
}).done(function(message){
console.log(message);
}).fail(function(data, message){
console.log(message);
});
Server-Side
var braintreePay = require('braintree');
app.get("/payment_braintree", function(request, response){
var data = request.query;
var gateway = braintreePay.connect({
environment: braintreePay.Environment.Sandbox,
merchantId: "MymerchentID",
publicKey: "MypublicKey",
privateKey: "MyprivateKey",
});
var saleRequest = {
amount: data.price,
creditCard: {
number: data.number,
cvv: data.cvv2,
expirationMonth: data.expire_month,
expirationYear: data.expire_year.slice(2),
cardHolder: data.name
},
options: {
submitForSettlement: true
}
};
gateway.transaction.sale(saleRequest, function(error, result){
if(error){
console.log(error.name);
throw error;
}
if(result.success){
response.send(result.transaction.id);
} else {
response.send(result.message);
}
});
});
I have cross checked everything, from keys and card data everything is in order but i am getting an error in callback after making gateway.transaction.sale(...); called Authentication Error . Which i tried to figure out for hours but could not get through.
error object is
authenticationError: Authentication Error
arguments: undefined
message: "Authentication Error"
name: "authenticationError"
stack: undefined
type: "authenticationError"
Where am i going wrong?
I have created an account sandbox.braintreegateway those key credentials are from the account that i have created, i din't create an app like how its done in paypal.
I am going through lack of understanding in Braintree integration.
Are their any proper documented resource.

Resources