### Example Installation Request Query String
Source: https://shopify.dev/docs/apps/auth/oauth
This is an example of the query string received when a user installs your app. It includes shop, timestamp, and hmac parameters.
```text
"hmac=700e2dadb827fcc8609e9d5ce208b2e9cdaab9df07390d2cbca10d7c328fc4bf&shop={shop}.myshopify.com×tamp=1337178173"
```
--------------------------------
### Example Query String with HMAC and Code Parameters
Source: https://shopify.dev/docs/apps/auth/oauth
This example displays the full query string including the 'hmac' and 'code' parameters, as received during an app installation request.
```text
"code=0907a61c0c8d55e99db179b68161bc00&hmac=700e2dadb827fcc8609e9d5ce208b2e9cdaab9df07390d2cbca10d7c328fc4bf&shop={shop}.myshopify.com&state=0.6784241404160823×tamp=1337178173"
```
--------------------------------
### Start Application (npm, yarn, pnpm)
Source: https://shopify.dev/docs/apps/deployment/web
Start your Shopify application after setting up the database and environment variables. Check logs if the app fails to start.
```bash
npm run start
```
```bash
yarn start
```
```bash
pnpm run start
```
--------------------------------
### Install Shopify AI Toolkit
Source: https://shopify.dev/docs/apps/build/ai-toolkit
Use this command to install the entire Shopify AI Toolkit. Ensure you have Node.js and npm installed.
```bash
npx skills add Shopify/shopify-ai-toolkit
```
--------------------------------
### Install Shopify AI Toolkit Skill
Source: https://shopify.dev/docs/apps/build/devmcp
Use this command to install the entire Shopify AI Toolkit. To install a single skill, use the `--skill` flag.
```bash
npx skills add Shopify/shopify-ai-toolkit
```
```bash
npx skills add Shopify/shopify-ai-toolkit --skill shopify-admin
```
--------------------------------
### Install jsonwebtoken Package
Source: https://shopify.dev/docs/apps/build/discounts/network-access
Install the jsonwebtoken package for your mock HTTP server.
```bash
npm i jsonwebtoken
```
--------------------------------
### Deploy Shopify App with GitHub Actions (Yarn)
Source: https://shopify.dev/docs/apps/launch/deployment/deploy-in-ci-cd-pipeline
This GitHub Actions workflow deploys app components to Shopify using Yarn as the package manager. It mirrors the npm example but uses Yarn commands for dependency installation and CLI setup.
```yaml
name: Deploy app
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- name: Install npm dependencies
run: yarn install
- name: Install Shopify CLI
run: yarn global add @shopify/cli@latest
- name: Deploy
env:
# Token from the Dev Dashboard
SHOPIFY_APP_AUTOMATION_TOKEN: ${{ secrets.SHOPIFY_APP_AUTOMATION_TOKEN }}
COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
run: shopify app deploy --config production --allow-updates --source-control-url "$COMMIT_URL"
```
--------------------------------
### Set up environment variables
Source: https://shopify.dev/docs/apps/build/storefront-mcp/build-storefront-ai-agent
Rename the .env.example file to .env and add your Claude API key.
```bash
CLAUDE_API_KEY=your_claude_api_key
```
--------------------------------
### Run Setup Script (npm, yarn, pnpm)
Source: https://shopify.dev/docs/apps/deployment/web
Execute the setup script to create or update your database. Ensure your environment variables are correctly configured before running.
```bash
npm run setup
```
```bash
yarn setup
```
```bash
pnpm run setup
```
--------------------------------
### Retrieve App Installation ID
Source: https://shopify.dev/docs/apps/build/custom-data/ownership
Use the `currentAppInstallation` query to get the app installation ID, which is needed for setting app-data metafields.
```graphql
query {
currentAppInstallation {
id
}
}
```
--------------------------------
### Retrieve App Installation ID
Source: https://shopify.dev/docs/apps/build/custom-data/metafields
Get the app installation ID using the `currentAppInstallation` GraphQL query. This ID is necessary for setting app-data metafields.
```APIDOC
## POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
### GraphQL query
```graphql
query {
currentAppInstallation {
id
}
}
```
### Response
```json
{
"data": {
"currentAppInstallation": {
"id": "gid://shopify/AppInstallation/123456"
}
}
}
```
```
--------------------------------
### Start Development Server with Localhost
Source: https://shopify.dev/docs/apps/build/storefront-mcp/servers/customer-account
Restart your server using this command to apply customer account authentication configurations.
```bash
$ shopify app dev --use-localhost
```
--------------------------------
### Retrieve App Installation ID
Source: https://shopify.dev/docs/apps/custom-data
Get the unique app installation ID using the `currentAppInstallation` GraphQL query. This ID is necessary for setting app-specific metafields.
```APIDOC
## POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
### Description
Retrieves the current app installation ID.
### Method
POST
### Endpoint
https://{shop}.myshopify.com/api/{api_version}/graphql.json
### Request Body
```graphql
query {
currentAppInstallation {
id
}
}
```
### Response
#### Success Response (200)
- **data** (object) - Contains the result of the query.
- **currentAppInstallation** (object)
- **id** (ID) - The unique identifier for the app installation.
### Response Example
```json
{
"data": {
"currentAppInstallation": {
"id": "gid://shopify/AppInstallation/123456"
}
}
}
```
```
--------------------------------
### Create Product with Basic Options
Source: https://shopify.dev/docs/apps/build/product-merchandising/products-and-collections/metafield-linked
This example shows how to create a basic product using the `productCreate` mutation, setting essential fields like the title.
```APIDOC
## POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
## GraphQL mutation
```graphql
mutation CreateProduct($product: ProductInput!) {
productCreate(product: $product) {
product {
id
title
options {
name
values
}
}
userErrors {
field
message
}
}
}
```
## Variables
```json
{
"product": {
"title": "T-Shirt",
"options": [
{
"name": "Size",
"values": ["Small", "Medium", "Large"]
}
]
}
}
```
```
--------------------------------
### Start the development server
Source: https://shopify.dev/docs/apps/build/storefront-mcp/build-storefront-ai-agent
Start the development server using the Shopify CLI. Ensure you use --use-localhost and --reset flags.
```bash
shopify app dev --use-localhost --reset
```
--------------------------------
### Start development server
Source: https://shopify.dev/docs/apps/payments/credit-card/build-credit-card-app?framework=remix
Start your development server using the `app dev` command. Ensure this command is running to serve your app during development.
```bash
app dev
```
--------------------------------
### Get Inventory Levels with Pagination (REST)
Source: https://shopify.dev/docs/apps/build/graphql/migrate/learn-how
This is an example of a GET request to retrieve inventory levels, demonstrating how to specify inventory item IDs. The response includes inventory details and pagination information.
```http
GET /admin/api/{api_version}/inventory_levels.json?inventory_item_ids={inventory_item_id}
```
--------------------------------
### Run Development Server
Source: https://shopify.dev/docs/apps/build/app-home/app-home-ui-extensions
Command to start a local development server for previewing the extension in your dev store's admin. Press 'p' to open the preview URL.
```bash
shopify app dev
```
--------------------------------
### TOML (app-owned) example
Source: https://shopify.dev/docs/apps/build/metaobjects/manage-metaobject-definitions
This example demonstrates how to create an app-owned metaobject definition for author profiles using a `shopify.app.toml` configuration file. This ensures the definition is consistently deployed across all installations and maintained by the app.
```APIDOC
## shopify.app.toml
[metaobjects.app.author]
name = "Author"
access.admin = "merchant_read_write"
access.storefront = "public_read"
[metaobjects.app.author.fields.full_name]
name = "Full Name"
type = "single_line_text_field"
[metaobjects.app.author.fields.bio]
name = "Biography"
type = "multi_line_text_field"
[metaobjects.app.author.fields.email]
name = "Email"
type = "single_line_text_field"
[metaobjects.app.author.fields.photo]
name = "Profile Photo"
type = "file_reference"
## Deploy the changes with your app:
##
```bash
shopify app deploy
```
```
--------------------------------
### Preact MapPopover Example
Source: https://shopify.dev/docs/apps/build/checkout/migrate-to-web-components/map-popover
Use this Preact snippet to render a map with a popover marker in a Shopify extension. Ensure you have the '@shopify/ui-extensions/preact' package installed.
```javascript
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
export default function extension() {
render(, document.body);
}
function Extension() {
return (
620 King Street West, Toronto
);
}
```
--------------------------------
### Start your app development server
Source: https://shopify.dev/docs/apps/build/payments/credit-card/use-the-cli
Use the Shopify CLI to build and preview your app on a dev store. This command starts a development server with a permanent tunnel.
```bash
shopify app dev --tunnel-url
```
--------------------------------
### Filter by prefix match
Source: https://shopify.dev/docs/apps/build/metafields/query-using-metafields
Use the `*` wildcard to find resources where a string metafield starts with specific characters. This is useful for partial matches when you don't know the complete value. The following example finds all products that start with "notch" as their lapel type on a custom suit.
```APIDOC
## POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
### GraphQL mutation
```graphql
query NotchLapelProducts {
products(first: 20, query: "metafields.custom.lapel_style:notch*") {
edges {
node {
id
title
metafield(namespace: "custom", key: "lapel_style") {
value
}
}
}
}
}
```
```
--------------------------------
### Use app configuration
Source: https://shopify.dev/docs/apps/build/cli-for-apps/test-apps-locally
Switch to the development configuration of your app if necessary. This command prepares your app for local development.
```bash
shopify app config use
```
--------------------------------
### Refund Created Webhook Example
Source: https://shopify.dev/docs/apps/build/purchase-options/subscriptions/fulfillments/sync-orders-subscriptions
Occurs when a refund is created. This webhook can be used to ensure contracts get updated as well, if that's the merchant's intention.
```json
{
"id": 890088186047892319,
"order_id": 820982911946154508,
"created_at": null,
"note": "Things were damaged",
"user_id": 548380009,
"processed_at": null,
"restock": false,
"duties": [
],
"total_duties_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"admin_graphql_api_id": "gid:\/\/shopify\/Refund\/890088186047892319",
"refund_line_items": [
{
"id": 866550311766439093,
"quantity": 1,
"line_item_id": 866550311766439020,
"location_id": null,
"restock_type": "no_restock",
"subtotal": 199.0,
"total_tax": 0.0,
"subtotal_set": {
"shop_money": {
"amount": "199.00",
"currency_code": "USD"
}
}
}
]
}
```
--------------------------------
### Get Customer Details (REST)
Source: https://shopify.dev/docs/apps/build/graphql/migrate/learn-how
Example of retrieving customer details using the REST API. This endpoint requires the shop domain, API version, and customer ID.
```text
GET https://{shop}.myshopify.com/admin/api/{api_version}/customer/6201722765389.json
```
--------------------------------
### Startup Script for Cloud Run
Source: https://shopify.dev/docs/apps/launch/deployment/deploy-to-google-cloud-run
Launches the Cloud SQL Proxy and then starts the production application. Ensures the database connection is available before Prisma operations.
```shell
#!/bin/sh
# Start Cloud SQL Proxy in background
/cloud-sql-proxy --port 5432 ${INSTANCE_CONNECTION_NAME} &
# Wait for proxy to be ready
sleep 3
# Run production setup and start the app
npm run setup:prod && npm run start
```
--------------------------------
### Migrate onPress to onClick in React Extensions
Source: https://shopify.dev/docs/apps/build/customer-accounts/migrate-to-web-components/link
Use the `onClick` prop for handling link clicks in React customer account extensions. This example demonstrates the setup for a React extension using `reactExtension`.
```javascript
import {
reactExtension,
Link,
} from '@shopify/ui-extensions-react/customer-account';
export default reactExtension(
'customer-account.profile.block.render',
() => ,
);
function Extension() {
return console.log('Clicked')}>Learn more;
}
```
--------------------------------
### Create an App Version
Source: https://shopify.dev/docs/apps/build/checkout/customize-header
Navigate to your app directory and run this command to create and release an app version, which is a snapshot of your app configuration and extensions.
```bash
shopify app version
```
--------------------------------
### Nest a Warranty Line Item in Preact
Source: https://shopify.dev/docs/apps/build/product-merchandising/nested-cart-lines/create-nested-cart-lines
Use the `useCartLineTarget` hook to get cart line information and `applyCartLinesChange` to add a nested item. This example adds a warranty to the first cart line.
```javascript
import {render} from 'preact';
import {useCartLineTarget} from '@shopify/ui-extensions/checkout/preact';
export default function extension() {
render(, document.body);
}
function Extension() {
const cartLines = useCartLines();
const lineId = cartLines[0]?.id;
const warrantyVariantId = "gid://shopify/ProductVariant/2";
const handleNestWarranty = async () => {
try {
const result = await shopify.applyCartLinesChange({
type: 'addCartLine',
merchandiseId: warrantyVariantId,
quantity: 1,
parent: {
lineId,
}
});
if (result.type === 'error') {
throw new Error(result.message);
}
} catch (error) {
throw new Error(error)
}
return (
Nest line
);
}
```
--------------------------------
### Using GraphQL Client to Create a Product
Source: https://shopify.dev/docs/apps/build/graphql/migrate/libraries
Demonstrates creating a product using the GraphQL Admin client and a mutation.
```APIDOC
## POST /graphql
### Description
Creates a new product using a GraphQL mutation.
### Method
POST
### Endpoint
/graphql
### Request Body
- **query** (string) - Required - The GraphQL mutation string.
- **variables** (object) - Required - The variables for the mutation.
- **input** (object) - Required - The input for product creation.
- **title** (string) - Required - The title of the product.
### Request Example
```json
{
"query": "mutation($input: ProductInput!) { productCreate(input: $input) { product { id title } userErrors { field message } } }",
"variables": {
"input": {
"title": "My new product"
}
}
}
```
### Response
#### Success Response (200)
- **data** (object) - The result of the GraphQL query.
- **productCreate** (object) - The result of the product creation mutation.
- **product** (object) - The created product details.
- **id** (string) - The ID of the created product.
- **title** (string) - The title of the created product.
- **userErrors** (array) - Any errors encountered during the mutation.
#### Response Example
```json
{
"data": {
"productCreate": {
"product": {
"id": "gid://shopify/Product/12345",
"title": "My new product"
},
"userErrors": []
}
}
}
```
```
--------------------------------
### Initial Checkout Branding Customizations
Source: https://shopify.dev/docs/apps/build/checkout/styling/customize-sections
This example shows the initial structure for customizing checkout branding, specifically setting colors and corner radius for the main section. It's a starting point for more complex styling.
```json
{
"checkoutProfileId": "gid://shopify/CheckoutProfile/YOUR_CHECKOUT_PROFILE_ID_HERE",
"checkoutBrandingInput": {
"customizations": {
"main": {
"section": {
"colorScheme": "COLOR_SCHEME2",
"cornerRadius": "NONE",
"padding": "LARGE_200",
"border": "FULL"
}
}
}
}
}
```
```json
{
"data": {
"checkoutBrandingUpsert": {
"checkoutBranding": {
"customizations": {
"main": {
"section": {
"colorScheme": "COLOR_SCHEME2",
"cornerRadius": "NONE",
"padding": "LARGE_200",
"border": "FULL"
}
}
}
},
"userErrors": []
}
}
}
```
--------------------------------
### Create Reporting Function for Onboarding Started Event
Source: https://shopify.dev/docs/apps/build/app-events/send-events
Use this function to send an 'onboarding_started' event. It requires the shop ID and access token. Ensure the idempotency key is unique for each onboarding flow version.
```javascript
async function reportOnboardingStarted(shopId, accessToken) {
const response = await fetch(
"https://api.shopify.com/app/unstable/events",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify({
shop_id: shopId,
event_handle: "onboarding_started",
timestamp: new Date().toISOString(),
idempotency_key: `onboard_start_${shopId}_v3`,
attributes: {
onboarding_version: 3,
total_steps: 5,
source: "app_install",
},
}),
}
);
if (!response.ok) {
console.error(
"Failed to report onboarding started:",
response.status
);
}
}
```
--------------------------------
### Initialize development environment with CLI template
Source: https://shopify.dev/docs/apps/build/shopifyql/python-sdk-and-cli
Use the Shopify CLI to initialize a development environment with a Jupyter notebook template for a fast start. This template includes a pre-configured Python environment and automatic app setup.
```terminal
shopify app init --template=https://github.com/Shopify/shopify-app-notebooks-template
```
--------------------------------
### Shopify GraphQL Query with Axios
Source: https://shopify.dev/docs/apps/build/graphql/migrate/libraries
Utilize Axios to send a POST request to the Shopify GraphQL endpoint. This example demonstrates passing query variables separately, which can be useful for dynamic queries. Requires the 'axios' package to be installed.
```javascript
(async () => {
const axios = require('axios');
// Update to the GraphQL endpoint
const options = {
url: 'https://shop.myshopify.com/admin/api/2023-10/graphql.json',
// Use POST instead of GET
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': 'YOUR-ACCESS-TOKEN'
},
// Pass the query in the request body
// Add a query with the fields that you want to retrieve
// Use a GID instead of a simple ID
data: JSON.stringify({
query: `
query product($id: ID!) {
product(id: $id) {
title
description
}
}`,
variables: {
id: "gid://shopify/Product/1234"
}
})
}
// Destructure the response
const { data: { data: { product } } } = await axios(options);
console.log(product);
})();
```
--------------------------------
### Example Shopify App Configuration File
Source: https://shopify.dev/docs/apps/build/app-configuration
This TOML file demonstrates the structure and common settings for configuring a Shopify application, including client ID, URLs, scopes, authentication, and webhooks.
```toml
name = "Example App"
client_id = "a61950a2cbd5f32876b0b55587ec7a27"
application_url = "https://www.app.example.com/"
embedded = true
handle = "example-app"
[access_scopes]
scopes = "read_products"
[access.admin]
direct_api_mode = "online"
[auth]
redirect_urls = [
"https://app.example.com/api/auth/callback",
"https://app.example.com/api/auth/oauth/callback",
]
[customer_authentication]
redirect_uris = [
"https://app.example.com/api/customer/auth/callback"
]
javascript_origins = [
"https://app.example.com"
]
logout_urls = [
"https://app.example.com/api/customer/logout"
]
[webhooks]
api_version = "2024-01"
[[webhooks.subscriptions]]
topics = [ "app/uninstalled" ]
compliance_topics = [ "customers/redact", "customers/data_request", "shop/redact" ]
uri = "/webhooks"
```
--------------------------------
### Extract PayPal payment method from Braintree
Source: https://shopify.dev/docs/apps/build/purchase-options/subscriptions/migrate-to-subscriptions-api
Use this Ruby snippet to extract PayPal payment method details from a Braintree customer. This is a starting point for migrating PayPal payment methods and requires Braintree SDK setup.
```ruby
require "rubygems"
require "braintree"
gateway = Braintree::Gateway.new(
:environment => :sandbox,
:merchant_id => "merchant_id",
:public_key => "public_key",
:private_key => "private_key",
)
customer = gateway.customer.find('customer_id')
paypal_payment_method = customer.payment_methods.find { |pm| pm.is_a?(Braintree::PayPalAccount) }
puts "customer_id: #{customer.id}, billing_agreement_id: #{paypal_payment_method.billing_agreement_id}"
```
--------------------------------
### Navigate to Mock HTTP Server Directory
Source: https://shopify.dev/docs/apps/build/discounts/network-access
Navigate to the directory where you created the mock HTTP server.
```bash
cd mock-http-server
```
--------------------------------
### Get Customer Details (GraphQL)
Source: https://shopify.dev/docs/apps/build/graphql/migrate/learn-how
Example of retrieving customer details using a GraphQL query. This query targets a specific customer by their global ID and requests various fields including marketing consent and order information.
```graphql
POST https://{shop}.myshopify.com/admin/api/{api_version}/graphql.json
{
customer(id: "gid://shopify/Customer/6201722765389") {
id
email
emailMarketingConsent {
marketingState
consentUpdatedAt
marketingOptInLevel
}
createdAt
updatedAt
firstName
lastName
numberOfOrders
state
amountSpent {
amount
currencyCode
}
lastOrder {
id
name
}
note
verifiedEmail
multipassIdentifier
taxExempt
tags
market {
currencySettings {
baseCurrency {
currencyCode
}
}
}
phone
}
}
```
--------------------------------
### Start Development Server
Source: https://shopify.dev/docs/apps/build/discounts/build-discount-function
Run the `shopify app dev` command to start your development server. This command automatically watches for changes in your Function's build files and applies them.
```bash
shopify app dev
```
--------------------------------
### Reading Metafields
Source: https://shopify.dev/docs/apps/build/metafields/manage-metafields
Query metafields through their parent resource using GraphQL. This example retrieves a product along with its metafields, demonstrating common patterns like fetching metafields with pagination, getting a specific metafield by namespace/key, and filtering by namespace.
```APIDOC
## Reading Metafields
### Description
Query metafields through their parent resource using GraphQL. This example retrieves a product along with its metafields, demonstrating three common patterns: fetching metafields (with pagination), getting a specific metafield by namespace/key, and filtering by namespace.
### GraphQL Endpoint
`POST https://{shop}.myshopify.com/api/{api_version}/graphql.json`
### Request Body Example (GraphQL Query)
```graphql
query GetProductWithMetafields {
product(id: "gid://shopify/Product/1234567890") {
id
title
metafields(first: 10) {
edges {
node {
namespace
key
value
type
}
}
}
warranty: metafield(namespace: "product_details", key: "warranty_info") {
value
}
productDetails: metafields(namespace: "product_details", first: 20) {
edges {
node {
key
value
}
}
}
}
}
```
### Notes
For advanced querying techniques, see Query using metafields.
```
--------------------------------
### Start Shopify CLI dev preview
Source: https://shopify.dev/docs/apps/build/checkout/cart-checkout-validation/create-server-side-validation-function
Use the Shopify CLI `dev` command to start the dev preview. This command rebuilds your function on file changes and updates extension drafts for immediate testing.
```bash
cd ../..
shopify app dev
```
--------------------------------
### Reduce Latitude/Longitude Precision for Caching (Rust)
Source: https://shopify.dev/docs/apps/build/functions/network-access/performance-and-resilience
Adjusts latitude and longitude to three decimal places to increase cache hit rates for pickup point lookups. This example demonstrates making a GET request to an external API with reduced precision coordinates.
```rust
fn fetch(input: fetch::input::ResponseData) -> Result {
let delivery_address = &input.delivery_address;
if let (Some(latitude), Some(longitude)) = (&delivery_address.latitude, &delivery_address.longitude) {
let latitude_with_reduced_precision = format!( "{:.3}", latitude);
let longitude_with_reduced_precision = format!( "{:.3}", longitude);
return Ok(fetch::output::FunctionFetchResult {
request: Some(fetch::output::HttpRequest {
method: fetch::output::HttpRequestMethod::GET,
url: format!(
"https://api.pickuppoint.io/search?lat={}&lon={}",
latitude_with_reduced_precision,
longitude_with_reduced_precision
),
handlers: vec![],
body: None,
policy: fetch::output::HttpRequestPolicy {
read_timeout_ms: 500,
},
}),
});
}
Ok(fetch::output::FunctionFetchResult { request: None })
}
```
--------------------------------
### Reduce Latitude/Longitude Precision for Caching (JavaScript)
Source: https://shopify.dev/docs/apps/build/functions/network-access/performance-and-resilience
Adjusts latitude and longitude to three decimal places using `toFixed(3)` to increase cache hit rates for pickup point lookups. This example demonstrates making a GET request to an external API with reduced precision coordinates.
```javascript
export function fetch(input) {
let { latitude, longitude } = input.deliveryAddress;
if (latitude && longitude) {
let latitudeWithReducedPrecision = latitude.toFixed(3);
let longitudeWithReducedPrecision = longitude.toFixed(3);
return {
request: {
method: 'GET',
url: `https://api.pickuppoint.io/search?lat=${latitudeWithReducedPrecision}&lon=${longitudeWithReducedPrecision}`,
headers: [],
body: null,
policy: {
readTimeoutMs: 500,
},
},
};
}
return { request: null };
}
```
--------------------------------
### Create Product using REST Resource Class
Source: https://shopify.dev/docs/apps/build/graphql/migrate/libraries
Instantiate a new product using the resource class and a hash of properties. Use `save!` to create the product and raise an error if it fails.
```ruby
product_properties = {
title: "My new product"
}
product = ShopifyAPI::Product.new(from_hash: product_properties)
product.save!
```
--------------------------------
### Using REST Client to Create a Product
Source: https://shopify.dev/docs/apps/build/graphql/migrate/libraries
Demonstrates how to create a new product using the REST Admin client.
```APIDOC
## POST /products
### Description
Creates a new product in Shopify.
### Method
POST
### Endpoint
/products
### Request Body
- **product** (object) - Required - The product details.
- **title** (string) - Required - The title of the product.
### Request Example
```json
{
"product": {
"title": "My new product"
}
}
```
### Response
#### Success Response (200)
- **product** (object) - The created product details.
#### Response Example
```json
{
"product": {
"id": 12345,
"title": "My new product"
}
}
```
```
--------------------------------
### MetaobjectUpsertInput Example
Source: https://shopify.dev/docs/apps/build/metaobjects/standard-review-metaobject
An example of the input structure for the `MetaobjectUpsertInput` mutation. Note that this example is incomplete and requires all available and required fields to be supplied.
```json
{
"handle": {
"handle": "review-1",
"type": "product_review"
},
"input": {
"fields": [
{
"key": "rating",
"value": "{\"scale_min\":\"1\", \"scale_max\": \"5\", \"value\": \"4.0\"}"
}
]
}
}
```
--------------------------------
### Example Query for Shop and Products
Source: https://shopify.dev/docs/apps/build/graphql/basics/queries
This example demonstrates how to query for shop information, including its address, and a list of products. It illustrates the structure of a GraphQL query and its corresponding response.
```APIDOC
## QueryRoot
### Description
The `QueryRoot` object is the initial entry point for all queries in the GraphQL API. Everything that can be queried is defined as a field or connection on the `QueryRoot` object.
### Example Query
```graphql
{
shop {
name
primaryDomain {
url
}
products(first: 3) {
edges {
node {
title
handle
}
}
}
}
}
```
### Response Example
```json
{
"data": {
"shop": {
"name": "My Awesome Store",
"primaryDomain": {
"url": "https://my-awesome-store.myshopify.com"
},
"products": {
"edges": [
{
"node": {
"title": "Awesome T-Shirt",
"handle": "awesome-t-shirt"
}
},
{
"node": {
"title": "Cool Mug",
"handle": "cool-mug"
}
},
{
"node": {
"title": "Sticker Pack",
"handle": "sticker-pack"
}
}
]
}
}
}
}
```
```
--------------------------------
### Install Dependencies with npm
Source: https://shopify.dev/docs/apps/deployment/web
Installs project dependencies using npm ci for a clean and reproducible installation. This is a step before building the app for deployment.
```bash
npm ci
```