How to use OAuth to place an order

Shopify Partner
27 0 1

I want to place an order via the API. But would rather use OAuth2.

How to convert the code below to OAuth style? The code is based on:


Example with Username + password   - Shows how to use Username + password to post add a new product.


Example with OAuth2 - only shows web hooks - no details of how to place an order


Code - with Username + password

const dotenv = require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const crypto = require('crypto');
const cookie = require('cookie');
const nonce = require('nonce')();
const querystring = require('querystring');
const request = require('request-promise');


   const placeOrderRequestUrl = 'https://' + shop + '/admin/orders.json';
   const placeOrderPayload = {
     "order": {
       "line_items": [
       { "quantity": 1,
         "variant_id": 606602985481,
         "title": "EMILY SINGLET DRESS ",
         "price": "7.75",
         "product_id": 60511617033,
         "gift_card": false }
   }; , {  json: placeOrderPayload })
   .auth(apiUser , apiPassword, false)
   .then(function (response) {
        console.log("placeOrder succeeded with status %d", response.statusCode);
     .catch((error) => {
       console.log("placeOrder failed");       

How to convert this to OAuth style?


Shopify Staff
Shopify Staff
1369 56 202

Hey Eddy.

Not sure I understand what you mean when you say "oauth style". Oauth is used to acquire an online or offline access token. Once you have an access token, you include it in the header of your request as a value for `X-Shopify-Access-Token`.

After writing that I assume you are looking for an alternative to Basic authentication. In which case, the above applies. First get an access token, then make requests specifying X-Shopify-Access-Token in the header.

That's shown in the Node tutorial here:

      const shopRequestUrl = 'https://' + shop + '/admin/shop.json';
      const shopRequestHeaders = {
        'X-Shopify-Access-Token': accessToken,

      request.get(shopRequestUrl, { headers: shopRequestHeaders })
      .then((shopResponse) => {


1 Like
Shopify Partner
27 0 1

Thanks. Yes that is the answer. I missed it the first time through - all working now.