PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 26, 2022

[FIXED] How to make API request in a Shopify private APP

 July 26, 2022     javascript, node.js, shopify-api, shopify-api-node, shopify-app     No comments   

Issue

So I'm developing a private app in Shopify using node.js and react, so far it's just a form that submits new products to the store, pretty simple, the thing that I have realized is that the Admin API from Shopify won't let me make request as a private app, or so thats what I understand from it, apparently the solution has to do with setting up a back-end server, which I'm at a loss because I quickstarted the app with the Shopify CLI and sets up a ngrok tunnel server for you, I'm unsure if I would need to set up another one or what to do next. its scaffolded with this process: https://shopify.dev/apps/getting-started/create

This article describes the perfect solution but they don't go into details about it so that's why I'm comming here:https://metafieldsmanager.thebestagency.com/articles/how-to-build-a-private-app

Code:

AddProductForm.js

let headers = {'X-Shopify-Access-Token': 'access token',
'host': 'store-example.myshopify.com', 
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}

let baseUrl = 'https://store-example.myshopify.com/admin/api/2021-07/'

Right now I'm just attempting a simple fetch request.


let handleSubmit = () => {  
        let toAdd = {
            product:{
                title: title,
                body_html: bodyHtml,
                vendor: vendor,
            }

        }
        console.log(baseUrl + 'products.json')
        fetch(baseUrl + 'products.json', {  
            headers:  headers
        }).then(res=>console.log(res))

I've omitted the rest of the code to keep it simple but its pretty much basic JSX and form handling.


Solution

After a while of dealing with Shopify apps, you DO need another server that has some https configuration or tunnel it with Ngrok, that server needs to call Shopify api instead of your front-end and then the app that the Shopify CLI scaffolds for you has to call that server.



Answered By - Santiago
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing