Updated: Solved by Sajeetharan's suggestion! Thanks.
I'm trying to implement the api to partially update cosmos db. I got 404 not found when I tested this patch request. I tested query in cosmo's db, it's working as expected. I don't know which part is wrong.
You should invoke the Patch on the container as how you have done fetchAll request.
Here is a sample,
const multipleOperations: PatchOperation[] = [
{
op: "add",
path: "/aka",
value: "MeFamily"
},
{
op: "replace",
path: "/lastName",
value: "Jose"
},
{
op: "remove",
path: "/parents"
},
{
op: "set",
path: "/address/zip",
value: 90211
},
{
op: "incr",
path: "/address/zip",
value: 5
}
];
const { resource: patchSource2 } = await container.item(patchId!).patch(multipleOperations);
Related
I wanted to ask how to create channels in discord.js 14 (i tried to researched but found nothing) I want to make a simple text channel! :)) Also, with the stuff i found, it worked ( no errors) it just didnt create anything / post errors in debug log
It's literally under Discord.js documentation. Please, next time before asking a question read the docs.
https://discord.js.org/#/docs/discord.js/main/general/welcome
guild.channels.create({
name: "hello",
type: ChannelType.GuildText,
parent: cat[0].ID,
// your permission overwrites or other options here
});
//If the command is slash type
const { Permissions } = require("discord.js")
interaction.guild.channels.create({
name: "new-channel",
type: 'GUILD_TEXT',
permissionOverwrites: [
{
id: interaction.guild.id,
accept: [Permissions.FLAGS.VIEW_CHANNEL],
},
],
});
//If the command is message type
const { Permissions } = require("discord.js")
message.guild.channels.create({
name: "new-channel",
type: 'GUILD_TEXT',
permissionOverwrites: [
{
id: message.guild.id,
accept: [Permissions.FLAGS.VIEW_CHANNEL],
},
],
});
I am implementing Klarna Checkout in my webapp. Backend using aws serverless. Frontend: react.
I am stucked at creating a order. It works fine inside postman but I can't get basic auth working axios.
For testing purposes I am posting orders from my react app. It will be moved to the backend once I get it working.
My axios code looks like this.
axios
.post(
"https://api.playground.klarna.com/checkout/v3/orders",
{
purchase_country: "DE",
purchase_currency: "EUR",
locale: "de-DE",
order_amount: 3,
order_tax_amount: 0,
order_lines: [
{
type: "digital",
reference: "Test",
name: "Test Subscription",
quantity: 1,
quantity_unit: "pcs",
unit_price: 3,
tax_rate: 0,
total_amount: 3,
total_discount_amount: 0,
total_tax_amount: 0
}
],
merchant_urls: {
terms: "https://www.example.com/terms.html",
checkout: "https://www.example.com/checkout.html",
confirmation: "https://www.example.com/confirmation.html",
push: "https://www.example.com/api/push"
}
},
{
auth: {
username: "xxx",
password: "xxx"
},
headers: {
"Content-Type": "application/json"
}
}
)
.then(result => console.dir(result));
I get a 401 error at OPTIONS.
The response I'm getting.
I have tried it with postman, which works fine.
To summarize the comments: Klarna's API cannot be called from browser only from serverside.
I called the same code from my aws lambda and it worked fine.
I have a problem concerning a Telegram bot I am currently working on. I get messages from users in the following format:
update { update_id: 82618016,
message:
{ message_id: 363,
from: { id: 22303518, first_name: 'Steve', language_code: 'de-DE' },
chat: { id: 22303518, first_name: 'Steve', type: 'private' },
date: 1501501753,
text: 'j' } }
When I want to access the id of the chat I can do this without any problems by using
$.message.chat.id
As soon as a want to get the message_id or first_name I only get "undefined".
$.message.chat.first_name
$.message.message_id
Can anyone help me here? As far as I see it I understood the structure of the message correctly so I don't really know what's the problem here.
Thank you very much in advance
EDIT: I am adding a bit more of my code here:
The main code for the bot (including the webhook) is this:
initializeBot();
function initializeBot(){
const Telegram = require('telegram-node-bot');
const PingController = require('./controllers/ping');
const OtherwiseController = require('./controllers/otherwise');
const tg = new Telegram.Telegram('MY_TOKEN_IS_HERE', {
webhook: {
url: 'https://xxx.herokuapp.com',
port: process.env.PORT || 443,
host: '0.0.0.0'
}
})
tg.router.when(new Telegram.TextCommand('/ping', 'pingCommand'), new PingController())
.otherwise (new OtherwiseController());
}
When the OtherwiseController gets called the following code is called (I reduced it to the essentials to clarify the problem.
class OtherwiseController extends Telegram.TelegramBaseController {
handle($){
console.log($.message.chat.first_name);
console.log($.message.text);
console.log($.message.chat.id);
console.log($.message.message_id);
}
}
The console output for this message
update { update_id: 82618020,
message:
{ message_id: 371,
from: { id: 22303518, first_name: 'Steve', language_code: 'de-DE' },
chat: { id: 22303518, first_name: 'Steve', type: 'private' },
date: 1501509762,
text: 'hello' } }
would be:
undefined
hello
22303518
undefined
Use the below method to extract the keys of your json object, then you can access with an appropriate key:
Object.keys($.message.chat);
I am new to nodejs i just want to bring data from event.js to app.js its in same directory but i could not get it working any idea how to make it work ?
app.js
var SnmpData = require('./event.js');
console.log('SNMP data',SnmpData);
event.js
var message = {
event: {
header: {
eventSource: "d-sms"
},
body: {
data: [
{
oid: "1.3.6.1.4.140.625",
host: "135.89.157.201",
port: "162",
value: "Problem with monitoring device",
type: ""
},
{
oid: "1.3.6.1.4.345.765",
host: "135.89.157.299",
port: "162",
value: "Problem with monitoring device-2",
type: ""
}],
message: "Activate Collaborate"
}
}
}
}
just add in the end of events.js this :
exports.message = message ;
Also take a look to node modules to understand how things work.
I am trying to execute a search query with search_type of count with the elasticsearch.angular.js build from the npm module.
I can execute the query like this:
POST /index1/type1/_search?search_type=count
{
"aggs": {
"reviews": {
"nested": {
"path": "reviews"
}
}
}
}
but when I try to translate the query to the .js api, I get an error. My code looks like this:
var requestObject = {
index:'index1',
type:'type1',
searchType: 'count',
body: {
query:{
aggs: {
reviews: {
nested: {
path: "reviews"
}
}
}
}
};
esClient.search(requestObject)
The trace looks like this:
console.js:1 DEBUG: 2015-08-04T15:28:59Z
starting request { method: 'POST',
path: '/index1/type1/_search',
body: { aggs: { reviews: [Object] } },
query: { search_type: 'count' } }
That looks OK to an elasticsearch newbie, but the request completes with an error: ReferenceError: count is not defined.
What am I missing here please?
It turned out that my problem was a stupid error on my part (thanks #robertklep for pointing it out). The code above actually works correctly. As I was not able to find an example of using using searchType from the api, I am leaving this here in the hope it will be useful to somebody else.