How to update the template of a widget in BigCommerce - bigcommerce

I've built a widget using the content/widget-templates api endpoint using this data as the body in the request
{
"name": "Test Widget One",
"template": "<h1>Test Widget One</h1>",
"schema": [
{
"type": "tab",
"label": "Content",
"sections": []
}
]
}
What do I do if I want to edit that template? If I repost this request with a new template it will create a new widget with the same name. I've taken the provided template uuid and formed a request like so
{
"name": "Test Widget One",
"widget_configuration": {
"images": [
{
"image_url": "{{where-the-image-should-link-to}}",
"image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/91/309/thekinfolktablecover_1024x1024__80715.1456436719.jpg?c=2&imbypass=on"
},
{
"image_url": "{{where-the-image-should-link-to}}",
"image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/109/361/kinfolkessentialissue_1024x1024__22507.1456436715.jpg?c=2&imbypass=on"
},
{
"image_url": "{{where-the-image-should-link-to}}",
"image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/500x659/products/85/282/livingwithplants_grande__26452.1456436666.jpg?c=2&imbypass=on"
}
]
},
"widget_template": {
"uuid": "my-uuid",
"template": "<h1>This is an update to test widget One</h1>"
},
"widget_template_uuid": "my-uuid"
}
The response reports no errors, but no update is made to the actual template of the widget.
This is the response I get back: (I replaced the uuid's with just 'uuid' for the example's sake)
{
"data": {
"uuid": "uuid",
"name": "Test Widget One",
"widget_configuration": {
"images": [
{
"image_url": "{{where-the-image-should-link-to}}",
"image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/91/309/thekinfolktablecover_1024x1024__80715.1456436719.jpg?c=2&imbypass=on"
},
{
"image_url": "{{where-the-image-should-link-to}}",
"image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/1280x1280/products/109/361/kinfolkessentialissue_1024x1024__22507.1456436715.jpg?c=2&imbypass=on"
},
{
"image_url": "{{where-the-image-should-link-to}}",
"image_source": "https://cdn11.bigcommerce.com/s-n0i50vy/images/stencil/500x659/products/85/282/livingwithplants_grande__26452.1456436666.jpg?c=2&imbypass=on"
}
],
"_": {
"id": "id"
}
},
"widget_template": {
"uuid": "uuid",
"name": "Test Widget One",
"schema": [
{
"type": "tab",
"label": "Content",
"sections": []
}
],
"template": "<h1>Test Widget One</h1>",
"date_created": "2020-08-05T17:46:37.802Z",
"date_modified": "2020-08-05T17:46:37.818Z",
"kind": "custom",
"storefront_api_query": "",
"icon_name": "default",
"template_engine": "handlebars_v3",
"client_rerender": false,
"site_id": 1000,
"current_version_uuid": "uuid",
"channel_id": 1
},
"date_created": "2020-08-05T18:04:24.512Z",
"date_modified": "2020-08-05T18:04:24.512Z",
"description": "",
"storefront_api_query_params": {},
"site_id": 1000,
"version_uuid": "uuid",
"channel_id": 1
},
"meta": {}
}
What do I need to do to make an update to the template of a custom widget that has already been uploaded?

You can Delete or Update an existing template using the correct API call and HTTP "method".
For example you can do a HTTP DELETE or a PUT (POST is what you seem to be doing which is adding a new template). Ensure you set the correct uuid in the path below to update or delete it:
https://api.bigcommerce.com/stores/{{$$.env.store_hash}}/v3/content/widget-templates/:uuid

Related

How to create a new database on Notion API with the new "Status" property?

Notion API HTTP requests are not working when I add a new "Status" propoerty for a new database creation.
I've been trying for a while to figure out why, sending Notion a simple HTTP POST request with a "Status" breaks it.
If I just replace "Status" with a simple "Select" it works fine...
This is the code that I tried on my latest attempt:
{
"is_inline": true,
"parent": {
"type": "page_id",
"page_id": page_id
},
"icon": {
"type": "emoji",
"emoji": "🐟"
},
"title": [
{
"type": "text",
"text": {
"content": "Catches",
"link": null
}
}
],
"properties": {
"Name": {
"title": {}
},
"Status": {
"status": {
"options": [
{
"name": "Not started",
"color": "default"
},
{
"name": "25% Complete",
"color": "blue"
},
{
"name": "50% Complete",
"color": "blue"
},
{
"name": "75% Complete",
"color": "blue"
},
{
"name": "Done",
"color": "green"
},
{
"name": "Blocked",
"color": "red"
}
]
}
}
}
}
Status ref page on Notions docs: https://developers.notion.com/reference/property-object#status-configuration

Shopware 6 API / Product Listing / How to add available color variants for each product on the response

API Request
/store-api/product-listing/{categoryId}
I want each product in the API response to have available color variants. Because I want to show color variants on the product list page. But currently this data is not provided by the shopware 6 api.
I've tried to add this data by using associations but it didnt help.
Request Body
{
"includes": {
"product": ["id", "productNumber", "cover", "options"]
},
"associations": {
"options": {
"media": []
}
}
}
The request body looks to be correct. If the product is a variant then it should have content for options.
To verify try the following request body:
{
"limit": 1,
"includes": {
"product": ["id", "productNumber", "options"],
"property_group_option": ["name", "group"],
"property_group": ["name"]
},
"associations": {
"options": {
"associations": {
"group": []
}
}
},
"filters": [
{
"type": "not",
"operator": "and",
"queries": [
{
"type": "equals",
"field": "parentId",
"value": null
}
]
}
]
}
This should yield a single variant.
Response should look similar to this:
{
"entity": "product",
"total": 1,
"aggregations": [],
"page": 1,
"limit": 1,
"elements": [
{
"productNumber": "10042.1",
"options": [
{
"name": "linen",
"group": {
"name": "textile",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
},
{
"name": "35",
"group": {
"name": "size",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
},
{
"name": "chartreuse",
"group": {
"name": "shirt-color",
"apiAlias": "property_group"
},
"apiAlias": "property_group_option"
}
],
"id": "0002ea44c49c41ecb91c43e7e49e422d",
"apiAlias": "product"
}
],
"states": [],
"apiAlias": "dal_entity_search_result"
}

GA4 data api - (not set) in custom dimensions

We are currently using GA4 data API and faced the issue when custom dimensions returns value "(not set)".
We were using the following article to set custom dimension for the session count, but we still receiving "(not set)" values.
Example of request:
{
"dateRanges": [
{
"startDate": "2021-09-01",
"endDate": "2021-09-05"
}
],
"offset": 0,
"limit": 100,
"dimensionFilter": {
"filter": {
"fieldName": "eventName",
"stringFilter": {
"matchType": 1,
"value": "screen_view",
"caseSensitive": true
}
}
},
"dimensions": [
{
"name": "customUser:applicationID"
},
{
"name": "customEvent:ga_session_number"
},
{
"name": "dateHour"
},
{
"name": "platform"
},
{
"name": "sessionSource"
},
{
"name": "sessionMedium"
},
{
"name": "sessionCampaignName"
},
{
"name": "deviceCategory"
}
],
"metrics": [
{
"name": "userEngagementDuration"
}
]
}
Does anybody have any idea why it may happen?

Pass an already existing Model to next in Loopback

There is Project model
{
"name": "Project",
"plural": "Projects",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"title": {
"type": "string",
"required": true
},
"description": {
"type": "string"
},
"code": {
"type": "string"
},
"startDate": {
"type": "date",
"required": true
},
"endDate": {
"type": "date"
},
"value": {
"type": "number"
},
"infoEN": {
"type": "string"
},
"infoRU": {
"type": "string"
},
"infoAM": {
"type": "string"
},
"externalLinks": {
"type": [
"string"
]
}
},
"validations": [],
"relations": {
"industry": {
"type": "belongsTo",
"model": "Industry",
"foreignKey": "",
"options": {
"nestRemoting": true
}
},
"service": {
"type": "belongsTo",
"model": "Service",
"foreignKey": "",
"options": {
"nestRemoting": true
}
},
"tags": {
"type": "hasAndBelongsToMany",
"model": "Tag",
"foreignKey": "",
"options": {
"nestRemoting": true
}
}
},
"acls": [],
"methods": {}
}
And it hasAndBelongsToMany tags
here is Tag model
{
"name": "Tag",
"plural": "Tags",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
Now when the relation is created loopback api gives this api endpoint.
POST /Projects/{id}/tags
This creates a new tag into the tags collection and adds it to the project.
But what about adding an already existing tag to the project?
So I figured maybe I add before save hook to the Tag
Here I'll check if the tag exists and then pass the existing one for the relation.
Something like this.
tag.js
'use strict';
module.exports = function(Tag) {
Tag.observe('before save', function(ctx, next) {
console.log(ctx.instance);
Tag.find({name: ctx.instance.name})
next();
});
// Tag.validatesUniquenessOf('name', {message: 'name is not unique'});
};
#HaykSafaryan it just demo to show you how to use tag inside project
var app = require('../../server/server');
module.exports = function(project) {
var tag=app.models.tags
//afterremote it just demo. you can use any method
project.afterRemote('create', function(ctx, next) {
tag.find({name: ctx.instance.name},function(err,result)){
if(err) throw err;
next()
}
});
};
this is just example code to show you how to use update,create ,find ,upsertwithwhere etc. tag for validation you have to setup condition over here it will not take validation which you defined in tags models

Failed to execute 'send' on 'XMLHttpRequest' for only one url in Loopback

Strongloop/Loopback node.js server used with 'ng-admin' editor and sqlite db. I need to get count of entities:
var Httpreq = new XMLHttpRequest();
Httpreq.open('GET', yourUrl, false);
Httpreq.send(null);
return Httpreq.responseText;
where yourUrl is like http://localhost:3000/api/v1/entity/count.
All urls works except one of entity named 'Advertisement', I have angular.js:12783 Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load http://localhost:3000/api/v1/advertisement/count. This url works in API explorer.
Advertisement.json:
{
"name": "Advertisement",
"base": "EntityBase",
"plural": "Advertisement",
"options": {
"validateUpsert": true,
"sqlite3": {
"table": "advertisement"
}
},
"properties": {
"name": {
"type": "string",
"required": true
},
"category_id": {
"type": "number"
},
"due_date": {
"type": "string"
},
"from_date": {
"type": "string"
},
"phone": {
"type": "string"
},
"site": {
"type": "string"
}
},
"validations": [],
"relations": {
"category": {
"type": "belongsTo",
"model": "Category",
"foreignKey": "category_id"
},
"photos": {
"type": "hasMany",
"model": "Photo",
"foreignKey": "advertisement_id"
}
},
"acls": [],
"methods": {},
"mixins": {
"Timestamp": {},
"SoftDelete": {},
"GenderAge": {},
"Descripted": {}
}
}
Renamed entity to Commercial to fix this.