Shopify REST API: Unable to add a new product variant with new option type getting error "Option values provided for 1 unknown option(s)" - rest

when creating a product in Shopify via the REST API, adds a default option and variant like below
"options": [
{
"id": 9651869188247,
"product_id": 7644173172887,
"name": "Title",
"position": 1,
"values": [
"Default Title"
]
}
]
Variants:
{
"variants": [
{
"id": 42211487744151,
"product_id": 7644173172887,
"title": "Default Title",
"price": "1.00",
"sku": "",
"position": 1,
"inventory_policy": "deny",
"compare_at_price": null,
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2022-06-17T17:18:24+05:30",
"updated_at": "2022-06-17T17:18:24+05:30",
"taxable": true,
"barcode": null,
"grams": 0,
"image_id": null,
"weight": 0.0,
"weight_unit": "kg",
"inventory_item_id": 44310083534999,
"inventory_quantity": 0,
"old_inventory_quantity": 0,
"requires_shipping": true,
"admin_graphql_api_id": "gid://shopify/ProductVariant/42211487744151"
}
]
}
I want to update the existing Option and Variants of a product to show "Color" & "Size" as options and variants of them. For that I tried the Shopify Rest API but that still is raising the below error
request model:
{
"variant": {
"product_id": 7644173172887,
"option1": "red",
"option2": "small",
"price": "1.0",
"title": "S"
}
}
response :
{
"errors": {
"base": [
"Option values provided for 1 unknown option(s)"
]
}
}

You are not specifing what endpoint you're using but I can see that you're specifing the Product Id and that should not be the case. If you need to add a new variant this is the request you should do
POST https://yourstore.myshopify.com/admin/api/2022-04/products/7644173172887/variants.json
{"variant":{"option1":"Red", "option2" :"Small", "title": "Red", "price":"1.00"}}
You will also need to update the current "Default Title" variant (I suggest, if possible to create the product with a valid variant).
PUT https://yourstore.myshopify.com/admin/api/2022-04/variants/42211487744151.json
{"variant":{"id":42211487744151,"option1":"Red","option2" : "S", "price":"99.00", "title" : "Red"}}

Related

How to exclude some item when query with typeorm in Nestjs and Postgres

I want to build a query when i send username to server so i can exclude the record has the excludeUsers has the same username i sent.
Here is my data : `
"id": "f4830220-9912-4cbb-b685-edf4aaaf8fd5",
"createdAt": "2022-03-24T10:19:48.096Z",
"updatedAt": "2022-03-24T10:26:42.487Z",
"isDeleted": false,
"username": "vietphuongthoa98",
"link": "",
"type": "follow",
"current": 13456,
"target": 13556,
"totalPurchase": 100,
"purchasedPacks": [
{
"id": "fbb3079b-32c9-4c4b-a297-16741d1f5485",
"name": "Some packets",
"type": "follow",
"count": 2,
"price": 100,
"follows": 50,
"createdAt": "2022-03-23T07:18:22.898Z",
"isDeleted": false,
"updatedAt": "2022-03-23T09:49:30.192Z",
"description": "Some packages description.",
"originPrice": 0
}
],
"excludeUsers": [
{
"id": "9d8c25d2-8f03-46b3-92fa-b9489b943a56",
"deviceName": "iPhone 12 Pro Max",
"username": "hoaa.hanassii",
"platform": "ios",
"timeZone": 0,
"deviceAge": 21,
"subscribed": true,
"coins": 19600,
"subscriptionExpiration": "2022-04-27T00:00:00.000Z",
"isBlocked": false
}
]
Here is my query builder :
queryBuilder
.leftJoin('featured_user.excludeUsers', 'excludeUsers')
.andWhere('excludeUsers.username != :username', {
username: filter.username,
});
The actual query result is :
SELECT "featured_user"."id" AS "featured_user_id",
"featured_user"."tenant_id" AS "featured_user_tenant_id",
"featured_user"."created_at" AS "featured_user_created_at",
"featured_user"."updated_at" AS "featured_user_updated_at",
"featured_user"."is_deleted" AS "featured_user_is_deleted",
"featured_user"."username" AS "featured_user_username",
"featured_user"."link" AS "featured_user_link",
"featured_user"."type" AS "featured_user_type",
"featured_user"."current" AS "featured_user_current",
"featured_user"."target" AS "featured_user_target",
"featured_user"."total_purchase" AS "featured_user_total_purchase",
"featured_user"."purchased_packs" AS "featured_user_purchased_packs",
"featured_user"."user_id" AS "featured_user_user_id",
"excludeUsers"."username" AS "excludeUsers_username",
"excludeUsers"."id" AS "excludeUsers_id"
FROM "featured_users" "featured_user"
LEFT JOIN "featured_users_exclude_users_users" "featured_user_excludeUsers" ON "featured_user_excludeUsers"."featured_users_id"="featured_user"."id"
LEFT JOIN "users" "excludeUsers" ON "excludeUsers"."id"="featured_user_excludeUsers"."users_id"
WHERE "excludeUsers"."username" != $1 -- PARAMETERS: ["hoaa.hanassii"]
The problem is nothing response. Any ideal ? Thanks
can you add getMany() end of querybuilder and try
queryBuilder
.leftJoin('featured_user.excludeUsers', 'excludeUsers')
.andWhere('excludeUsers.username != :username', {
username: filter.username,
}).getMany()

How to get nested "Sequelize" data?

I have created a Sequelize ORM based PostgreSQL database. I have implemented some relation between product and reviews. And, each review has been posted by a user. So, when I am querying for a single product, I want the data with, product, reviews & inside review I want to see who posted as well means user.
{
"id": 1,
"name": "Rounded Neck T-Shirt",
"title": "some title",
"snippet": "some snippet od demin t shirt",
"details": "some details",
"moreInfo": "some moreInfo",
"size": "size will be in a seperate table this will be FK",
"stock": 452,
"askingPrice": 4299,
"offPrice": null,
"offer": null,
"ratings": null,
"images": null,
"pictureUrl": "https://loopinfosol.in/themeforest/ekka-html-v31/ekka-html/assets/images/product-image/6_2.jpg",
"purchaseCost": 4200,
"createdAt": "2022-02-14T10:59:55.999Z",
"updatedAt": "2022-02-14T11:07:12.916Z",
"categoryId": 1,
"userId": 1,
"reviews": [
{
"id": 1,
"rating": 5,
"comment": "Very nice product",
"createdAt": "2022-02-14T17:28:22.680Z",
"updatedAt": "2022-02-14T17:28:22.680Z",
"productId": 1,
"userId": 1
}
]
}
Here, "userId" is the foreign key for the registered user id. I want to see the user data inside "reviews" as well. How can I do that?
I get the above JSON data by querying the following code.
Product.findOne({
include: [Review],
where: { id: req.params.id },
})
If you already have an association definition like Review.belongsTo(User, ... then you simply need to indicate a nested include option with User model:
Product.findOne({
include: [{
model: Review,
include: [{
model: User
}]
}],
where: { id: req.params.id },
})

Updating Mongo DB collection field from object to array of objects

I had to change one of the fields of my collection in mongoDB from an object to array of objects containing a lot of data. New documents get inserted without any problem, but when attempted to get old data, it never maps to the original DTO correctly and runs into errors.
subject is the field that was changed in Students collection.
I was wondering is there any way to update all the records so they all have the same data type, without losing any data.
The old version of Student:
{
"_id": "5fb2ae251373a76ae58945df",
"isActive": true,
"details": {
"picture": "http://placehold.it/32x32",
"age": 17,
"eyeColor": "green",
"name": "Vasquez Sparks",
"gender": "male",
"email": "vasquezsparks#orbalix.com",
"phone": "+1 (962) 512-3196",
"address": "619 Emerald Street, Nutrioso, Georgia, 6576"
},
"subject":
{
"id": 0,
"name": "math",
"module": {
"name": "Advanced",
"semester": "second"
}
}
}
This needs to be updated to the new version like this:
{
"_id": "5fb2ae251373a76ae58945df",
"isActive": true,
"details": {
"picture": "http://placehold.it/32x32",
"age": 17,
"eyeColor": "green",
"name": "Vasquez Sparks",
"gender": "male",
"email": "vasquezsparks#orbalix.com",
"phone": "+1 (962) 512-3196",
"address": "619 Emerald Street, Nutrioso, Georgia, 6576"
},
"subject": [
{
"id": 0,
"name": "math",
"module": {
"name": "Advanced",
"semester": "second"
}
},
{
"id": 1,
"name": "history",
"module": {
"name": "Basic",
"semester": "first"
}
},
{
"id": 2,
"name": "English",
"module": {
"name": "Basic",
"semester": "second"
}
}
]
}
I understand there might be a way to rename old collection, create new and insert data based on old one in to new one. I was wondering for some direct way.
The goal is to turn subject into an array of 1 if it is not already an array, otherwise leave it alone. This will do the trick:
update args are (predicate, actions, options).
db.foo.update(
// Match only those docs where subject is an object (i.e. not turned into array):
{$expr: {$eq:[{$type:"$subject"},"object"]}},
// Actions: set subject to be an array containing $subject. You MUST use the pipeline version
// of the update actions to correctly substitute $subject in the expression!
[ {$set: {subject: ["$subject"] }} ],
// Do this for ALL matches, not just first:
{multi:true});
You can run this converter over and over because it will ignore converted docs.
If the goal is to convert and add some new subjects, preserving the first one, then we can set up the additional subjects and concatenate them into one array as follows:
var mmm = [ {id:8, name:"CORN"}, {id:9, name:"DOG"} ];
rc = db.foo.update({$expr: {$eq:[{$type:"$subject"},"object"]}},
[ {$set: {subject: {$concatArrays: [["$subject"], mmm]} }} ],
{multi:true});

How to use embedsMany in laravel to get all attributes? Only foreign key is returning

Hello Good Developers,
I am trying to implement embedsMany relationship of jenssegers/laravel-mongodb
I have two collections:
ProfileSection - {
"_id": "5c865ea4257db43fe4007331",
"general_name": "MY_PROFILE",
"type": "public",
"points": 100,
"status": 1,
"translated": [
{
"con_lang": "US-EN",
"country_code": "US",
"language": "EN",
"text": "My Profile",
"description": "My Profile"
},
...
],
"updated_at": "2019-03-11T13:12:04.000Z",
"created_at": "2019-03-11T13:12:04.000Z"
}
Profile Questions - {
"_id": "5c865ea3257db43fe40072b2",
"id": "STANDARD_EDUCATION",
"general_name": "STANDARD_EDUCATION",
"country_code": "US",
"order": 1,
"profile_section_id": "5c865ea4257db43fe4007331",
"profile_section": "My Profile",
"translated": [
{
"con_lang": "US-EN",
"text": "What is the highest level of education you have completed?",
"hint": null,
"mapping": {},
"answers": [
{
"precode": "1",
"text": "3rd Grade or less",
"mapping": {}
}
]
},
{...}
],
"updated_at": "2019-03-11T13:12:03.000Z",
"created_at": "2019-03-11T13:12:03.000Z"
}
In ProfileSection I have added
public function questions()
{
return $this->embedsMany(ProfilerQuestions::class, '_id', 'profile_section_id');
}
If I execute ProfileSection::find('5c865ea4257db43fe4007331')->questions
It returns me Profile Questions Object with only one attribute: 5c865ea4257db43fe4007331 i.e ObjectId of Profile Section
I tried using ->with('questions) before accessing questions object
like this
but it's not working
I don't understand what's the issue will definitely need some help.

Trying to figure out how tax lines work when creating Shopify order via API

I am posting the following to the Shopify API create order endpoint and receiving a response without tax lines that are filled. I haven't seen anything on the internet on this, other than that Shopify doesn't offer another endpoint for just taxes. So, I am trying to figure out if tax lines are supposed to be generated automatically in the order response when creating an order via the API or if I have to include the tax lines in the request in order for tax lines to be included, because I know when I create an order in the admin the tax lines are automatically calculated and included for me?:
{
"order": {
"email": "some#email.com",
"financial_status": "paid",
"fulfillment_status": null,
"send_receipt": true,
"send_fulfillment_receipt": true,
"note": "Created by somename",
"line_items": [
{
"variant_id": 21718275463,
"quantity": 1,
"price": 99,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717700871,
"quantity": 1,
"price": 1000,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717690055,
"quantity": 1,
"price": 555,
"requires_shipping": true,
"product_id": 6821668807
}
],
"processing_method": "offsite",
"shipping_address": {
"first_name": "Chris",
"address1": "10101 Musick Road",
"phone": "9999999999",
"city": "St. Louis",
"zip": "63123",
"province": "MO",
"country": "United States",
"last_name": "Becker",
"name": "Chris Becker",
"country_code": "US",
"province_code": "MO"
},
"source_name": "somename",
"taxes_included": false,
"shipping_lines": [
{
"title": "standard",
"price": 0.00,
"code": null,
"source": "brand owner on shopify",
"carrier_identifier": null,
"tax_lines": null
}
],
"tags": "some Order"
}
}
Here is a useful documentation about tax: https://help.shopify.com/api/reference/location
Tax are not automatically calculated from cart.js ajax api. They just give a clue whether tax is already included in the price or not. If not, then it can be added with the bill.