Specify a blank value in a custom PickList field via api - bigcommerce

How can I specify an empty value for a custom-field
https://developer.bigcommerce.com/api-reference/customer-subscribers/v3-customers-api/customer-form-fields/customerformfieldvalueput
PUT https://api.bigcommerce.com/stores/:store_id/v3/customers/form-field-values
[
{
"name": "MyCustomField",
"address_id": 395,
"value": ""
}
]
gives me this
{
"status": 422,
"title": "Create form field value failed.",
"type": "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes",
"errors": {
"0.form_field_value": "Option '' does not exist in 'MyCustomField'"
}
}
I have also tried
"value": null
with result
"errors": {
"0.data": "Missing form-field value for form-field 'MyCustomField'"
}
"value": undefined
with result
{
"status": 400,
"title": "Input is invalid",
"type": "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes",
"errors": {}
}

If the custom form field doesn't already exist on the store you're sending this call to, you'll see an error like "Form-field 'test' does not exist in the 'Customer' form". Once set to an existing field's name, I was able to successfully send a call like the one described here.
Are you also creating the custom form field programmatically? You might need to add logic so that this call is only run after the field is created.

Related

Shopify section schema: different content for each present block

I'm just starting out with Shopify development, and I'm creating a custom section called USP Banner which has a single block type called column that can be added up to 4 times; and that column just has one text and one richtext field within it. The content of each column is identical on every page, but the section can appear in different places depending on the page itself.
I've given the column default values for the text & richtext and added the 4 columns that will be used into the presets definition of the schema; however because it's just the same column x 4, each column has the same content 4 times. What I'm aiming for is that when you add the section to any page, it prefills each column with different content.
I read through the Shopify docs and all I found was some vague allusion to having a settings object within the block presets, but I can't find any examples of that anywhere. I also found an old SO answer stating that presets can't contain default content.
Is there an easy way to add default content to repeating blocks within a section?
Although it's not made clear in the official docs, you can set default values for repeated blocks in the presets; but whereas the settings when defining the blocks are arrays of objects, the settings within the preset blocks are objects where each pre-determined field value uses the field's unique ID as its key. For example, a typical section schema might look like:
{% schema %}
{
"name": "USP Banner",
"blocks": [
{
"type": "column",
"name": "Column",
"limit": 4,
"settings": [
{
"type": "text",
"id": "heading",
"label": "Heading",
},
{
"type": "richtext",
"id": "text",
"label": "Text",
}
]
}
],
"presets": [
{
"name": "USP Banner",
"blocks": [
{
"type": "column"
},
{
"type": "column"
}
]
}
]
}
{% endschema %}
...so to create preset values for each block, we simply add settings to the preset definition like so:
"presets": [
{
"name": "USP Banner",
"blocks": [
{
"type": "column",
"settings": {
"heading": "Remarkable Value",
"text": "<p>Never knowingly undersold</p>"
}
},
{
"type": "column",
"settings": {
"heading": "5-Year Warranty",
"text": "<p>We're that confident in our products</p>"
}
}
]
}
]
...where the key for each field (heading & text in this case) is the ID of the defined fields in the blocks section at the top of the schema.

Remove user selected item from the list in SAP conversational AI Chatbot

I am working on a chatbot project where I have to create a dynamic list option. There is a list of 15 Items (first step). When user selects one, selected item should be removed from the list. After that It will return to first step (list) and will display only 14 items. Where is the issue in step 3?
Step 1: I have created a "item_list" in the memory field of one skill.
[{"item": "product_1", "value": 5},{"item": "product_2", "value": 6},{"item": "product_3", "value": 4}]
Step 2: Choose custom list and enter the following script in the same skill.
{
"type": "list",
"delay": "",
"content": {
"elements": [
{{#eachJoin memory.item_list}}
{
"title": "{{this.item_list.item}}",
"subtitle": "{{this.item_list.value}}",
"imageUrl": "",
"status": "",
"statusState": "<''/none/information/error/success/warning>",
"description": "",
"buttons": [
{
"title": "{{this.item_list.item}}",
"value": "{{this.item_list.item}}",
"type": "postback"
}
]
}{{/eachJoin}}
]
}
}
Step 3: In another skill, set memory field where the user input is stored and set another memory "item_list" to match the user input within the array value to remove it from the item_list. For this, I have entered the following script. But there is some problem with that script. How can I remove the item from the array?
{{#inArray memory.item_list.title memory.user_input.raw}} "{{remove memory.item_list memory.user_input.raw}}" {{else}} "{{memory.lists}}"{{/inArray}}

How to extract the field from JSON object with QueryRecord

I have been struggling with this problem for a long time. I need to create a new JSON flowfile using QueryRecord by taking an array (field ref) from input JSON field refs and skip the object field as shown in example below:
Input JSON flowfile
{
"name": "name1",
"desc": "full1",
"refs": {
"ref": [
{
"source": "source1",
"url": "url1"
},
{
"source": "source2",
"url": "url2"
}
]
}
}
QueryRecord configuration
JSONTreeReader setup as Infer Schema and JSONRecordSetWriter
select name, description, (array[rpath(refs, '//ref[*]')]) as sources from flowfile
Output JSON (need)
{
"name": "name1",
"desc": "full1",
"references": [
{
"source": "source1",
"url": "url1"
},
{
"source": "source2",
"url": "url2"
}
]
}
But got error:
QueryRecord Failed to write MapRecord[{references=[Ljava.lang.Object;#27fd935f, description=full1, name=name1}] with schema ["name" : "STRING", "description" : "STRING", "references" : "ARRAY[STRING]"] as a JSON Object due to java.lang.ClassCastException: null
Try the following approach, in your case it shoud work:
1) Read your JSON field fully (I imitated it with GenerateFlowFile processor with your example)
2) Add EvaluateJsonPath processor which will put 2 header fileds (name, desc) into the attributes:
3) Add SplitJson processor which will split your JSON byt refs/ref/ groups (split by "$.refs.ref"):
4) Add ReplaceText processor which will add you header fields (name, desc) to the split lines (replace "[{]" value with "{"name":"${json.name}","desc":"${json.desc}","):
5) It`s done:
Full process in my demo case:
Hope this helps.
Solution!: use JoltTransformJSON to transform JSON by Jolt specification. About this specification.

How to get list of statements for a given Wikidata ID?

The only thing I managed to do is this link:
https://www.wikidata.org/w/api.php?action=wbgetentities&ids=Q568&format=jsonfm
But this produces lots of useless data. What I need is to get all the statements for the given item, but I can't see any of the statements in the query above.
here it will be:
{ "instance of" : "chemical element",
"element symbol" : "Li",
"atomic number" : 3,
"oxidation state" : 1,
"subclass of" : ["chemical element", "alkali metal"]
// etc...
}
Is there an API for this or must I scrape the web page?
The information you want is in your query, except it's hard to decode. For example, this:
"P246": [
{
"id": "q568$E47B8CE7-C91D-484A-9DA4-6153F132997D",
"mainsnak": {
"snaktype": "value",
"property": "P246",
"datatype": "string",
"datavalue": {
"value": "Li",
"type": "string"
}
},
"type": "statement",
"rank": "normal",
"references": …
}
]
means that the “element symbol” (property P246) is “Li”. So, you will need to read all the properties from your query and then find out the name for each of the properties you found.
To get just the statements, you could also use action=wbgetclaims, but it's in the same format as above.

JSON parsing using JSON.net

I am accessing the facebook api and using the json.net library (newtonsoft.json.net)
I declare a Jobject to parse the content and look for the specific elements and get their values. Everything works fine for the first few but then I get this unexplained nullexception error " (Object reference not set to an instance of an object)
Now I took a look at the declaration but cannot see how to change it. Any help appreciated:
Dim jobj as JObject = JObject.Parse(responseData)
message = jobj("message").tostring
The error occurs at the last line above.I check to see if message is null and then look for the next desired field as follows
catch exception..
dim jobj2 as JObject = JObject.parse(responseData)
description = jobj2("description").tostring
JSON responsedata:
{
"id": "5281959998_126883980715630",
"from": {
"name": "The New York Times",
"category": "Company",
"id": "5281959998"
},
"picture": "http://external.ak.fbcdn.net /safe_image.php?d=e207958ca7563bff0cdccf9631dfe488&w=
90&h=90&url=http\u00253A\u00252F\u00252Fgraphics8.nytimes.com\u00252Fimages\u00252F2011\u00252F02\u00252F04\u00252Fbusiness\u00252FMadoff\u00252FMadoff-thumbStandard.jpg",
"link": "http://nyti.ms/hirbn0",
"name": "JPMorgan Said to Have Doubted Madoff Long Before His Scheme Was Revealed",
"caption": "nyti.ms",
"description": "Newly unsealed court documents show that bank
executives were suspicious of Bernard Madoff\u2019s accounts
and steered clients away from him but did not alert regulators.",
"icon": "http://static.ak.fbcdn.net/rsrc.php/yD/r/aS8ecmYRys0.gif",
"type": "link",
"created_time": "2011-02-04T16:09:03+0000",
"updated_time": "2011-02-06T20:09:51+0000",
"likes": {
"data": [
{
"name": "Siege Ind.",
"category": "Product/service",
"id": "152646224787462"
},
{
"name": "Lindsey Souter",
"id": "100000466998283"
},
This is one example where "message" does not appear in the first few lines but appears later. So what I do is look for position of message and description and which ever is first go and get that and if I get an error or the fields do not return anything, I try and parse by regex and even that is not working right.
Well, presumably jobj("message") has returned Nothing, which will happen if jobj doesn't have a message property. If you think this is incorrect, please post a short but complete piece of JSON to help us investigate.
(Is there any reason why you're declaring message and assigning it a value on the second line, only to overwrite that value on the third line?)