mutation M($marketingEngagement: MarketingEngagementInput!, $marketingActivityId: ID, $channelHandle: String, $remoteId: String) {
marketingEngagementCreate(marketingEngagement: $marketingEngagement, marketingActivityId: $marketingActivityId, channelHandle: $channelHandle, remoteId: $remoteId) {
marketingEngagement {
occurredOn
utcOffset
isCumulative
adSpend {
amount
currencyCode
}
clicksCount
impressionsCount
commentsCount
favoritesCount
unsubscribesCount
complaintsCount
failsCount
sendsCount
uniqueViewsCount
uniqueClicksCount
sharesCount
viewsCount
sessionsCount
sales {
amount
currencyCode
}
orders
firstTimeCustomers
returningCustomers
marketingActivity {
id
}
channelHandle
}
userErrors {
field
message
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation M($marketingEngagement: MarketingEngagementInput!, $marketingActivityId: ID, $channelHandle: String, $remoteId: String) { marketingEngagementCreate(marketingEngagement: $marketingEngagement, marketingActivityId: $marketingActivityId, channelHandle: $channelHandle, remoteId: $remoteId) { marketingEngagement { occurredOn utcOffset isCumulative adSpend { amount currencyCode } clicksCount impressionsCount commentsCount favoritesCount unsubscribesCount complaintsCount failsCount sendsCount uniqueViewsCount uniqueClicksCount sharesCount viewsCount sessionsCount sales { amount currencyCode } orders firstTimeCustomers returningCustomers marketingActivity { id } channelHandle } userErrors { field message } } }",
"variables": {
"marketingEngagement": {
"occurredOn": "2018-06-29",
"utcOffset": "-07:00",
"isCumulative": false,
"adSpend": {
"currencyCode": "CAD",
"amount": "19.90"
},
"impressionsCount": 100,
"clicksCount": 40,
"commentsCount": 1,
"unsubscribesCount": 1,
"complaintsCount": 1,
"failsCount": 1,
"sendsCount": 1,
"uniqueViewsCount": 1,
"uniqueClicksCount": 1,
"sharesCount": 5,
"viewsCount": 10,
"favoritesCount": 0,
"sessionsCount": 40,
"sales": {
"amount": "304.50",
"currencyCode": "CAD"
},
"orders": 8,
"firstTimeCustomers": 5.0,
"returningCustomers": 3.0
},
"marketingActivityId": "gid://shopify/MarketingActivity/794355127",
"channelHandle": null,
"remoteId": null
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation M($marketingEngagement: MarketingEngagementInput!, $marketingActivityId: ID, $channelHandle: String, $remoteId: String) {
marketingEngagementCreate(marketingEngagement: $marketingEngagement, marketingActivityId: $marketingActivityId, channelHandle: $channelHandle, remoteId: $remoteId) {
marketingEngagement {
occurredOn
utcOffset
isCumulative
adSpend {
amount
currencyCode
}
clicksCount
impressionsCount
commentsCount
favoritesCount
unsubscribesCount
complaintsCount
failsCount
sendsCount
uniqueViewsCount
uniqueClicksCount
sharesCount
viewsCount
sessionsCount
sales {
amount
currencyCode
}
orders
firstTimeCustomers
returningCustomers
marketingActivity {
id
}
channelHandle
}
userErrors {
field
message
}
}
}`,
{
variables: {
"marketingEngagement": {
"occurredOn": "2018-06-29",
"utcOffset": "-07:00",
"isCumulative": false,
"adSpend": {
"currencyCode": "CAD",
"amount": "19.90"
},
"impressionsCount": 100,
"clicksCount": 40,
"commentsCount": 1,
"unsubscribesCount": 1,
"complaintsCount": 1,
"failsCount": 1,
"sendsCount": 1,
"uniqueViewsCount": 1,
"uniqueClicksCount": 1,
"sharesCount": 5,
"viewsCount": 10,
"favoritesCount": 0,
"sessionsCount": 40,
"sales": {
"amount": "304.50",
"currencyCode": "CAD"
},
"orders": 8,
"firstTimeCustomers": 5.0,
"returningCustomers": 3.0
},
"marketingActivityId": "gid://shopify/MarketingActivity/794355127",
"channelHandle": null,
"remoteId": null
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation M($marketingEngagement: MarketingEngagementInput!, $marketingActivityId: ID, $channelHandle: String, $remoteId: String) {
marketingEngagementCreate(marketingEngagement: $marketingEngagement, marketingActivityId: $marketingActivityId, channelHandle: $channelHandle, remoteId: $remoteId) {
marketingEngagement {
occurredOn
utcOffset
isCumulative
adSpend {
amount
currencyCode
}
clicksCount
impressionsCount
commentsCount
favoritesCount
unsubscribesCount
complaintsCount
failsCount
sendsCount
uniqueViewsCount
uniqueClicksCount
sharesCount
viewsCount
sessionsCount
sales {
amount
currencyCode
}
orders
firstTimeCustomers
returningCustomers
marketingActivity {
id
}
channelHandle
}
userErrors {
field
message
}
}
}`,
"variables": {
"marketingEngagement": {
"occurredOn": "2018-06-29",
"utcOffset": "-07:00",
"isCumulative": false,
"adSpend": {
"currencyCode": "CAD",
"amount": "19.90"
},
"impressionsCount": 100,
"clicksCount": 40,
"commentsCount": 1,
"unsubscribesCount": 1,
"complaintsCount": 1,
"failsCount": 1,
"sendsCount": 1,
"uniqueViewsCount": 1,
"uniqueClicksCount": 1,
"sharesCount": 5,
"viewsCount": 10,
"favoritesCount": 0,
"sessionsCount": 40,
"sales": {
"amount": "304.50",
"currencyCode": "CAD"
},
"orders": 8,
"firstTimeCustomers": 5.0,
"returningCustomers": 3.0
},
"marketingActivityId": "gid://shopify/MarketingActivity/794355127",
"channelHandle": null,
"remoteId": null
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation M($marketingEngagement: MarketingEngagementInput!, $marketingActivityId: ID, $channelHandle: String, $remoteId: String) {
marketingEngagementCreate(marketingEngagement: $marketingEngagement, marketingActivityId: $marketingActivityId, channelHandle: $channelHandle, remoteId: $remoteId) {
marketingEngagement {
occurredOn
utcOffset
isCumulative
adSpend {
amount
currencyCode
}
clicksCount
impressionsCount
commentsCount
favoritesCount
unsubscribesCount
complaintsCount
failsCount
sendsCount
uniqueViewsCount
uniqueClicksCount
sharesCount
viewsCount
sessionsCount
sales {
amount
currencyCode
}
orders
firstTimeCustomers
returningCustomers
marketingActivity {
id
}
channelHandle
}
userErrors {
field
message
}
}
}
QUERY
variables = {
"marketingEngagement": {
"occurredOn": "2018-06-29",
"utcOffset": "-07:00",
"isCumulative": false,
"adSpend": {
"currencyCode": "CAD",
"amount": "19.90"
},
"impressionsCount": 100,
"clicksCount": 40,
"commentsCount": 1,
"unsubscribesCount": 1,
"complaintsCount": 1,
"failsCount": 1,
"sendsCount": 1,
"uniqueViewsCount": 1,
"uniqueClicksCount": 1,
"sharesCount": 5,
"viewsCount": 10,
"favoritesCount": 0,
"sessionsCount": 40,
"sales": {
"amount": "304.50",
"currencyCode": "CAD"
},
"orders": 8,
"firstTimeCustomers": 5.0,
"returningCustomers": 3.0
},
"marketingActivityId": "gid://shopify/MarketingActivity/794355127",
"channelHandle": nil,
"remoteId": nil
}
response = client.query(query: query, variables: variables)