I am trying to create Products on Shopify using the API,
In the CSV upload there is a field Variant SKU which sets the (default) product SKU, I can't seem to find the correct way to create a product along with this value?
I tried (python3);
import requests
import json
from config import SHOPIFY_URL
payload = {
'product': {
'title': 'Hello Product',
'variants': {
'option1': 'Primary',
'sku': 'hello-product'
}
}
}
requests.post(
f'{SHOPIFY_URL}/products.json',
headers = {'content-type': 'application/json'},
data=json.dumps(payload)
)
The product get created but the SKU doesn't.
The TL;DR of my question;
What to I need to pass to fill the Product CSV Upload file's field Variant SKU?
Update
Thanks to David Lazar's comments, I realized that I need to use a list of variants.
payload = {
'product': {
'title': 'Hello Product',
'variants': [
{
'option1': 'Primary',
'sku': 'hello-product'
}
]
}
}
This however creates the product with one variant using the passed SKU.However what I am looking is to create the Porduct with its own SKU, no variations for the product, just a SKU for the product.
Related
There are several items in the cart with the same variant id, but different properties and discounts. I noticed that when I make a post request using the lineitem keys to the cart/update.js endpoint, it is not updating the correct line item. It's just updating the first item that has the variant id..
Any reason why this could happen?
For example, there are multiple lineitems with the variant id "40072319336547".
When I run this
jQuery.post(window.Shopify.routes.root + 'cart/update.js', "updates[40072319336547:62a477719b1f798b23f1ce16199c1668]=3" );
It's not updating the line item with key "40072319336547:62a477719b1f798b23f1ce16199c1668". Just some other lineitem with the variant id 40072319336547.
In that case (multiple lines with same variant id in the cart) is better to use change.js instead of update.js: https://shopify.dev/api/ajax/reference/cart#post-locale-cart-change-js
I'm doing like this:
$.ajax({
type: "post", url: "/cart/change.js", data: [
{"quantity": 2, "line": 0},
{"quantity": 4, "line": 1},
], dataType: 'json'
});
You see that I don't use the variantId but I'm using the line index. The downside of this approach is that if you need to apply a change to all the same variant ids you need to know which lines have to be changed. But that can be done reading the respone from cart.js
I am using Karate version 0.8.0.1 and I want to perform following steps to test some responses.
I make a Get to web service 1
find the value for currencies from the response of web service 1 using jsonpath: $.currencies
Step 2 gives me following result: ["USD","HKD","SGD","INR","GBP"]
Now I use Get method for web service 2
From the response of web service 2 I want to get the value of price field with json-path something like below(passing the values from step 3 above):
$.holding[?(#.currency=='USD')].price
$.holding[?(#.currency=='HKD')].price
$.holding[?(#.currency=='SGD')].price
$.holding[?(#.currency=='INR')].price
$.holding[?(#.currency=='GBP')].price
So there are so many currencies but I want to verify price for only the currencies returned by web service 1(which will be always random) and pass it on to the the output of web service 2 to get the price.
Once i get the price I will match each price value with the value returned from DB.
I am not sure if there is any simple way in which I can pass the values returned by service 1 into the json-path of service 2 one by one and get the results required. Any suggestions for doing this will be helpful As this will be the case for most of the web services I will be automating.
There are multiple ways to do this in Karate. The below should give you a few pointers. Note how there is a magic variable _$ when you use match each. And since you can reference any other JSON in scope, you have some very powerful options.
* def expected = { HKD: 1, INR: 2, USD: 3}
* def response1 = ['USD', 'HKD', 'INR']
* def response2 = [{ currency: 'INR', price: 2 }, { currency: 'USD', price: 3 }, { currency: 'HKD', price: 1 }]
* match response2[*].currency contains only response1
* match each response2 contains { price: '#(expected[_$.currency])' }
You probably already have seen how you can call a second feature file in a loop which may be needed for your particular use case. One more piece of the puzzle may be this - it is very easy to transform any JSON array into the form Karate expects for calling a feature file in a loop:
* def response = ['USD', 'HKD', 'INR']
* def data = karate.map(response, function(x){ return { code: x } })
* match data == [{code: 'USD'}, {code: 'HKD'}, {code: 'INR'}]
EDIT - there is a short-cut to convert an array of primitives to an array of objects now: https://stackoverflow.com/a/58985917/143475
Also see this answer: https://stackoverflow.com/a/52845718/143475
I'm trying to create a refund using Shopify API with the details in the documentation here:
and this is the payload I'm sending:
{ currency: 'GBP',
notify: false,
refund_line_items:
[ { line_item_id: '<line-item-id>',
quantity: 1,
restock_type: 'no_restock' } ] }
But I get this error:
StatusCodeError: 422 - {"errors":{"refund_line_items.line_item":["can't be blank"]}}
But refund_line_items.line_item is not mentioned in the documentation. I have checked the and the line_item_id is correct (is the ID of the variation ID, not the product ID, but I have tried using SKU and product ID, same result)
Other response in SO infers that this is because the line_item_id is incorrect but that's not the case. Any suggestions would be much appreciated. Thanks!
I am working on React Native Razorpay payment gateway integration.
I am using react-native-razorpay.
Code is below:-
Send Params are:-
var options = {
description: "Credits towards consultation",
image: "https://i.imgur.com/3g7nmJC.png",
currency: "INR",
key: "a-----b----ccc-dd",
amount: Math.round(Number(order_total).toFixed(2) * 100),
name: "Product",
prefill: {
email: email ? email : "v#razorpay.com",
contact: mobile ? mobile : "1111111111",
name:
firstname && lastname
? `${firstname} ${lastname}`
: "Razorpay Software"
},
theme: { color: theme.colors.primaryColor },
payment_capture: 1
};
Checkout Method:-
RazorpayCheckout.open(options)
.then(data => {
// handle success
console.log("payment success", data);
if (data && data.razorpay_payment_id) {
orderData.payment = data.razorpay_payment_id;
this.props.payMyOrder(orderData);
}
})
.catch(error => {
// handle failure
this.toast.show(error.description);
});
I am getting only razorpay_payment_id in response but, razorpay_payment_id and razorpay_signature are missing. Also, in Razorpay backend Razorpay Order Id and Order Id are missing.
hey as we can see in the above code options object that you are passing to the checkout you are not passing the order_id, you should pass the order_id as well. Since you are not passing the order_id the same is not getting returned to you after the payment is done. refer to the below link on how to create an order at your server-side.
https://razorpay.com/docs/api/orders/
if you pass the order_id in the request param to the checkout you'll get the order_id and signature as well in the payment response.
Please check the documentation we need to pass the order_id, here.
As per the documentation, once you pass the order_id, then only after payment successful razorpay returns the
razorpay_order_id,razorpay_payment_id and razorpay_signature.
After that you can compare the signature to get acknowledgement of payment success.
Just a note if your id is wrong your razorpaySignature too will not appear
Issue mostly will be because of invalid order Id, the order id received from Backend should be the one backend got from Razorpay.
Something like below should be used at your backend to generate order id (format of order id will be order_<some id>). You can get language based backend implementation at this link
var instance = new Razorpay({ key_id: 'YOUR_KEY_ID', key_secret: 'YOUR_SECRET' })
instance.orders.create({
amount: 50000,
currency: "INR",
receipt: "receipt#1",
notes: {
key1: "value3",
key2: "value2"
}
})
hello every one i am new in big commerce.
Now i am updating single page checkout using checkout sdk. every thing work fine till now i am following git hub implementing instructions . But the the problem is after update customer shipping address need to select the shipping option for shipping. I am using this syntax for doing this
const saddress = {
address1: $('#shippingaddress').val(),
address2: "",
city: $('#shippingcity').val(),
company: "",
country: $('#shippingcountry').val(),
countryCode: "AU",
customFields: [],
email: $('#email').val(),
firstName: $('#shippingfname').val(),
lastName:$('#shippinglname').val(),
phone: $('#shippingphone').val(),
postalCode: $('#shippingzip').val(),
stateOrProvince: $('#shippingProvince').val(),
stateOrProvinceCode: $('#shippingProvince').val(),
};
const updateaddress = await
service.updateShippingAddress(saddress);
After complete this action the function return all shipping address details along with the ID column and shipping options available in this address. but the problem is that function return the options and also the shipping address details but no ID column found in that list. that's why i am sending the billing address ID for select shipping option this is my code
const newState = await service.selectShippingOption(billing_ID, Shippingoption_ID);
after that i am going to direct payment options my code is
const payment = await service.loadPaymentMethods();
let paymentmethod=payment.data.getPaymentMethods();
in this function i am getting all the payment options details then i go for payment my code is
wait service.initializePayment({ methodId: 'testgateway' });
const payment = {
methodId: 'testgateway',
paymentData: {
ccExpiry: { month: 10, year: 20 },
ccName: 'BigCommerce',
ccNumber: '4111111111111111',
ccType: 'visa',
ccCvv: 123,
},
};
After complete this function this function return a error
Error: "Your order is missing a shipping method. Please return to the
shopping cart and checkout again."