@agentlewis You can create a “public app” without listing it in the App Store. This is done from the Developer Portal (https://partners.shopify.com). It’s considered an “unlisted app”, but gives your store the functions like app proxy. With that said, it does take more effort to build the app and get it installed on your store.
@john12345 Using your private app credentials in a POST or GET url directly from your storefront is not a secure way to do it. If you do, anyone can inspect the code of your page and see clearly your username and password.
It’s my understanding that you need to have your app process the POST request (behind the scenes), then return the results to your storefront page.
@Busfox please correct me if this isn’t correct..
Example of POST on client/storefront page:
<!--partial code for POST request from storefront- this is not complete-->
fetch('https://www.yourstore.com/apps/createSomething', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token':'your-storefront-token'
},
body: JSON.stringify({ someData, customerURL }), })
.then(function (res) {
return res.text();
})
Then – in your app behind the scenes – you do your API calls with your username:password. This example is using GraphQL…
<!-- partial code in app to process POST from storefront (this is creating and fetching customer metafields) -->
const apiKey = "api key";
const apiSecret = "api secret";
const createSomething = (someData, customerURL) => {
const metafieldquery = `mutation customerUpdate($input: CustomerInput!) {
customerUpdate(input: $input) {
customer {
id
metafields (first:10, namespace:"mynamespace") {
edges {
node {
id
namespace
key
value
}
}
}
}
}
}`;
const input = {
"id": customerURL,
"metafields": {
"namespace": "mynamespace",
"key": "mykey",
"value": someData,
"valueType": "STRING"
}
};
const params = {
query: metafieldquery,
variables: { input }
}
const optionsMetafields = {
method: "post",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(params)
};
const url = 'https://' + apiKey + ':' + apiSecret + '@' + shopUrl + '/admin/api/2019-07/graphql.json'
console.log(url) //used to see if URL is correct
fetch(url, optionsMetafields)
.then(res => res.json())
.then(response => {
console.log(JSON.stringify(response, null, 4))
});
}
Hope this help…