I have been using NodeJS library for querying the price of the chepeast flight for a route, for next 60 days. Even after switching to production environment, the API throws 404 error (details mentioned below) for some common routes like SFO to YYC.
Do let me know how I can resolve this.
NotFoundError {
response: Response {
headers: {
date: 'Tue, 19 Oct 2021 17:09:32 GMT',
'content-type': 'application/vnd.amadeus+json',
'content-length': '263',
connection: 'close',
'ama-internal-message-version': '14.1',
'ama-request-id': '00010UI9218IBV',
'ama-gateway-request-id': 'rrt-0b7b1036c139b8050-a-eu-4707-50043169-1',
'access-control-allow-headers': 'origin, x-requested-with, accept, Content-Type, Authorization',
'access-control-max-age': '3628800',
'access-control-allow-methods': '*',
server: 'Amadeus',
'access-control-allow-origin': '*'
},
statusCode: 404,
request: Request {
host: 'api.amadeus.com',
port: 443,
ssl: true,
scheme: 'https',
verb: 'GET',
path: '/v1/shopping/flight-dates',
params: [Object],
queryPath: '/v1/shopping/flight-dates?origin=SFO&destination=YYC&departureDate=2021-10-19%2C2021-12-
18&oneWay=true&viewBy=DATE',
bearerToken: '[REDACTED]',
clientVersion: '5.7.0',
languageVersion: '14.16.1',
appId: null,
appVersion: null,
headers: [Object]
},
body: '{"errors":[{"status":404,"code":6003,"title":"ITEM/DATA NOT FOUND OR DATA NOT EXISTING","detail":"No price result found"},{"status":404,"code":6003,"title" :"ITEM/DATA NOT FOUND OR DATA NOT EXISTING","detail":"No price results found for input combined criteria"}]}',
result: { errors: [Array] },
data: undefined,
parsed: true
},
description: [
{
status: 404,
code: 6003,
title: 'ITEM/DATA NOT FOUND OR DATA NOT EXISTING',
detail: 'No price result found'
},
{
status: 404,
code: 6003,
title: 'ITEM/DATA NOT FOUND OR DATA NOT EXISTING',
detail: 'No price results found for input combined criteria'
}
],
code: 'NotFoundError'
}
My code to query the data looks something like this:
const Amadeus = require("amadeus");
var client = new Amadeus({
hostname: "production",
clientId: FLIGHT_SEARCH_API_KEY,
clientSecret: FLIGHT_SEARCH_API_SECRET,
});
const response = await client.shopping.flightDates.get({
origin,
destination,
departureDate: `${currentDate},${lastDate}`,
oneWay: true,
viewBy: "DATE",
});
The Flight Inspiration Search & Flight Cheapest Date Search APIs are built on top of a pre-computed cache. The APIs compute every day the most trending options based on past searches and bookings and fill the cache, which means that the cache is dynamic. If you need to get access to a full inventory of Amadeus you need to use the live Flight Offers Search API.
Related
A year ago we implemented ApplePay on the web in our project and everything worked just fine. But now it's unstable and payment can be successful on the third try sometimes. We are facing an ECONNRESET error while requesting POST https://apple-pay-gateway.apple.com/paymentservices/startSession and an error message “Payment not completed” on the client side
Error: read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
errno: -104,
code: 'ECONNRESET',
config: {
url: 'https://apple-pay-gateway.apple.com/paymentservices/startSession',
method: 'post',
data: '{"merchantIdentifier":"merchant.com.xxxxxxxx","displayName":"xxxxxxxxxx","initiative":"web","initiativeContext":"xxxxxxxx.xxx","domainName":"xxxxxxxx.xxx"}',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
'User-Agent': 'axios/0.19.2',
'Content-Length': 191
}
},
...
response: undefined,
isAxiosError: true,
Client side code:
applePaySession.onvalidatemerchant = async (event) => {
try {
const data = {
url: event.validationURL,
method: 'post',
body: {
merchantIdentifier,
displayName,
initiative: "web",
initiativeContext: window.location.hostname
},
json: true,
}
const merchantSession = await this.$axios.$post('/apple_pay_session', data);
if (merchantSession && merchantSession.merchantSessionIdentifier) {
applePaySession.completeMerchantValidation(merchantSession)
} else {
applePaySession.abort();
}
} catch (error) {
logReqError(error)
applePaySession.abort();
}
};
Server side:
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
keepAlive: true,
cert: fs.readFileSync(`uploads/apple_pay/${id}/certificate.pem`),
key: fs.readFileSync(`uploads/apple_pay/${id}/private.key`)
});
const sessionRes = await axios({
url: request.body.url,
method: request.body.method.toLowerCase(),
data: request.body.body,
headers: {'Content-Type': 'application/json'}, httpsAgent
})
We checked the status of Merchant Domain - it's verified, Apple Pay Payment Processing Certificate and Apple Pay Merchant Identity Certificate are valid. I also checked project code with the official documentation, as well as with other sources.
I hope anyone has had a similar problem. Any code samples or guesses will be helpful anyway
We have elastic hosted on GCP. I'm getting an error when I try to simply post a document. I'm using their node.js package, and I'm stuck with the following error:
PS C:\Projects\foo> node --experimental-modules --unhandled-rejections=strict app.js
(node:19356) ExperimentalWarning: The ESM module loader is experimental.
(node:19356) ExperimentalWarning: Conditional exports is an experimental feature. This feature could change at any time
Posting to Elastic => 5f91dfb0c64004000aab6c9b
C:\Projects\foo\node_modules\#elastic\elasticsearch\lib\Transport.js:257
const error = new ResponseError(result)
^
ResponseError: Response Error
at IncomingMessage.<anonymous> (C:\Projects\foo\node_modules\#elastic\elasticsearch\lib\Transport.js:257:25)
at IncomingMessage.emit (events.js:323:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
name: 'ResponseError',
meta: {
body: { error: 'Routing Error. The path you have requested is invalid.' },
statusCode: 404,
headers: {
'content-type': 'application/json;charset=utf-8',
server: 'Jetty(9.4.30.v20200611)',
'x-cloud-request-id': 'srCq9DMFQVWuGsdXxgWhjA',
'x-content-type-options': 'nosniff',
'x-found-handling-cluster': '[Removed]',
'x-found-handling-instance': 'instance-0000000001',
'x-frame-options': 'SAMEORIGIN',
'x-request-id': 'a2696b33-e4dc-4dfc-a8b1-f7ec17906ff7',
'x-runtime': '0.010689',
'x-xss-protection': '1; mode=block',
date: 'Mon, 09 Nov 2020 21:28:28 GMT',
'content-length': '66'
},
meta: {
context: null,
request: [Object],
name: 'elasticsearch-js',
connection: [Object],
attempts: 0,
aborted: false
}
}
}
I have the client set up as follows
const client = new Client({
node: 'https://[REMOVED].ent-search.us-central1.gcp.cloud.es.io',
auth: {
apiKey: 'Bearer private-[REMOVED]'
}
});
Then I attempt to send a json file as an array to Elastic.
client.helpers.bulk({
datasource: posts,
onDocument(doc) {
return {
create: {_index: 'my-index', _id: elasticPost.id}
};
}
});
Update:
The JSON names MUST be lowercase. For example:
Doesn't Work:
{
"Id": 123456
}
Works:
{
"id": 123456
}
Another thing may have to do with needing the cloud ID from Elastic, I'm not sure if this is required as well, but the lowercase allowed me to upload our document directly into Elastic.
I think you have one too many create in the command you return from onDocument. The command you can return is described here:
So, by removing one create layer, it should work:
client.helpers.bulk({
datasource: posts,
onDocument(doc) {
return {
create: {_index: 'my-index', _id: elasticPost.id}
};
}
});
UPDATE:
Looking at the host name *.ent-search.*, it looks like you're using the elasticsearch client to try to connect to the Enterprise search backend, that cannot work as the latter doesn't support the _bulk API.
If you connect to an AppSearch backend, you can't use the the _bulk endpoint (i.e. client.helpers.bulk()). Instead, you need to add documents through the AppSearch Documents API. Feel free to share more info on what you're trying to achieve.
The JSON names MUST be lowercase. For example:
Doesn't Work:
{
"Id": 123456,
"userName": "Dave2118"
}
Works:
{
"id": 123456,
"username": "Dave2118"
}
I've been trying to connect to Admob API from an AWS Lambda to extract some values from reports automatically from time to time. I've successfully got google-auth-library-nodejs to a layer and I am trying to use it to connect to Admob API.
I've made sure to give my Service account an Owner role and I've added the necessary GOOGLE_APPLICATION_CREDENTIALS path to the environement variables.
This is the code that I've added to my Lambda:
const {GoogleAuth} = require('google-auth-library');
exports.handler = (event, context, callback) => {
async function main() {
const auth = new GoogleAuth({
scopes: ['https://www.googleapis.com/auth/admob.report'],
});
const client = await auth.getClient();
//console.log("client", JSON.stringify(client));
const url = `https://admob.googleapis.com/v1/accounts`;
const res = await client.request({ url });
console.log("res: ", JSON.stringify(res.data));
}
main().catch(console.error);
};
When I run the code, I get the following error:
ERROR GaxiosError: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
at Gaxios._request (/opt/nodejs/node_modules/gaxios/build/src/gaxios.js:85:23)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async JWT.requestAsync (/opt/nodejs/node_modules/google-auth-library/build/src/auth/oauth2client.js:350:18)
at async main (/var/task/index.js:97:19) {
response: {
config: {
url: 'https://admob.googleapis.com/v1/accounts',
headers: [Object],
params: [Object: null prototype] {},
paramsSerializer: [Function: paramsSerializer],
validateStatus: [Function: validateStatus],
responseType: 'json',
method: 'GET'
},
data: { error: [Object] },
headers: {
'alt-svc': 'quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000',
'cache-control': 'private',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Wed, 26 Feb 2020 18:41:51 GMT',
server: 'ESF',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin, Referer',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '0'
},
status: 401,
statusText: 'Unauthorized',
request: { responseURL: 'https://admob.googleapis.com/v1/accounts' }
},
config: {
url: 'https://admob.googleapis.com/v1/accounts',
headers: {
Authorization: 'Bearer [Removed]',
'User-Agent': 'google-api-nodejs-client/5.10.1',
'x-goog-api-client': 'gl-node/12.14.1 auth/5.10.1',
Accept: 'application/json'
},
params: [Object: null prototype] {},
paramsSerializer: [Function: paramsSerializer],
validateStatus: [Function: validateStatus],
responseType: 'json',
method: 'GET'
},
code: 401,
errors: [
{
message: 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.',
domain: 'global',
reason: 'unauthorized'
}
]
}
I've been trying to find my mistake by searching on google, stack overflow, reading tutorials about connecting to Admob API as well as reading the library's code. I would really appreciate if someone could point me towards a solution.
The problem is you are trying to use a service account where OAuth User Credentials are required. You will need to implement the OAuth 2 Flow where the user enters their Google username and password.
AdMob: Authorization for the request
Refer to the following Google example on how to create a node.js OAuth 2 client.
https://github.com/googleapis/google-auth-library-nodejs#oauth2
I have a Watson Tone cloud service up and running and I am trying to link it to my index.js file. However it doesn't seem to want to connect.
Code below:
const ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
const toneAnalyzer = new ToneAnalyzerV3({
version: '2017-09-21',
iam_apikey: 'omoNirDx1MUQwCdlHTQ-5Fxklx2_c0dUVAyMFIItFLty',
url: 'http://watson-row-analyser.eu-gb.cf.appdomain.cloud/#'
});
const text =
'Team, I know that times are tough! Product ' +
'sales have been disappointing for the past three ' +
'quarters. We have a competitive product, but we ' +
'need to do a better job of selling it!';
const toneParams = {
tone_input: { text: text },
content_type: 'application/json'
};
toneAnalyzer
.tone(toneParams)
.then((toneAnalysis) => {
console.log(JSON.stringify(toneAnalysis, null, 2));
})
.catch((err) => {
console.log('error:', err);
});
Current error code:
Marcs-MacBook-Pro:npm-global marcwatts$ node index1.js
error: { Not Found: Not Found
at formatError (/Users/marcwatts/Desktop/mxw817/DBTestApp/npm-global/node_modules/watson-developer-cloud/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:111:17)
at /Users/marcwatts/Desktop/mxw817/DBTestApp/npm-global/node_modules/watson-developer-cloud/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:259:19
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Not Found',
code: 404,
message: 'Not Found',
body:
'"<!DOCTYPE html>\\n<html lang=\\"en\\">\\n<head>\\n<meta charset=\\"utf-8\\">\\n<title>Error</title>\\n</head>\\n<body>\\n<pre>Cannot POST /</pre>\\n</body>\\n</html>\\n"',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
connection: 'close',
'transfer-encoding': 'chunked',
'content-security-policy': 'default-src \'none\'',
'content-type': 'text/html; charset=utf-8',
date: 'Sat, 06 Jul 2019 15:32:34 GMT',
'x-content-type-options': 'nosniff',
'x-powered-by': 'Express',
'x-global-transaction-id': 'ba9308f85d20bf12a70673ff' } }
Link to api for Watson:
https://cloud.ibm.com/apidocs/tone-analyzer?code=node
Code 404 means Not Found. A requested item or parameter does not exist. What am I missing?
I'm trying to access my assistant but I'm getting a 404 Not Found error when inserting the iam_api_key and the url provided in the dahsboard.
And I can't find the password in the dahsboard.
I'm working with Node.js. I've tried to create other service credentials but nothing worked
{
username: '{api-key}',
password: '{password}', // I can't find this
// OR even
iam_apikey: '{api-key}'
url: '{url}',
version: '{version}',
disable_ssl_verification: true,
}
{ Not Found: Resource not found
{ ... }
at
at process._tickCallback (internal/process/next_tick.js:188:7) name: 'Not Found', code: 404, message: 'Resource not found',
body: '{"error":"Resource not found","code":404}', headers: {
'x-backside-transport': 'FAIL FAIL',
'content-type': 'application/json; charset=utf-8',
'access-control-allow-origin': '*',
'access-control-allow-methods': 'GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS',
'access-control-allow-headers': 'Content-Type, Content-Length, Authorization, X-Watson-Authorization-Token, X-WDC-PL-OPT-OUT,
X-Watson-UserInfo, X-Watson-Learning-Opt-Out, X-Watson-Metadata',
'access-control-max-age': '3600',
'content-security-policy': 'default-src \'none\'',
'x-dns-prefetch-control': 'off',
'x-frame-options': 'SAMEORIGIN',
'strict-transport-security': 'max-age=31536000;',
'x-download-options': 'noopen',
'x-content-type-options': 'nosniff',
'x-xss-protection': '1; mode=block',
'x-global-transaction-id': '{x-global-transaction-id}',
'x-dp-watson-tran-id': '{x-dp-watson-tran-id}',
'x-dp-transit-id': '{x-dp-transit-id}',
'content-length': '41',
'x-edgeconnect-midmile-rtt': '124',
'x-edgeconnect-origin-mex-latency': '142',
date: 'Wed, 19 Jun 2019 20:38:08 GMT',
connection: 'close' } }
You have to use either the api key OR the username / password combination. The API docs for IBM Watson Assistant have code samples for Node.js:
const AssistantV2 = require('ibm-watson/assistant/v2');
const assistant = new AssistantV2({
version: '{version}',
iam_apikey: '{apikey}',
url: '{url}'
});
Use this code as well. It's working on me. I added serviceUrl and headers. Make sure to add the correct service URL according to the assistant URL.
const assistant = new AssistantV2({
version: "2019-02-28",
authenticator: authenticator,
url: process.env.WATSON_ASSISTANT_URL,
serviceUrl: "https://api.us-south.assistant.watson.cloud.ibm.com",
headers: {
"X-Watson-Learning-Opt-Out": "true",
},
});
Refer more - https://cloud.ibm.com/apidocs/assistant-v2?code=node#endpoint-cloud