I get "invalid id" when using the new fileDelete to remove a file from the admin page - shopify

I've been able to make a script to save a file using the new fileCreate but when I try to delete a file with fileDelete, I can't seems to get the right ID.
mutation fileDelete($fileIds: [ID!]!) {
fileDelete(fileIds: $fileIds) {
userErrors {
field
message
}
deletedFileIds
}
}
I pass the ID from my last image: "gid://shopify/ImageSource/20805776113730", called with a new private app key (which should use the v2021-10)
If anybody got that mutation to work, I would appreciate any help.
Response from Shopify:
{
"data": {
"fileDelete": null
},
"errors": [{
"message": "invalid id",
"locations": [{
"line": 3,
"column": 4
}],
"path": ["fileDelete"]
}],
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 1,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 999,
"restoreRate": 50
}
}
}
}
Here is what's send:
{
"query": "mutation fileDelete($fileIds: [ID!]!) {\r\n\t\t\tfileDelete(fileIds: $fileIds) {\r\n\t\t\t userErrors {\r\n\t\t\t\tfield\r\n\t\t\t\tmessage\r\n\t\t\t }\r\n\t\t\t deletedFileIds\r\n\t\t\t}\r\n\t\t }",
"variables": {
"fileIds": "gid:\/\/shopify\/ImageSource\/20825330909250"
}
}

You need to send the ImageMedia ID:
{
"fileIds": "gid://shopify/MediaImage/20835931816073"
}
To get that ID, you need to send your request like this:
{
files(first: 99, reverse:true){
edges{
cursor
node{
... on MediaImage {
id
mimeType
image {
originalSrc
}
}
__typename
createdAt
fileStatus
preview{
image{
altText
id
transformedSrc
originalSrc
}
status
}
}
}
}
}
Response:
{
"data": {
"files": {
"edges": [
{
"cursor": "xxxxxx",
"node": {
"id": "gid:\/\/shopify\/MediaImage\/xxxx",
"mimeType": "image\/png",
"image": {
"originalSrc": "xxxx"
},
"__typename": "MediaImage",
"createdAt": "2021-10-21T17:39:58Z",
"fileStatus": "READY",
"preview": {
"image": {
"altText": "xxxx",
"id": "gid:\/\/shopify\/ImageSource\/xxxx",
"transformedSrc": "xxxx",
"originalSrc": "xxxx"
},
"status": "READY"
}
}
},
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 398,
"actualQueryCost": 18,
"throttleStatus": {
"maximumAvailable": 1000.0,
"currentlyAvailable": 982,
"restoreRate": 50.0
}
}
}
}

Related

Google-Chat-API: Open dialog from posted message

I use bot to post cards with version 2 (сards_v2 property).
Cards are rendered as normal, but I want to add a Button to open Dialog. This does not work.
How can I achieve this?
I post to POST /v1/chat/channels/:channel_id/messages?
body:
{
"cards_v2": [{
"card": {
"header": {
"title": "Rolodex",
"subtitle": "Manage your contacts!",
"imageType": "CIRCLE",
"imageUrl": "https://www.gstatic.com/images/branding/product/2x/contacts_48dp.png"
},
"sections": [{
"widgets": [{
"buttonList": {
"buttons": [{
"text": "Add Contact",
"onClick": {
"action": {
"function": "openDialog",
"interaction": "OPEN_DIALOG"
}
}
}]
}
}]
}]
}
}]
}
Then I click on Button, and receive event:
{
"type": "CARD_CLICKED",
"eventTime": "2022-08-31T16:16:36.147391Z",
"message": {
"name": "spaces/:space_id/messages/YTyNVBNW-H4.YTyNVBNW-H4",
"sender": { ... },
"createTime": "2022-08-31T16:16:31.639439Z",
"thread": { ... },
"space": { ... },
"cardsV2": [{
"card": {
"header": {
"title": "Rolodex",
"subtitle": "Manage your contacts!",
"imageType": "CIRCLE",
"imageUrl": "https://www.gstatic.com/images/branding/product/2x/contacts_48dp.png"
},
"sections": [{
"widgets": [{
"buttonList": {
"buttons": [{
"text": "Add Contact",
"onClick": {
"action": {
"function": "openDialog"
}
}
}]
}
}]
}]
}
}],
"retentionSettings": {
"state": "PERMANENT"
}
},
"user": { ... },
"space": { ... },
"action": {
"actionMethodName": "openDialog"
},
"common": {
"hostApp": "CHAT",
"invokedFunction": "openDialog"
}
}
First: Event skips DialogEventType is REQUEST_DIALOG.
Second: When I respond with dialog response, but no dialog appears.
{
"actionResponse": {
"type": "DIALOG",
"dialogAction": {
"dialog": {
"body": {
"sections": [{
"header": "Add new contact",
"widgets": [{
"textInput": {
"name": "contactName",
"label": "Name",
"type": "SINGLE_LINE"
}
}, {
"buttonList": {
"buttons": [{
"text": "Next",
"onClick": {
"action": {
"function": "openSequentialDialog"
}
}
}]
}
}]
}]
}
}
}
}
}
I see only error:

MongoDB get fieldvalue based on fieldname

I'm new to MongoDB, and I'm not sure if what I'm trying to do is possible at all. I've exhausted my Google skills, so I'm hoping someone here can give me a push in the right direction.
My data is structured like this:
db={
"people": [
{
"id": 1,
"name": "Pete",
"occupation": "baker"
},
{
"id": 2,
"name": "Mike",
"occupation": "painter"
}
],
"activity": [
{
"baker": "bakes",
"painter": "paints"
}
]
}
Although this is just sample data, my "activity" is a single large document with unique keys that I'm trying to get the value from, based on key name (when it matches value from the "people" document).
What I'm trying to achieve is this output:
[
{
"id": 1,
"name": "Pete",
"occupation": "baker”,
“activity:” “bakes”
},
{
"id": 2,
"name": "Mike",
"occupation": "painter”,
“activity”: “paints”
}
]
Is this possible at all?
If I understand your database and data model, it seems like a poor model.
If the data model was different (see below), the query would be quite simple. Given that, here's one way you could generate your desired output with your model.
db.people.aggregate([
{ "$lookup": {
"from": "activity",
"let": { occ: "$occupation" },
"pipeline": [
{
"$replaceWith": {
"$arrayToObject": {
"$filter": {
"input": { "$objectToArray": "$$ROOT" },
"as": "kv",
"cond": { "$eq": [ "$$kv.k", "$$occ" ] }
}
}
}
}
],
"as": "activity"
}
},
{ "$set": {
"activity": {
"$getField": {
"field": "v",
"input": {
"$first": {
"$objectToArray": { "$first": "$activity" }
}
}
}
}
}
},
{ "$unset": "_id" }
])
Try it on mongoplayground.net.
If your activity collection has this model...
[
{
"occupation": "baker",
"activity": "bakes"
},
{
"occupation": "painter",
"activity": "paints"
}
]
... then the query could be:
db.people.aggregate([
{ "$lookup": {
"from": "activity",
"localField": "occupation",
"foreignField": "occupation",
"as": "activity"
}
},
{ "$set": { "activity": { "$first": "$activity.activity" } } },
{ "$unset": "_id" }
])
Try it on mongoplayground.net.

MongoDB Lookup values based on dynamic field name

I'm pretty sure the below can be done, I'm struggling to understand how to do it in MongoDB.
My data is structured like this (demo data):
db={
"recipes": [
{
"id": 1,
"name": "flatbread pizza",
"ingredients": {
"1010": 1,
"1020": 2,
"1030": 200
}
},
{
"id": 2,
"name": "cheese sandwich",
"ingredients": {
"1040": 1,
"1050": 2
}
}
],
"ingredients": [
{
"id": 1010,
"name": "flatbread",
"unit": "pieces"
},
{
"id": 1020,
"name": "garlic",
"unit": "clove"
},
{
"id": 1030,
"name": "tomato sauce",
"unit": "ml"
},
{
"id": 1040,
"name": "bread",
"unit": "slices"
},
{
"id": 1050,
"name": "cheese",
"unit": "slices"
}
]
}
The output I'm trying to achieve would look like this:
[
{
"id": 1,
"name": "flatbread pizza",
“flatbread”: “1 pieces”,
“garlic”: “2 cloves”,
“tomato sauce”: “200 ml”
},
{
"id": 2,
"name": "cheese sandwich",
“bread”: “1 slices”,
“cheese”: “2 slices”
}
]
I've tried several approaches, and I get stuck at the bit where I need to do a lookup based on the ingredient name (which actually is the id). I tried using $objectToArray to turn it into a k-v document, but then I get stuck in how to construct the lookup pipeline.
This is not a simple solution, and probably can be improved:
db.recipes.aggregate([
{
"$addFields": {
ingredientsParts: {
"$objectToArray": "$ingredients"
}
}
},
{
$unwind: "$ingredientsParts"
},
{
"$group": {
_id: "$id",
name: {
$first: "$name"
},
ingredientsParts: {
$push: {
v: "$ingredientsParts.v",
id: {
$toInt: "$ingredientsParts.k"
}
}
}
}
},
{
"$lookup": {
"from": "ingredients",
"localField": "ingredientsParts.id",
"foreignField": "id",
"as": "ingredients"
}
},
{
$unwind: "$ingredients"
},
{
"$addFields": {
"ingredientsPart": {
"$filter": {
input: "$ingredientsParts",
as: "item",
cond: {
$eq: [
"$$item.id",
"$ingredients.id"
]
}
}
}
}
},
{
$project: {
ingredients: 1,
ingredientsPart: {
"$arrayElemAt": [
"$ingredientsPart",
0
]
},
name: 1
}
},
{
"$addFields": {
units: {
k: "$ingredients.name",
v: {
"$concat": [
{
$toString: "$ingredientsPart.v"
},
" ",
"$ingredients.unit"
]
}
}
}
},
{
$group: {
_id: "$_id",
name: {
$first: "$name"
},
units: {
$push: "$units"
}
}
},
{
"$addFields": {
"data": {
"$arrayToObject": "$units"
}
}
},
{
"$addFields": {
"data.id": "$_id",
"data.name": "$name"
}
},
{
"$replaceRoot": {
"newRoot": "$data"
}
}
])
You can see it works here
As rickhg12hs said, it can be modeled better.

Querying an Array in Graphql

I have the following query on graphql
query articles {
articles {
news_link
article_details {
description
title
brands {
name
}
featured_image {
url
}
published_at
}
}
}
Which will give me the following sample response
{
"data": {
"articles": [
{
"news_link": "http://loanstreet.com.my",
"article_details": [
{
"description": "My first article",
"title": "First Article",
"brands": [
{
"name": "Fendi"
}
],
"featured_image": {
"url": "/uploads/e5c00dbd3a3648dd8c0e1c2a44f50c0d.png"
},
"published_at": "2020-03-31T04:00:00.000Z"
},
{
"description": "Lighter ff article",
"title": "First Article LP",
"brands": [
{
"name": "Lighter"
}
],
"featured_image": {
"url": "/uploads/ac6c5f26050f46eebd37fa7319ab531b.png"
},
"published_at": "2020-03-31T04:00:00.000Z"
}
]
}
]
}
}
I am trying to query and only get the response where brand name is "Fendi" but cannot seem to get it right using Graphql playground.
I tried this
query articles {
articles {
news_link
article_details {
description
title
brands(where: {name: "Fendi"}) {
name
}
featured_image {
url
}
published_at
}
}
}
but it gave me this response which is not really what i want
{
"data": {
"articles": [
{
"news_link": "http://loanstreet.com.my",
"article_details": [
{
"description": "My first article",
"title": "First Article",
"brands": [
{
"name": "Fendi"
}
],
"featured_image": {
"url": "/uploads/e5c00dbd3a3648dd8c0e1c2a44f50c0d.png"
},
"published_at": "2020-03-31T04:00:00.000Z"
},
{
"description": "Lighter ff article",
"title": "First Article LP",
"brands": [],
"featured_image": {
"url": "/uploads/ac6c5f26050f46eebd37fa7319ab531b.png"
},
"published_at": "2020-03-31T04:00:00.000Z"
}
]
}
]
}
}
I am expecting a response like this
{
"data": {
"articles": [
{
"news_link": "http://loanstreet.com.my",
"article_details": [
{
"description": "My first article",
"title": "First Article",
"brands": [
{
"name": "Fendi"
}
],
"featured_image": {
"url": "/uploads/e5c00dbd3a3648dd8c0e1c2a44f50c0d.png"
},
"published_at": "2020-03-31T04:00:00.000Z"
}
]
}
]
}
}
Any help is appreciated. Thanks

Create a new Google Sheet with row or column groups

I'm trying to create a new spreadsheet using spreadsheets#create, with specified row groups.
In the API Explorer, I am entering in the JSON below. which corresponds to the following appearance:
No errors are flagged or returned when I execute the call, but when the sheet is created, the specified grouping is not created - only the values are set.
{ "properties": {
"title": "Test Spreadsheet",
"locale": "en"
},
"sheets": [
{ "properties": {"title": "Test1"},
"data": [
{
"startRow": 0,
"startColumn": 0,
"rowData": [
{ "values": [
{ "userEnteredValue": { "stringValue": "Top1" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "Top2" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2A" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2B" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "" } },
{ "userEnteredValue": { "stringValue": "Top2C" } }
]
},
{ "values": [
{ "userEnteredValue": { "stringValue": "Top3" } }
]
}
]
}
],
"rowGroups": [
{ "range": {
"dimension": "ROWS",
"startIndex": 2,
"endIndex": 5
}
}
]
}
]
}
Even when I create the rowGroups JSON directly on the page, with its structured editor to make sure it is properly defined, the created spreadsheet still doesn't group the specified rows. I have triple-checked all my objects from the top down, and can't see what I am doing wrong.