Shopify GraphQL Query to retrieve UTM Parameters from Orders - graphql

I'm quite new to GraphQL syntax so would love to see why I am getting null back as my result.
What I am trying to is query orders in a store and retrieve back the UTM Params associated with that order.
This is the query:
query {
orders(first:10) {
edges {
node {
customerJourney {
moments {
... on CustomerVisit {
utmParameters {
source
campaign
content
medium
term
}
}
}
}
}
}
}
}
This is the results:
{
"data": {
"orders": {
"edges": [
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
},
{
"node": {
"customerJourney": null
}
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 42,
"actualQueryCost": 22,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 978,
"restoreRate": 50
}
}
}
}
It seems all the customerJourney's are returning null. Is there something wrong with the query?

Shopify will only show data on orders that are less than 60 days old. As you have stated "first: 10" you're asking for the first 10 orders on that store which are likely over 60 days old. Try getting the last 10 orders using the reverse boolean.
query {
orders(first: 10, reverse:true) {
edges {
node {
customerJourney {
moments {
... on CustomerVisit {
utmParameters {
source
campaign
content
medium
term
}
}
}
}
}
}
}
}

Related

Graphql $limit variable not returning correct amount of items on AWS Appsync

Running the following query, I get two results:
query x($keyword: String = "Pulp", $limit: Int, $nexttoken: String) {
listProducts(filter: {or: [{name: {contains: $keyword}}, {description: {contains: $keyword}}]}, limit: $limit, nextToken: $nexttoken) {
items {
id
}
nextToken
}
}
Response:
{
"data": {
"listProducts": {
"items": [
{
"id": "ba8048f3-1099-4184-8e78-f0e57b521465"
},
{
"id": "335770ad-f566-4385-a861-7d0dab6c9dd8"
}
],
"nextToken": null
}
}
}
By setting $limit: Int=1, I get an empty array of items:
{
"data": {
"listProducts": {
"items": [],
"nextToken": "xxxxxx"
}
}
}
By setting $limit: Int=2, I get one item:
{
"data": {
"listProducts": {
"items": [
{
"id": "ba8048f3-1099-4184-8e78-f0e57b521465"
}
],
"nextToken": "xxxxxx"
}
}
}
In order to get all 2 two items, I need to set $limit=4. Why?

Why is my graphql query return all product?

I'm testing graphql query on Shopify GraphiQL Explorer for filtering products on Storefront API.
My query is like this:
query ProductType {
collectionByHandle(handle: "pants") {
handle
products(first: 10, filters: {
productType: "pants"
}) {
edges {
node {
handle
productType
}
}
}
}
}
And got the result like this:
{
"data": {
"collectionByHandle": {
"handle": "pants",
"products": {
"edges": [
{
"node": {
"handle": "my-test-product-pants",
"productType": "pants"
}
},
{
"node": {
"handle": "pleated-straight-pants-mens-fashion-elastic-waist-casual-pants-men-streetwear-loose-ice-silk-trousers-mens-wide-leg-pants-s-2xl",
"productType": ""
}
},
...
Basically, the result has all the products that I have for that collection. Can anybody help me with this? This is literally the code I got from shopify website
As we can see in the tutorial filters is an array
{
"product_filters": [
{
"productType": "shoes"
},
{
"productVendor": "bestshop"
},
{
"variantOption": {
"name": "color",
"value": "blue"
}
}
]
}
So, try this instead
query ProductType {
collectionByHandle(handle: "pants") {
handle
products(first:10, filters: [{ productType: "pants" ]}) {
...
}
}
}

How can I find customer by email in Shopify graphql

Now I am testing the Shopify graphql for get customer by email.
But Shopify Customer query does not work correctly. query is following.
{
customers(first: 10, query:"email:'test#gmail.com'") {
edges {
node {
id
lastName
verifiedEmail
firstName
lastName
email
phone
tags
}
}
}
}
but the result is following.
{
"data": {
"customers": {
"edges": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 252,
"actualQueryCost": 2,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 998,
"restoreRate": 50
}
}
}
}
Shopify Store have that customer. But the query didn't find customer.
I am sure we can solve this problem.
If you have experience one, please help me.
Thanks.
Not sure if you still need an answer. The string after query: needs to be just the email. see here:
query GetThat {
customers(first: 10, query: "mikeyboy#aol.com"){
edges{
node {
firstName
lastName
defaultAddress {
id
address1
}
}
}
}
}
Results:
{
"data": {
"customers": {
"edges": [
{
"node": {
"firstName": "MikeyBoy",
"lastName": "ohohoh",
"defaultAddress": {
"id": "gid://shopify/MailingAddress/7969224163540?model_name=CustomerAddress",
"address1": "123 sesame st"
}
}
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 22,
"actualQueryCost": 4,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 996,
"restoreRate": 50
}
}
}
}

How to filter GraphQL query?

I'm new to GraphQL and got stuck in a query. Well, this is sample GQL that returns every record in database:
{
viewer {
savingsAccount {
id
feed {
id
__typename
title
detail
postDate
... on TransferInEvent {
amount
originAccount {
name
}
}
... on TransferOutEvent {
amount
destinationAccount {
name
}
}
... on TransferOutReversalEvent {
amount
}
... on BillPaymentEvent {
amount
}
... on DebitPurchaseEvent {
amount
}
... on BarcodePaymentEvent {
amount
}
... on DebitWithdrawalFeeEvent {
amount
}
... on DebitWithdrawalEvent {
amount
}
}
}
}
}
Here is sample return:
{
"data": {
"viewer": {
"savingsAccount": {
"id": "5c8fe258-34fd-4bdc-bfb6-761bc78435df",
"feed": [{
"id": "5fcd6040-cf19-4dbf-be25-47d2f1a7a29b",
"__typename": "DebitPurchaseEvent",
"title": "Test",
"detail": "Test $$",
"postDate": "2020-12-06",
"amount": 59.7
}, {
"id": "5fcd5bbd-fc70-4d87-944d-d0a186559289",
"__typename": "DebitPurchaseEvent",
"title": "Test",
"detail": "Test $$",
"postDate": "2020-12-06",
"amount": 30.0
}
}
}
}
}
How do I apply filter to return some specific postDate? I mean, after, before, etc. This attribute is stored as string but I believe it is possible to do some convertion.
Thanks in advance!

prismic graphql querying single user

I'm trying to figure out how to query a single user from graphql schema by id. I'm using the graphiql tool and I'm able to get all Users.
{
allPrismicUsers {
edges {
node {
id
data {
name
}
}
}
}
}
Outputs :
{
"data": {
"allPrismicUsers”: {
"edges": [
{
"node": {
"id": "Prismic__User__WzKFwywAABmiZk_4",
"data": {
"name": “John Doe”
}
}
},
{
"node": {
"id": "Prismic__User__WzKDZywAABmiZkYp",
"data": {
"name": “Jane Doe“
}
}
},
{
"node": {
"id": "Prismic__User__WzKGDiwAAJSiZlFL",
"data": {
"name": “Cat Doe”
}
}
}
]
}
}
}
I also have prismicUser() on the schema
query {
prismicUser {
id
data {
name
}
}
}
Output:
{
"data": {
"prismicUser": {
"id": "Prismic__User__WzKGDiwAAJSiZlFL",
"data": {
"name": "Cat Doe"
}
}
}
}
I'm trying to query a user based on a specific id but not sure if I'm querying the wrong way.
I tried this.
query {
prismicLocation(id: "Prismic__User__WzKDZywAABmiZkYp") {
data {
name
}
}
}
I get an error
{ "errors": [
{
"message": "Argument \"id\" has invalid value \"Prismic__User__WzKDZywAABmiZkYp\".\nExpected
\"prismicUserIdQueryString_2\", found not an object.",
"users": [
{
"line": 25,
"column": 23
}
]
} ] }
How can I call a specific user based on their id ?
According to the Gatsby GraphQL reference, Gatsby allows you to filter results by any field in GraphQL (using operators such as eq, ne, etc.)
The gatsby-source-prismic plugin provides a field called prismicId (i.e. W1syKSIAAAzdN1Jg).
Here is an example query:
{
prismicUser(prismicId:{eq:"WzKDZywAABmiZkYp"}) {
data {
name
}
}
}
But you can also query by id:
prismicUser(id:{eq:"Prismic__User__WzKDZywAABmiZkYp"})

Resources