question

jp1358 avatar image
jp1358 asked Warwick Price commented

Need direction to setup nodejs with clovers api

Hi, I need direction to setup nodejs with clovers api. I want to get order amounts by searching a order id. I don't have a developer account since I am not trying to make an app. I just want the simple function to get an order amount by searching a order id through the api. It seems the clover docs only cover developers making apps. I tryed using passport but I dont know what to put into the authorization url since I dont have a client id only a merchant id. I also dont know what to put into the tokenURL im guessing I can get req.header for the AUTHORIZATION_CODE?

const express = require('express') 
const app = express()
const passport = require('passport')
const OAuth2Strategy = require('passport-oauth2').Strategy; 

passport.use(new OAuth2Strategy({ 
authorizationURL: 'https://www.clover.com/oauth/authorize?client_id={appId}&redirect_uri={CLIENT_REDIRECT_URL}', 
tokenURL: 'https://www.example.com/oauth_callback?merchant_id={mId}&employee_id={employeeId}&client_id={appId}&code={AUTHORIZATION_CODE}', 
clientID: EXAMPLE_CLIENT_ID, 
clientSecret: EXAMPLE_CLIENT_SECRET, 
callbackURL: "http://localhost:3000/success" }, function(accessToken, refreshToken, profile, cb) { User.findOrCreate({ exampleId: profile.id }, function (err, user) { return cb(err, user); }); } )); 

app.get('/auth/example', passport.authenticate('oauth2')); 

app.get('/auth/example/callback', passport.authenticate('oauth2', { failureRedirect: '/login' }), function(req, res) { // Successful authentication, redirect home. res.redirect('/'); });
REST API
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered

Are you a Clover merchant trying to access your own data? If not, then, you need a Clover app in order to integrate. Why? Because the app is how merchants give you access to their data. https://docs.clover.com/docs/clover-development-basics-web-app#web-app

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jp1358 avatar image
jp1358 answered Warwick Price commented

Yes I am an existing merchant with one years worth of data, I don’t plan on making any apps I just want to access my data.

4 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image David Marginian ♦♦ commented ·

Ok, in that case you can use a Merchant Token, you don't need to go through the OAuth flow (so you don't need passport). You can create a merchant token from your merchant dashboard via Setup -> API Tokens and make API calls directly - https://docs.clover.com/reference, see more about using the API here - https://docs.clover.com/docs/making-rest-api-calls (all subsections).

0 Likes 0 ·
jp1358 avatar image jp1358 David Marginian ♦♦ commented ·

I keep getting a server response of { message: '401 Unauthorized' } using node-fetch.

const express = require('express')
const fetch = require('node-fetch')
const app = express()

const options = {
  headers: {
      'accept': 'application/json',
      'authorization': `Bearer ${my_auth_token}`
  }
};


fetch(`https://api.clover.com/v3/merchants/{my_mid}`, options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
0 Likes 0 ·
jp1358 avatar image jp1358 jp1358 commented ·
AHH yes I got it, I was putting a different mid that was only 12 digits long, I carefully read that the right mid is 13 characters long. Thanks!
0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community