How to update multiple contacts using xero-node library - node.js

I'm using xero-node npm package & looks like it will save me a ton of time.
I want to create OR update multiple contacts but not sure how. I'm hoping someone from Xero monitors this tag.
var contacts = [];
var contact = { "Name": "ABC", ContactNumber:"code123"};
contacts.push(xeroClient.core.contacts.newContact(contact));
const retVal = await xeroClient.core.contacts.saveContacts(contacts);
If I run it once , it creates the contact ( or multiple if I add to the array ) . I want to update the contact using my code ( not the xero generated id - because then I would need to store that it my other system).
If I run it a second time , it fails. I assume that is because it is doing a PUT instead of a POST..?
Here are the docs.
https://github.com/XeroAPI/xero-node/blob/2a1ec34888e998cabd72aa79fa58a5b14f2c9cd5/docs/Contacts.md

You are correct.
Here are the docs on Contacts:
https://developer.xero.com/documentation/api/contacts
See this section:
PUT Contacts
Use this method to create one or more contact records. This method works very similar to POST Contacts but if an existing contact matches your ContactName or ContactNumber then you will receive an error.
ContactNumber is unique. So you're trying to create two contacts with the same ContactNumber.
I think saving the contact like in the example here would help: https://github.com/XeroAPI/xero-node/blob/2a1ec34888e998cabd72aa79fa58a5b14f2c9cd5/docs/Contacts.md

Related

SAP COMMERCE How to search multiple product codes using SolrSearchQueryTemplate?

Need to search multiple product codes using using SolrSearchQueryTemplate so that we can get all products in a single solr call
I am able to search one product code at a time using SolrSearchQueryTemplate but not sure how shall modify solr query so that i can pass multiple product codes in solr request
please find below implementation i have done to search single product code using SolrSearchQueryTemplate and it works fine
$productType=testProductType
$ftsQueryBuilder=multiFieldFreeTextQueryBuilder
INSERT_UPDATE SolrSearchQueryTemplate;name[unique=true];ftsQueryBuilder[default=$ftsQueryBuilder];showFacets;restrictFieldsInResponse;indexedType(Identifier)[default=$productType]
;TESTTEMPLATE;;false;true;
INSERT_UPDATE SolrSearchQueryProperty;ftsQuery;indexedProperty(name)[unique=true];searchQueryTemplate(name)[unique=true]
;true;code;TESTTEMPLATE
final PageableData pageableData = createPageableData(0, getSearchPageSize(), null, ShowMode.Page);
final SearchStateData searchState = new SearchStateData();
final SearchQueryData searchQueryData = new SearchQueryData();
searchQueryData.setValue(XSSFilterUtil.filter(prodIdentifier.get(0)));
searchQueryData.setSearchQueryContext(SearchQueryContext.THIRDPARTYINTEGRATION);
searchState.setQuery(searchQueryData);
pageableData.setFlow(MyConstants.THIRDPARTYINTEGRATION);
final ProductSearchPageData<SearchStateData, de.hybris.platform.commercefacades.product.data.ProductData> searchPageData = testCloudProductSearchFacade
.getProductByCodeMafIdBrand(searchState, pageableData, MyConstants.THIRDPARTYINTEGRATION);
List<ProductData> prodFromSolr = searchPageData.getResults();
let me know what modifications are required to be done in this so that i can pass multiple product codes in request
Note:
searchQueryData.setValue(XSSFilterUtil.filter(prodIdentifier.get(0)));
setValue method accepts single parameter of type String
is it possible to send multiple codes separated by some token which SolrSearchQueryTemplate will automatically consider as multiple search terms

Mongo function to find if superstring exists in array. Nodejs,

A document in my mongo 'companies' collection looks like this:
{
"companyName": "",
"companyIcon": "",
"domains": [
"companyDomainA.com",
"companyDomainB.dev"
],
"allowSubDomains": true
}
In my application the user enters his/her email address.
Using the Nodejs native mongo driver (https://mongodb.github.io/node-mongodb-native), I want to query (find) which company the user belongs to.
The problem is when the user enters the email as name#dept.companyDomainA.com.
I want to be able to query and find the company document of the user based on his email (subdomained 0 or more levels), ie. if the superstring of a string exists in an array in mongo.
(Caveat, I cannot store all the subdomains of the company as they are dynamic and can change at will)
Is there a regular expression way/db schema change way, to achieve this?
Thanks in advance!!
I would do it like this. First find the root domain from the email address. To do that I would split the email and fetch the domain first.
const email = "name#dept.companyDomainA.com";
const domain = email.split('#')[1]; // dept.companyDomainA.com
Now fetch the host (companyDomainA.com) from it. Follow this link.
So, I have found the root domain which is companyDomainA.com. Now run the find query.
db.collection('documents').find({"domains": "companyDomainA.com"});
I didn't test this code.

Srapi - retrieve 1-n property from the Lifecycle call back model parameter

i am using Strapi for a prototype and i am meeting the following issue. I have created a new content type "Checklist" and i added in it a relation property 1 to many with the User model provided by the users-permissions plugin.
Then i wanted to add some custom logic on the lifecycle call back, in beforeSave and in beforeUpdate from which i would like to access the user assigned to the Checklist.
The code looks like that:
{
var self = module.exports = {
// Before saving a value.
// Fired before an `insert` or `update` query.
generateLabel : (model) => {
var label = "";
var day = _moment(model.date,_moment.ISO_8601).year();
var month = _moment(model.date,_moment.ISO_8601).day();
var year = _moment(model.date,_moment.ISO_8601).month();
console.log(model);
if (model.user) {
label = `${model.user}-${year}-${month}-${day}`;
}else{
label = `unassigned-${year}-${month}-${day}`;
}
return label;
I call the method generateLabel from the callback. It works, but my model.user always returned undefined. It is a 1-n property. I can access model.date property (one of the field i have created) without any issue, so i guess the pbs is related to something i have to do to populate the user relation, but i am not sure on how to proceed.
When i log the model object, the console display what i guess is a complete mongoose object but i am not sure where to go from there as if i try to access the property that i see in the console, i will always reach an undefined.
Thanks in advance for your time, i use the following
strapi: 3.0.0-alpha.13.0.1
nodejs: v9.10.1
mongodb: 3.6.3
macos high sierra
Also running into the similar / same issue, I think this has to do with the user permissions plugin, and having to use that to access the User model. Or I thought about trying to find the User that’s associated with the id of the newly created record. I’m trying to use AfterCreate. Anyone that could shed some light on this would be great!
It's because relational attributes are not send in create fonction (See your checklist service add function).
Relations are handled in an other function updateRelations.
The thing you can do is to send values in Checklit.create()

infusionsoft contact field query with python

I know how to connect to Infusionsoft with Python 3 and how to process the following simple example:
#Set up the contact data we want to add
contact = {}; #blank dictionary
contact[“FirstName”] = “John”;
contact[“LastName”] = “Doe”;
contact[“Email”] = "john#doe.com";
contact[“Company”] = “ACME”;
But how do I mass update the WHOLE database? e.g. If I want to update ALL The Phone1 fields with an extra bit of code using IF statements.
Using Infusionsoft API you can only update contacts data one by one, sending a separate request per contact. Exact request depends on which type of API you use: REST or XML-RPC

Cloudant change notifications

I am new to Cloudant but have found it useful for a first stage of IoT data. But I need to subscribe to changes based on an id field that is separate from the _id and is unique to the sensor that is sending the data. The examples that I’ve seen so far haven’t helped with this problem. What I’m doing now is sending a separate json doc for each post, so it should return new docs with this sensor id. The json docs sometimes come in by the second but it can be hours as well.
I’m using c# in a .Net web app. The code below creates a call to the Cloudant database and returns the data that I want based on an index that was created for the field SensorID,
json =
{{
"selector": {
"SensorID" : "h7365cf3-17bc-4422-b436-f7bcf12b2e2a"
},
"fields": [
"Data"
]
}}
url = My Cloudant url + ” /_find”.
This returns all docs with the sensorID field that corresponds to the SensorID value in the json query, but just the json object of each doc nested in the Data field.
using (WebClient client = new WebClient())
{
byte[] postBytes = System.Text.ASCIIEncoding.UTF8.GetBytes(json.ToString());
client.UseDefaultCredentials = true;
client.Credentials = new NetworkCredential(username, password);
client.Headers[HttpRequestHeader.ContentType] = "application/json";
var response = client.UploadData(url, "POST", postBytes);
JObject iJson = JObject.Parse(client.Encoding.GetString(response));
return parseIncoming(iJson);
}
When the call is to My Cloudant url + “GET /_DB_UPDATES”, it returns information regarding changes to the whole database. This can be set up as a continuous feed.
I was hoping that this meant that i could subscribe to changes in documents to get new data coming, like Redis Pub/Sub. I’m starting to think that this might not be the case, but if anybody can show me how to do it I would be grateful.
As #adasilva70 said, you need to use the _changes feed.
You can filter changes with an appropriate filter function (so that only changes regarding the documents you're interested in show up).
You can get all updates since a given sequence point (everything since the last data you got) and/or you can use long polling or continuous mode for instant notifications.

Resources