How to add script to the front side of the shopify app - shopify

As i am new to shopify app i created an app and installed over a store with script tag having read and write permission . How can i dynamically add the javascript to the front side of shopify app.

Use the Script Tag API to create the javascript you want to load dynamically.
# POST /admin/script_tags.json
{
"script_tag": {
"event": "onload",
"src": "https://djavaskripped.org/fancy.js"
}
}
Documentation: Link

When your App is installed in a Shop, the merchant usually gets two dialogs to confirm. One is if you are asking for a billing charge. The other is for the scopes access to their shop. Assuming they approve both, you will get an oAuth token allowing you to read/write ScriptTag endpoint.
So when you get that oAuth token, you save it along with the shop name, and that is finally when you can POST your script tag payload in the store.

Related

Shopify API Configuration

When we created a API, I figured that I need to configure a new Shopify like this
const Shopify = require('shopify-api-node');
const shopify = new Shopify({
shopName: 'your-shop-name',
apiKey: 'your-api-key',
});
Is there any way to get the Shopify "your-shop-name" programmatically? So If I installed the app on another one it won't need to change. Or is there any other way to configure the API on Shopify?
I primarily need to update the product description using Admin REST API.
In your store, where you want to change descriptions using API calls, use the Admin App section to issue yourself an API key pair. You can give that key pair permission to edit products. And you're done! You have the store name obviously, and you have your access token. Nothing to it!

Connect API to Shopify

I have searched for tons of threads here in Stack Overflow but I can't seem to find the fitting or direct answers.
So we would like to fetch products from API of external (outside Shopify) source then upload them to Shopify. Is there a way to do this without creating an app? This external source API provides already data in Shopify format.
Thanks!
In the Shopify store you wish to add these products to, you can create an access token with permission to create products. Using that token, you are free to make API calls to the Shopify store, with the data representing products, to create products in the Shopify store. Very simple pattern. Takes about 30 seconds of your time to create the access token in the Shopify store admin.
No you have to create APP for it.
As per latest updates from Shopify, you need to create "Custom App" atleast to get the Access Tokens and API keys, because Shopify has depreciated "Private apps" They work like Private apps, as those apps are specific to only one store, but these apps can give you all the needed permission to Create and Fetch Products.
You can create new apps from admin panel here: [YourStoreDomain]/admin/settings/apps/development
Documentations realated to it is: https://help.shopify.com/en/manual/apps/custom-apps
From Shopify: https://help.shopify.com/en/manual/apps/private-apps
Note Private apps are deprecated and can't be created as of January
2022. Ask your app developer to create a custom app. Like private apps, custom apps are built exclusively for your shop, but they don't
require open API access to your store or access to your Shopify admin.

Generating Google Pay Token without UI

We have a use-case where we need to authorize a payment using a native payment on the web but use two different merchants. We want the user to press pay with Google and go through the ui but access google pay api with two different merchants. paymentsClient.loadPaymentData(paymentDataRequest).then(function(paymentData){ // if using gateway tokenization, pass this token without modification paymentToken = paymentData.paymentMethodData.tokenizationData.token; }).catch(function(err){ // show error in developer console for debugging console.error(err); });
is it possible to get the callback from this api request without a user interaction for the second request.

how to access shopify Products via API without api-key and password?

i want to develop a chrome extension to see stats for any store which develop in shopify, can i access any store products without API-Key and Password in shopify?
No, you cant access products json without using api-key or permanent token of the store.
But still you want to access the product details you atleast needs the handler of the product.
Lets say your store is "abc.myshopify.com" and handler of your product is "xyz", then you can product json of xyz by HTTP GET call in following url
https://www.abc.myshopify.com/products/xyz.json
in general
https://www.[storename]/products/[product-handle].json
You could try using the Shopify StoreFront API.
It allows to get information of your shop from from your own website or custom app. Although it doesn't need a API Password, it needs a Api Key that doesn't need to be a secret.
The documentation says this (the first point is the important):
Using the Storefront API, you can:
Fetch data about a single product or a collection of products to
display on any website or device.
Create unique checkout experiences
with full control over the shopping cart.
Create new customers or
modify existing ones, including address information.
Allow customers
to select unique product options.
There is no way shopify will provide store details (product list) without api authentication.
For your requirement, I would suggest to create a shopify app which will sync all product details to your storage and you can access data from there.

how to link purchases to user records in another system?

sorry I posted this in the google group before I realized you had moved this type of question to stackoverflow
I'm developing a web app with an e-commerce component based on shopify as a white-labelled product for our clients. Our app allows our clients' customers to purchase a subscription to a product for use within the app. Each of our clients will have a separate shopify store. We have a web interface that allows our clients to create products and we use the shopify api to create the products in their store via an app. We have installed web hooks to receive notification of payments so that we can create the appropriate records in our system to allow the customer access to the product they purchased.
So far, the plan has been to provide a product list on our site with a 'Buy Now' button that adds the product to the store's cart and then direct the user to checkout using Shopify's checkout system. In the fulfillment web hook, we get the cart token so all we need to do to link the two systems is record the cart token temporarily in our customer database and then we can credit the right user with the purchase.
The problem that we are running in to is that there seems to be no way to link the cart / order / payment to the user that is actually logged in to our system. We are still under development so we are using test stores and the domain of the app is different from the domain of the store (and that may be the case in the production system too) and it is seemingly impossible to figure out how to link the two systems.
I have tried a couple of different approaches ...
1) use a form and post to the store's cart/add.js with a return_to=back
This seems successful in that the items are added to the cart and opening the cart in a new window takes them to the cart they added the item to, but there is no way to associate that cart with the user on our system since we can't access the cart token in a separate domain
2) use a proxy (our system is written in nodes) to post to the store's cart and intercept the cart token.
This also works in that an item is added to a cart and we can access the _session_id and cart cookies from the response, but I don't seem to be able to set those cookies in the browser. Going to the store's cart doesn't show the item just added and the store gets a different cart token.
Is there a different approach or should one of those work?
Should we be doing this entirely differently?
Cheers
Paul
Your best bet is to put something in cart attributes when the order is created and use that when you get the webhook to link the order to the other system. You could have a simple json endpoint on the other server to get back the currently logged in user, or have them enter some user is on the cart page and store them in the cart atributes. More on cart attributes http://wiki.shopify.com/Ask_customer_for_additional_information
To implement John's suggestion, I put the following into my cart.liquid file:
<script type="text/javascript">
(function($){
$(document).ready(function(){
$.ajax({
url: 'http://<server>/token',
dataType: 'jsonp',
success: function(data, status, xhr) {
$('#cartform').append('<input type="hidden" name="attributes[token]" value="'+data.token+'" />');
},
error: function(xhr, status, error) {
alert('Error');
}
});
});
})(jQuery);
</script>
My server runs on a different domain than the shop, so I'm using jsonp. The token is something I can use to uniquely identify a customer record in my database. I am using an attribute so that it doesn't conflict with our client's use of shopify's note feature if they want to use it themselves for something. I have not yet tested this with my web hook but I assume that I can make this work from here on.
I'm not completely satisfied with this as it requires that our clients put this into their templates in order for shopify to work with our system. I still think that there should be a way through the JSON /cart API to set the value of the note for a cart.