Setting product published date via Shopify API doesn't work properly - shopify

When I set the published_at to a furture date by using the following JSON via Shopify product update API (https://ashop.myshopify.com/admin/products/product_id.json PUT).
{
"product": {
"id": 632910392,
"published": false,
"published_at": "2015-01-01T00:00:00+11:00"
}
}
It returned 200 and the following JSON
{
"product": {
"body_html": "something",
"created_at": "2014-01-07T14:49:00+11:00",
"handle": "test-product",
"id": 206281997,
"product_type": "MERCHANDISE",
"published_at": "2015-01-01T00:00:00+11:00",
"published_scope": "",
},
/* some other JavaScript properties*/
}
Shopify accepted the published date but the product was still visible. Below is the screenshot of the product Visibility
But if I removed "published_at": "2015-01-01T00:00:00+11:00" from the request JSON, the product changed to hidden.
How can I set the published date via Shopify API? Is it possible a Shopify API's bug?
Thanks for you help.

I have found a solution by using private API. And I tested it. Use publish_on instead of published_at. please refer to Shopify forums http://ecommerce.shopify.com/c/shopify-apis-and-technology/t/setting-product-published-date-via-shopify-api-doesn-t-work-properly-173469

Related

Magento 2 Rest API Can't Remove Category ID's from product

I am working on a REST API call which will remove the category ID from a live product. The below code returns true but this has not updated in the back end or on the site.
I have followed the magento documentation for the update request and that works well, I tried doing the inverse of that with the delete request and following some examples online.
The below method is DELETE.
If someone can advise how this category can be removed then please advise.
{
"product": {
"sku": "MRO2222",
"status": "0",
"category_links": [
{
"position": 100,
"category_id": "8"
}
]
}
}
Unfortunately there doesn't seem to be a proper way through a delete request with Magento Rest API.
The way to go is to unset the categories of the product and update with the desired categories afterwards.
You can unset the categories with a PUT request to endpoint:
https://www.yoursite.com/rest/all/V1/products/your_product_sku (replace url and sku)
with payload:
{
"product":{
"extensionAttributes":{
"category_links":[
]
}
}
}

Invalid variant ID while creating checkout for Shopify

I am trying to create checkout url using Admin API with following params.
URL: https://shopy-test11.myshopify.com/admin/api/2020-10/checkouts.json
{
"checkout": {
"line_items": [
{
"variant_id": 37033347711169,"quantity": 2
}
]
}
}
Unfortunately its returning below error which is not properly documented anywhere that I could find.
{
"errors": {
"line_items": {
"0": {
"variant_id": [
{
"code": "invalid",
"message": "is invalid",
"options": {}
}
]
}
}
}
}
I also tried Shopify-api ruby gem and got same error. There are some similar issue online, but none answers why that issue is occurring and how to fix it. This is new app under development which will create custom checkout. There's only one sales channel which is "Online Store" and is enabled for all products. Any ideas how to fix this issue? Any help is appreciated.
You seem to be mixing up concepts here. The checkout API is only associated with the Storefront API, and has nothing to do with the Admin API.
So this URL: /admin/api/2020-10/checkouts.json seems to be impossible. There is no endpoint in the admin API for checkouts, whereas, Storefront API which does have checkouts, might be your proper URL. So try that:
/api/2020-10/checkouts.json
And if you have the correct token in your header, it will likely work.

How to know the Shopify username who triggered a webhook?

I have a product/update Shopify webhook. When the webhook event comes, I see the JSON payload but I don't get any clue about who updated the product. I need the username or email or whatever to identify the user who triggered the webhook. Is that even possible ? If yes, how ?
As per Shopify Documentation, product/update hook does not contain any information regarding the user who triggered the action. However, if it is extremely important for you to find out the user, a workaround is to use the Shopify Events API. As you already have the Product ID in the recieved webhook, you may issue another call to
GET /admin/products/#{product_id}/events.json
and in the response
{
"events": [
{
"id": 677313116,
"subject_id": 921728736,
"created_at": "2008-01-10T08:00:00-05:00",
"subject_type": "Product",
"verb": "create",
"arguments": [
"IPod Touch 8GB"
],
"body": null,
"message": "Product was created: IPod Touch 8GB.",
"author": "Shopify",
"description": "Product was created: IPod Touch 8GB.",
"path": "/admin/products/921728736"
}
]
}
you will have the author field. You may further filter the result using verb and created_at fields.
The supported events are
But I am also only able to get the created, published and unpublished events.

How to replace session with stateless rest apis?

So, I am trying to make a shopping cart web architecture on rest framework where I am struggling to use browser storages to use as an alternative to maintaining the state.
I tried the window.localStorage and window.sessionStorage() APIs but it failed in the case of the private browsing mode in Safari and Opera.
So can anyone help out in the figuring other methods by which I can maintain states in rest based architecture?
You don't need sessions to store application state. User resources.
On approach would be to model every shopping cart as a resource with a unique ID:
/shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
The client application in the browser would read this resource:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
It would add an item to the cart:
POST /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
{
"itemId": "1234",
"quantity": 1
}
It would list the contents of the shopping cart:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
[
{
"itemId": "1234",
"title": "Some nice item",
"quantity": 1,
"price", 12.34,
"priceTotal": 12.34
},
{
"itemId": "9876",
"title": "Some other nice item",
"quantity": 2,
"price", 0.99,
"priceTotal": 1.98
}
]
The web application would remove an item from the cart:
DELETE /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items/9876
I think you get the idea.

MailChimp API V2 Need Help Regarding Templates

I am using the REST based MailChimp API version 2.0. I am trying to create a campaign using the campaigns/create API method. I have a template that I designed using the built in designer. In the request I specify the template ID of this template when creating the campaign. Is there a way I can send html in the body of the template while creating the campaign using the API ?. I have tried the following code, it works however I am unable to put in my custom html in the template when creating the campaign
{
"apikey": "my_key",
"type": "regular",
"options": {
"list_id": "d1c5306a1f",
"subject": "Welcome",
"from_email": "my#email.com",
"from_name": "Fawad Rashid",
"to_name": "Subscriber",
"template_id": 94425,
"inline_css": true,
"generate_text": true
},
"content": {
"html": "example html",
"sections": {
"text": "test"
}
}
}
Kindly guide me in this regards