Actions

Actions allow you to trigger API requests, HTTP requests, send email, etc.

shopify.get(url: string)

Send GET request to Shopify API - View Docs

Example: Get all products
actions.shopify.get("/admin/api/2020-04/products.json")

shopify.post(url: string, object)

Send POST request to Shopify API - View Docs

Example: Add new product
actions.shopify.post("/admin/api/2020-04/products.json", {
    product: {
      title: "Burton Custom Freestyle 151",
      body_html: "Good snowboard!",
      vendor: "Burton",
      product_type: "Snowboard",
      tags: "Barnes & Noble, John's Fav, Big Air"
    }
  })

shopify.put(url: string, data: object)

Send PUT request to Shopify API - View Docs

Example: Change a product
actions.shopify.put("/admin/api/2020-04/products/632910392.json", {
  "product": {
    id: 632910392,
    published: true
  }
})

shopify.delete(url: string)

Send DELETE request to Shopify API - View Docs

Example: Delete product
actions.shopify.delete("/admin/api/2020-04/products/12345.json")

shopify.graphql(query: string)

Send GraphQL request to Shopify API - View Docs

Example: Query name of the shop
actions.shopify.graphql(`query { shop { name } }`)

shopify.tagCustomer(customerId: string, tag: string)

Shortcut for adding a tag to a customer.

Note: Counts as 2 actions, as the customer must be fetched before being tagged.

Example: Tag customer
actions.shopify.tagCustomer("12345", "tag d")

shopify.tagOrder(orderId: string, tag: string)

Shortcut for adding a tag to an order.

Note: Counts as 2 actions, as the order must be fetched before being tagged.

Example: Tag order
actions.shopify.tagOrder("12345", "tag d")

pg.query(connectionOptions: string | object, query: string, params?: []any)

Exposes the 'pg' library. The first argument is the connection string or object, but the following arguments conform to the libraries 'query' method.

For more, see the node-postgres documentation .

Example: Insering data into Postgres
return actions.pg.query(
  process.env.DATABASE_URL,
  'insert into test_orders (total) values ($1)',
  [ payload.total_price ]
)

http.get(url: string, config?: object)

Send a GET request to any URL.

For more, see the Axios docs .

Example: Get data via HTTP GET request
actions.http.get('http://my.api.com/thing/1')
  .then({ data }) => {
    console.log('do something with thing 1', data)
  })

http.post(url: string, data: any, config?: object)

Send a POST request to any URL.

For more, see the Axios docs .

Example: Post data via HTTP POST request
actions.http.post('http://my.api.com/things', { a: 1 })
  .then({ data }) => {
    console.log('created a thing: { a: 1 }')
  })

http.put(url: string, data: any, config?: object)

Send a PUT request to any URL.

For more, see the Axios docs .

Example: Put data via HTTP PUT request
actions.http.put('http://my.api.com/things/1', { a: 1 })
  .then({ data }) => {
    console.log('updated a thing with { a: 1 }')
  })

http.delete(url: string, config?: object)

Send a DELETE request to any URL.

For more, see the Axios docs .

Example: Delete an item via a HTTP DELETE request
actions.http.delete('http://my.api.com/things/1', { a: 1 })
  .then({ data }) => {
    console.log('deleted a thing with { a: 1 }')
  })

email.send(config: object)

Send an email with either HTML or plain text.

Example: Send a HTML email
actions.emails.send({
  to: '[email protected]',
  cc: [ '[email protected]', '[email protected]' ],
  subject: 'Just a note',
  body: `
    

Hi!

Let me know what you think about ${customer.email}.

` })
On this page