Unable to add a single line items with modifiers using Clover POS REST API - rest

I am trying to add a single line item with modifiers using the Rest API. I see answers that it's not possible while adding bulk line items (the documentation for both suggests that this should be possible).
This is the request I am sending.
URL: https://sandbox.dev.clover.com/v3/merchants/MERCHANTID/orders/ORDERID/line_items
Request Type: POST
"item": {
"id":"9S1MXGERPQ7ER"
}
"modifications" : [{
"modifier" : {
"id" : "ZM8MV5X3M7R72",
"modifierGroup": {
"id" : "YC351CMAHF6AY"
}
},
"modifier" : {
"id" : "0X5A869PQT858",
"modifierGroup": {
"id" : "XZP32FHXQWKE6"
}
}
}]
The item gets created fine. but none of the modifiers are added.
I checked that creating a line item initially and then making an explicit call to the below URL to add modification works fine, but with this approach we can only add 1 modifier per call.
https://sandbox.dev.clover.com/v3/merchants/MERCHANTID/orders/ORDERID/line_items/LINEITEMID/modifications
Request:
{
"modifier" : {
"id" : "ZM8MV5X3M7R72"
}
}
With this approach we have to make multiple calls per line item based on number of modifiers selected.
Am I missing something here?

I have the same problem. you are missing the name and amount property of the modifier. These are required fields e.g
URL: https://sandbox.dev.clover.com/v3/merchants/MERCHANTID/orders/ORDERID/line_items
Request Type: POST
"item": {
"id":"9S1MXGERPQ7ER"
}
"modifications" : [{
"modifier" : {
"id" : "ZM8MV5X3M7R72",
"modifierGroup": {
"id" : "YC351CMAHF6AY"
},
},
"name": "yourModifierName",
"amount": "amountOfModifier"
}]

Related

Elastic Search Api issue while adding multiple fields to a tag

I am following the document
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html for adding a document and updating it.
The request for add is
PUT test/_doc/1
{
"counter" : 1,
"tags" : ["red"]
}
and the one for adding a new value to the tags list is like
POST test/_update/1
{
"script" : {
"source": "ctx._source.tags.add(params.tag)",
"lang": "painless",
"params" : {
"tag" : "blue"
}
}
}
which is working fine. now my issue is adding a list of values to the tag field , if I pass it like
"tag" : ["green","yellow"]
the entire list is getting added as a field. How can I avoid this ?
You simply need to adapt the script in order to handle both cases.
One way would be to use another parameter (e.g. tags) to add a list of values and keep tag for single values:
POST test/_update/1
{
"script" : {
"source": "def set = new HashSet(ctx._source.tags); if (params.tags != null) { set.addAll(params.tags) } else if (params.tag != null) { set.add(params.tag)} ctx._source.tags = new ArrayList(set);",
"lang": "painless",
"params" : {
"tags" : ["green", "yellow"]
}
}
}
If you don't want to add a new parameter, you can do it like this and test the nature of the tag value in order to run the correct operation:
POST test/_update/1
{
"script" : {
"source": "def set = new HashSet(ctx._source.tags); if (params.tag instanceof List) { set.addAll(params.tag) } else { set.add(params.tag) } ctx._source.tags = new ArrayList(set);",
"lang": "painless",
"params" : {
"tag" : ["green", "yellow"]
}
}
}

JOLT to index a field based on the name of another

Not sure if this is possible in jolt.
We are trying to extract a value whose field name is indexed by another field. Please take a look at the description below.
{
"_src" : {
"SomeName" : 123,
"FName" : "SomeName"
}
}
to
{
"val": "123",
"_src" : {
"SomeName" : 123,
"FName" : "SomeName"
}
}
Any ideas on how approach this, or if this is even possible in JOLT?
Thanks
Using shift spec:
Match on _src
Set value using SomeName
Using syntax #(1,src) which means go up 1 level and copy src, & will get the name of the current element.
[
{
"operation": "shift",
"spec": {
"_src": {
"SomeName": "val",
"#(1,_src)": "&"
}
}
}
]

MongoDB: Finding a value where object name contains url

We are using learninglocker and I am trying to query its mongodb. learninglocker puts escaped urls as object names, which makes them more difficult to search. I am returning 0 results when I would expect to return several.
My find is as follows:
{"statement.object.definition.extensions.http://activitystrea&46;ms/schema/1&46;0/device.device_type": "app"}
I assume that this should be escaped somehow, however, am unsure how.
http://activitystrea&46;ms/schema/1&46;0/device
Sample object:
"statement": {
"version" : "1.0.0",
"actor" : { },
"verb" : { },
"context" : { },
"object" : {
"definition" : {
"extensions" : {
"http://activitystrea&46;ms/schema/1&46;0/device" : {
"device_type" : "app"
}
}
}
}
}

Get Ember Data working with array of objects

I have a simple Ember Data app to list and show various objects.
My /servers.json API (for example) return this kind of format:
[
{
"hosted_domain" : "example.com",
"status" : 1,
"name" : "srv0443",
"id" : 443
},
{
"id" : 392,
"status" : 1,
"name" : "srv0392",
"hosted_domain" : "example.com"
},
{
"hosted_domain" : "example.com",
"id" : 419,
"name" : "srv0419",
"status" : 1
}
]
But I got the following error:
Assertion Failed: The response from a findAll must be an Array, not undefined
Ember Data expects this kind of format:
{
"servers" : [
{
"name" : "srv0443",
"status" : 1,
"id" : 443,
"hosted_domain" : "example.com"
},
{
"status" : 1,
"name" : "srv0392",
"id" : 392,
"hosted_domain" : "example.com"
},
{
"status" : 1,
"name" : "srv0419",
"hosted_domain" : "example.com",
"id" : 419
},
]
}
I know I can override the payload with the extractArray of the RESTSerializer.
It's works by doing payload = { servers: payload } but how get it working in a generic way?
How can I do to catch the needed key of an model type?
In a more general way, what is the good REST format, by convention?
Thanks.
Ember Data works by having the data follow a certain convention ({servers: payload}). So the data either needs to conform, or you have to extend the serializer as you mentioned (or some other customization like overriding the model's findAll() method). There isn't anyway around it, if you want to use Ember Data. Of course, you don't have to use Ember Data. Here is a good article about not using it: http://eviltrout.com/2013/03/23/ember-without-data.html
To customize the serializer you can extend it like this:
App.ServerSerializer = DS.RESTSerializer.extend({
extractArray: function(store, type, payload) {
this._super(store, type, {servers: payload});
},
});
Extract array is automatically called by ember after it gets a response from the server. This will put in the format ember data expects, then pass it on to continue processing as usual. But you will have to do that for each type of model. If you override App.ApplicationSerializer instead you might be able to use the type paramter to figure out which key should go in the modified payload, so it will work for any model, but I can't check it right now.
Finally found a solution by using primaryType.typeKey and ember-inflector tool on the RESTSerializer:
App.ApplicationSerializer = DS.RESTSerializer.extend
extractArray: (store, primaryType, payload) ->
# Payload reload with { type.pluralize: hash }
payloadKey = Ember.Inflector.inflector.pluralize primaryType.typeKey
payloadReloaded = []
payloadReloaded[payloadKey] = payload
#_super store, primaryType, payloadReloaded
In a nutshell:
Get the type key (e.g. server)
Pluralize it (e.g. servers)
Add it as payload master key (e.g. { servers: payload }
And that's it!
Please feel free to comment this solution if you have a better proposition.

Use two push-es in update command

Well the answer is probably no but I am curious to ask.
I have a Document which has two level of arrays in it:
{ '_id : '...' , events : [ urls : [], social_id : [] ], 'other_data' : '...' }
The code below works. What is does is update on a specific event the url array and adds to that set the event['event_url'] value (python).
db.col.update(
{ 'f_id' : venue['id'],
"events.title" : find_dict["events.title"] },
{ '$addToSet': { 'events.$.urls': event['event_url']} }
)
However in the same event I want to add a social id if not exists.
db.col.update(
{ 'f_id' : venue['id'],
"events.title" : find_dict["events.title"] },
{ '$addToSet': { 'events.$.social_id': event['social_id']} }
)
I was wandering if it's possible to merge the above commands into one and not run the update twice. I have not found anything in the documentation but I guess it's worth asking.
You can combine the two updates into a single operation by including both fields in the $addToSet object:
db.col.update(
{ 'f_id': venue['id'], "events.title": find_dict["events.title"] },
{ '$addToSet': {
'events.$.urls.': event['event_url'],
'events.$.social_id.': event['social_id']
}}
)