Shopify GraphQl Mutation getting an error when sending DraftOrderSendInvoice - javascript

I am creating a Draft Order and everything is working fine, But I am getting a GID which is not working when I am trying to send DraftOrderInvoice. I am not sure if the if my format is wrong or maybe I missed something, but any help in directions is much appreciated.
Let me know if any additional information is needed to clarify the current question.
mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
}
userErrors {
field
message
}
}
}
After the Draft order is created. I recieve a response with the GID "gid://shopify/DraftOrder/xxxxxxxxxxxxx"
I am then using the Draft Order Id to send an invoice, but I am having some formatting issues I think.
I plugged the Gid into the "Shopify GraphiQL App" to test for mutations and I get an error with the draft order Id.
mutation draftOrderInvoiceSend($id: ID!) {
draftOrderInvoiceSend(id: $id) {
draftOrder {
id
}
userErrors {
field
message
}
}
}
Variable
{
"id": "gid://shopify/DraftOrder/xxxxxxxxxx"
}
​
Error
{
"errors": [
{
"message": "Internal error. Looks like something went wrong on our end.\nRequest ID: ff0c8cfd-ce93-446f-9f12-b09580f945b7 (include this in support requests)."
}
]
}
According to Shopify Mutations the ID should look similar to the obj below
https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/draftorderinvoicesend
{
"id": "Z2lkOi8vU2hvcGlmeS9FeGFtcGxlLzE="
}

Related

Firestore document update using REST api

I'm trying to increment one value in firebase store using rest api following this guide https://firebase.google.com/docs/firestore/reference/rest/v1beta1/projects.databases.documents/commit
I'm trying to make the request using the form given at this documentation.
Here's my path to the document
/hindiscript-likes/kof97lbQ1IuuvgCHBfOh
where hindiscript-likes is the collection name.
The document looks like below
Here's my request body
{
"writes": [
{
"transform": {
"document": "projects/public-api-07/databases/(default)/documents/kof97lbQ1IuuvgCHBfOh",
"fieldTransforms": [
{
"increment": {
"integerValue": 1
}
}
]
}
}
]
}
But upon executing this, it is returnng 400 with the following error
{
"error": {
"code": 400,
"message": "Document name \"projects/public-api-07/databases/(default)/documents/kof97lbQ1IuuvgCHBfOh\" lacks \"/\" at index 73.",
"status": "INVALID_ARGUMENT"
}
}
Can somebody help ?
You're missing the name of the collection in the path of the document to update. What you have now is asking for just "kof97lbQ1IuuvgCHBfOh", which it assumes is the name of a collection but a missing document ID. But what you want instead is "hindiscript-likes/kof97lbQ1IuuvgCHBfOh".
Try:
"document": "projects/public-api-07/databases/(default)/documents/hindiscript-likes/kof97lbQ1IuuvgCHBfOh",

Can't createChatThread() with Preview 4 azure-sdk-for-js

The example code snippet # https://github.com/Azure/azure-sdk-for-js/tree/%40azure/communication-identity_1.0.0-beta.4/sdk/communication/communication-chat does NOT compile.
import { ChatClient, ChatThreadClient } from '#azure/communication-chat';
import { AzureCommunicationTokenCredential } from '#azure/communication-common';
let createChatThreadRequest =
{
topic: 'Preparation for London conference',
participants:
[
{
user: { communicationUserId: '<USER_ID_FOR_JACK>' },
displayName: 'Jack'
},
{
user: { communicationUserId: '<USER_ID_FOR_GEETA>' },
displayName: 'Geeta'
}
]
};
let createChatThreadResponse = await chatClient.createChatThread(createChatThreadRequest);
let threadId = createChatThreadResponse.chatThread.id;
my package.json:
"#azure/communication-identity": "1.0.0-beta.4",
"#azure/communication-calling": "1.0.0-beta.6",
"#azure/communication-chat": "1.0.0-beta.4",
"#azure/communication-common": "1.0.0-beta.5",
"#azure/communication-signaling": "1.0.0-beta.2",
Latest attempt:
createChatThreadRequest:
{
"topic": "Ghost Frog",
"participants": [
{
"user": {
"communicationUserId": "ey...Ug"
},
"displayName": "frog"
}
]
}
POST error 400
https://########.communication.azure.com/chat/threads?api-version=2020-11-01-preview3
RestError: {"error":{"code":"BadRequest","message":"One or more validation errors occurred.","details":[{"message":"The value provided for Id is invalid.","target":"Participants[0].Id"}]}}
The error message is looking for a property named 'Id'. The spec does NOT require an Id. Arg.
sorry you are running into issues and thank you for reaching out!
Someone on our team has tested out your code snippet and SDK versions and it compiled. Can you specify the error codes you are seeing? It will help us understand the issue better. Thanks!
given you are using version 1.0.0-beta.4 I can verify the code snippet you have is correct.
In the latest release of the JS SDK 1.0.0-beta.5 the user property was in fact renamed to id, however previous versions should still work as expected.
Can you verify if the latest version works for you? The error you are seeing can also occur if an invalid communicationUserId is provided.
Given your current version and code, if the issue is persisting we would like to investigate.
We try to keep these docs up to date during public preview but if you run into issues please let us know:
https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/communication/communication-chat
https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/chat/get-started?pivots=programming-language-javascript

Dialogflow Fulfilment webhook call failed

I am new to dialogflow fulfillment and I am trying to retrieve news from news API based on user questions. I followed documentation provided by news API, but I am not able to catch any responses from the search results, when I run the function in console it is not errors. I changed the code and it looks like now it is reaching to the newsapi endpoint but it is not fetching any results. I am utilizing https://newsapi.org/docs/client-libraries/node-js to make a request to search everything about the topic. when I diagnoise the function it says " Webhook call failed. Error: UNAVAILABLE. "
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const http = require('http');
const host = 'newsapi.org';
const NewsAPI = require('newsapi');
const newsapi = new NewsAPI('63756dc5caca424fb3d0343406295021');
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) =>
{
// Get the city
let search = req.body.queryResult.parameters['search'];// search is a required param
// Call the weather API
callNewsApi(search).then((response) => {
res.json({ 'fulfillmentText': response }); // Return the results of the news API to Dialogflow
}).catch((xx) => {
console.error(xx);
res.json({ 'fulfillmentText': `I don't know the news but I hope it's good!` });
});
});
function callNewsApi(search)
{
console.log(search);
newsapi.v2.everything
(
{
q: 'search',
langauge: 'en',
sortBy: 'relevancy',
source: 'cbc-news',
domains: 'cbc.ca',
from: '2019-12-31',
to: '2020-12-12',
page: 2
}
).then (response => {console.log(response);
{
let articles = response['data']['articles'][0];
// Create response
let responce = `Current news in the $search with following title is ${articles['titile']} which says that
${articles['description']}`;
// Resolve the promise with the output text
console.log(output);
}
});
}
Also here is RAW API response
{
"responseId": "a871b8d2-16f2-4873-a5d1-b907a07adb9a-b4ef8d5f",
"queryResult": {
"queryText": "what is the latest news about toronto",
"parameters": {
"search": [
"toronto"
]
},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"intent": {
"name": "projects/misty-ktsarh/agent/intents/b52c5774-e5b7-494a-8f4c-f783ebae558b",
"displayName": "misty.news"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 543
},
"languageCode": "en"
},
"webhookStatus": {
"code": 14,
"message": "Webhook call failed. Error: UNAVAILABLE."
},
"outputAudio": "UklGRlQqAABXQVZFZm10IBAAAAABAAEAwF0AAIC7AAACABAAZGF0YTAqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... (The content is truncated. Click `COPY` for the original JSON.)",
"outputAudioConfig": {
"audioEncoding": "OUTPUT_AUDIO_ENCODING_LINEAR_16",
"synthesizeSpeechConfig": {
"speakingRate": 1,
"voice": {}
}
}
}
And Here is fulfillment request:
{
"responseId": "a871b8d2-16f2-4873-a5d1-b907a07adb9a-b4ef8d5f",
"queryResult": {
"queryText": "what is the latest news about toronto",
"parameters": {
"search": [
"toronto"
]
},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"intent": {
"name": "projects/misty-ktsarh/agent/intents/b52c5774-e5b7-494a-8f4c-f783ebae558b",
"displayName": "misty.news"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 543
},
"languageCode": "en"
},
"webhookStatus": {
"code": 14,
"message": "Webhook call failed. Error: UNAVAILABLE."
},
"outputAudio": "UklGRlQqAABXQVZFZm10IBAAAAABAAEAwF0AAIC7AAACABAAZGF0YTAqAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... (The content is truncated. Click `COPY` for the original JSON.)",
"outputAudioConfig": {
"audioEncoding": "OUTPUT_AUDIO_ENCODING_LINEAR_16",
"synthesizeSpeechConfig": {
"speakingRate": 1,
"voice": {}
}
}
}
Also here is the screenshot from the firebase console.
Can anyone guide me what is that I am missing in here?
The key is the first three lines in the error message:
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'newsapi'
It is saying that the newsapi module couldn't be loaded and that the most likely cause of this is that you didn't list this as a dependency in your package.json file.
If you are using the Dialogflow Inline Editor, you need to select the package.json tab and add a line in the dependencies section.
Update
It isn't clear exactly when/where you're getting the "UNAVAILABLE" error, but one likely cause if you're using Dialogflow's Inline Editor is that it is using the Firebase "Spark" pricing plan, which has limitations on network calls outside Google's network.
You can upgrade to the Blaze plan, which does require a credit card on file, but does include the Spark plan's free tier, so you shouldn't incur any costs during light usage. This will allow for network calls.
Update based on TypeError: Cannot read property '0' of undefined
This indicates that either a property (or possibly an index of a property) is trying to reference against something that is undefined.
It isn't clear which line, exactly, this may be, but these lines all are suspicious:
let response = JSON.parse(body);
let source = response['data']['source'][0];
let id = response['data']['id'][0];
let name = response['data']['name'][0];
let author = response['author'][0];
let title = response['title'][0];
let description = response['description'][0];
since they are all referencing a property. I would check to see exactly what comes back and gets stored in response. For example, could it be that there is no "data" or "author" field in what is sent back?
Looking at https://newsapi.org/docs/endpoints/everything, it looks like none of these are fields, but that there is an articles property sent back which contains an array of articles. You may wish to index off that and get the attributes you want.
Update
It looks like that, although you are loading the parameter into a variable with this line
// Get the city and date from the request
let search = req.body.queryResult.parameters['search'];// city is a required param
You don't actually use the search variable anywhere. Instead, you seem to be passing a literal string "search" to your function with this line
callNewsApi('search').then((output) => {
which does a search for the word "search", I guess.
You indicated that "it goes to the catch portion", which indicates that something went wrong in the call. You don't show any logging in the catch portion, and it may be useful to log the exception that is thrown, so you know why it is going to the catch portion. Something like
}).catch((xx) => {
console.error(xx);
res.json({ 'fulfillmentText': `I don't know the news but I hope it's good!` });
});
is normal, but since it looks like you're logging it in the .on('error') portion, showing that error might be useful.
The name of the intent and the variable I was using to make the call had a difference in Casing, I guess calls are case sensitive just be aware of that

What is wrong with my JSON output for a Slack Message payload?

I have set up what I think should be a working JSON output to send a message in slack but Slack keeps rejecting it.
I have tried multiple different message layout formats using the guides on slack's api site, but so far the only method that has successfully sent is a fully flat JSON with no block formatting.
function submitValuesToSlack(e) {
var name = e.values[1];
var caseNumber = e.values[2];
var problemDescription = e.values[3];
var question = e.values[4];
var completedChecklist = e.values[5];
var payload = [{
"channel": postChannel,
"username": postUser,
"icon_emoji": postIcon,
"link_names": 1,
"blocks": [
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Name:*\n " + name
}
]
}]
}];
console.log(JSON.stringify(payload, null, "\t"));
var options = {
'method': 'post',
'payload': JSON.stringify(payload)
};
console.log(options)
var response = UrlFetchApp.fetch(slackIncomingWebhookUrl, options);
}
When I run this, I get the following output:
[
{
"channel":"#tech-support",
"username":"Form Response",
"icon_emoji":":mailbox_with_mail:",
"link_names":1,
"blocks":[
{
"type":"section",
"fields":[
{
"type":"mrkdwn",
"text":"*Name:*\n test"
}
]
}
]
}
]
Which I believe is correct, however slack api just rejects it with an HTTP 400 error "no text"
am I misunderstanding something about block formatting?
EDIT:
To Clarify, formatting works if I use this for my JSON instead of the more complex format:
{
"channel":"#tech-support",
"username":"Form Response",
"icon_emoji":":mailbox_with_mail:",
"link_names":1,
"text":"*Name:*\n test"
}
The reason you are getting the error no_text is because you do not have a valid message text property in your payload. You either need to have a text property as top line parameter (classic style - your example at the bottom) or a text block within a section block.
If you want to put to use blocks only (as you are asking) the section block is called text, not fields. fields is another type of section bock that has a different meaning.
So the correct syntax is:
[
{
"channel":"#tech-support",
"username":"Form Response",
"icon_emoji":":mailbox_with_mail:",
"link_names":1,
"blocks":[
{
"type":"section",
"text":[
{
"type":"mrkdwn",
"text":"*Name:*\n test"
}
]
}
]
}
]
Also see here for the official documentation on it.
Blocks are very powerful, but can be complicated at times. I would recommend to use the message builder to try out your messages and check out the examples in the docu.

Firebase multi location update, delete redundant data as part of update

I'm using firebase multi location updates to update a number of locations in my database.
One of the update paths contains a value that could be changed as part of the update therefore creating a new record at the new path location which is correct. This then leaves a redundant data at the original location that I need to delete as part of the update. Can someone give me a pointer on how to delete the redundant data as part of the update?
I am using the code below to create my update: -
var updatedUserDataContent = {
title: $scope.postToUpdate.title
commenter: $scope.postToUpdate.commenter
};
updatedUserData["Posts/" + $scope.postToUpdate.$id] = updatedUserDataContent;
updatedUserData["UserPosts/" + $scope.postToUpdate.commenter + "/" + $scope.postToUpdate.$id] = updatedUserDataContent;
The commenter could be changed by a user on the record before saving leaving the redundant data in the original commenter node. I have tried using the security rules but these stop data being created rather than deleted.
Edit 1
JSON as requested.
Before the update I have
{
"Not assigned" : {
"-KNfs3OhBmbb93w9VEW-" : {
"title": "vytg",
"commenter": "Not assigned"
}
}
}
After the update (after changing commenter from "Not assigned" to "User A") I have
{
"Not assigned": {
"-KNfs3OhBmbb93w9VEW-": {
"title": "vytg",
"commenter": "Not assigned"
}
},
"User A" : {
"-KNfs3OhBmbb93w9VEW-" : {
"title": "vytg",
"commenter": "User A"
}
}
}
but I want just
{
"User A" : {
"-KNfs3OhBmbb93w9VEW-" : {
"title": "vytg",
"commenter": "User A"
}
}
}
You're trying to move/rename a node, which is not an operation the database supports.
Since the new data is written correctly, all that is needed is that you also clear out the old node. Putting null in for that location will take care of that:
updatedUserData["Not assigned"] = null;

Categories

Resources