UPDATE CONTACT: How to get contact by custom field - google-people-api

I'm using the customField like my own key. It´s an uniqueID. First question:
Is this the best way to do that?
Second:
I was using ContactApp at Apps Script. I was abble to get the contact using the customField => usserDefined field.
How can do it at poeple api?
function updateContact(first_name,last_name, email, phone, address, custom_address, document, anniversary_day,anniversary_month, anniversary_year, sysCompany, sysJob) {
var contacts = ContactsApp.getContactsByCustomField(document,'CPF');
It´s possible to do it at People API?

Related

How to get Zomato restaurant ID using restaurant link?

I want to get details of a restaurant in Zomato. I have it's link as the input (https://www.zomato.com/mumbai/fantasy-the-cake-shop-kalyan?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1). By browsing the documentation of Zomato APIs, I didn't found a way to get it.
I tried searching for the restaurant using search API but it returns many results.
Any help will be appreciated
It's a two-step process:
Find out restaurant's city id, in your case, Mumbai's city id through the /cities API. It's a simple query search.
Use the city id from the above API call in the /search API, like, https://developers.zomato.com/api/v2.1/search?entity_type=city&entity_id=3&q=fantasy%20the%20cake%20shop%20kalyan
This would give all the basic information about a restaurant.
View the page's source and search for window.RES_ID
I had the same issue as you described. This Zomato's API approach is at least odd. It's almost immposible to GET any information about restaurant if you don't know res_id in advance and that's not possible to parse since Zomato will deny access.
This worked for me:
Obtain user-key from Zomato API Credentials (https://developers.zomato.com/api)
Search restaurant url via API (https://developers.zomato.com/api/v2.1/search?entity_id=84&entity_type=city&q=RESTAURANT_URL&category=7%2C9). The more specific you will be, the better results you'll get (This url is specified by city to Prague (ID = 84) and categories Daily menus (ID = 7) and Lunch (ID = 9). If there is possibility do specify city, category or cuisine, it helps, but should't be necessary. Don't forget to define GET method in headers.
Loop or filter through json results and search for the wanted url. You might need to use method valueOf() to search for the same url. Be careful, you might need to add "?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1" at the end of your wanted url so it has the same format. Check that through Zomato API Documentation page.
for (i in body.restaurants) {
var url_wanted = restaurant_url + '?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1'
var url_in_json = body.restaurants[i].restaurant.url;
if (url_wanted.valueOf() == url_in_json.valueOf()) {
var restaurant_id = body.restaurants[i].restaurant.id;
}
console.log('Voala! We have res_id:' + restaurant_id);
}
There you have it. It could be easier though.
Hope it helps!
once you have the url of the rseraunt's page you can simply look for a javascript object attribute named "window.RES_ID" and further use it in the api call.

Sitecore EXM creating contact list via importing csv

I have recently came across scenario where I need to create list via importing csv file. I have few queries to understand how it works
Does importing csv creates contact for each record in csv?
If yes what is the default contact identifier (Name or email)?
Importing contacts for EXM is done by using the List Manager module from Sitecore and there are two ways to import contacts:
Import contacts to the contacts database.
Import contacts and add them to a new Contact list.
When you import contacts from a CSV file, the List Manager allows you to manually map the fields, including the unique indentifier, based on which Sitecore will create a new contact or update an existing.
It's recommended to have a strategy when building this unique identifier, like contact's date of birth or zip code in combination with the first name rather than email address - as a person can have multiple email addresses and it might end up having multiple entries in your contacts database.
So to answer your question, Yes - the List Manager will create a new contact if it doesn't find a match based on the Indentifier you provide. The default identifier is the email address.
Official guideline from Sitecore
Import and export contacts from a list
https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/creating_lists/import_and_export_contacts_from_a_list
Important
List Manager uses the contact identifier to identify the contacts in your database and to ensure that unnecessary duplicates are not created when you import new contacts. Therefore, before you import a list of contacts, it is important that you create a strategy for the contact identifier. For example, if you use the contact's date of birth or zip code in combination with the first name, this makes a more suitable contact identifier than an email address alone. Using the email address as the contact identifier can result in a contact appearing multiple times in the database if they have more than one email address.
How to add a contact to a list
https://doc.sitecore.net/sitecore_experience_platform/digital_marketing/the_list_manager/creating_lists/add_a_contact_to_a_list
If you do not want to use the email address as the contact identifier, select the Manually map contact identifiers check box and then as the Identifier, select the field in the import file that you want to use as the unique identifier for the contacts.

Shopify Python API - how to search for a product

I have built a django app that is the primary store for my products. From this, I publish products to my Shopify Store. Now my django app knows first when my product goes out of stock.
Question:
What options do I have to search for products using the Python API? Can I search by Title, Variant SKU?
Is storing the generated ID while publish the only means to get a handle on the product later?
I want to do this - so that I can mark the products Out Of stock, in a batch process, for example.
Storing the product's id is the simplest way to get a handle on the product later.
However, the product API shows that you can filter products by vendor, handle, product_type, collection_id, published_status, updated_at, created_at or published_at.
The Using the shopify python API page shows how you can use these filters through keyword arguments to the find class method, e.g. shopify.Product.find(collection_id=841564295) to list products in a specific collection.
YOu can use the official shopify python API to find a product with id:
shopify.Product.exists(product.id) # => True
product = shopify.Product.find(292082188312)
For searching products with the product title, you can use GraphQL API

Prestashop: Add products to a new cart

This is not a general problem, but I hope someone has encountered this issue!!
I have a prestashop website, and now I'm creating a mobile version of this site, using phonegap.
I connect to the site data base via the prestashop webservice.
I can add a new cart, but this cart is empty and It doesn't belong to the customer who have added a product to his cart.
I have expected to use an url like this:
http://monsite/Create_carts.php?id_product=..&quantity=..&id_customer=..
but there is not an id_product or an id_customer attribute in the cart object.
My question is how to add products to a cart and make it belong to the logged customer?
You have an order object which links to a cart object and a customer object. There is also a cart_product object which links to a product and a cart.
Database structure:
customer -> order -> cart -> cart_object.
That is how it is in the database, I have no idea how to use the API to do that as I'm searching for that myself...
It usually seems to be that you get a blank schema, populate it with the correct data and then send it in to add it to the database. You can get the blank schema with something like:
$xml = $webService->get(array('url' => 'http://my_prestashop_shop/api/carts?schema=blank'));
But as I have stated. I cant seem to do this myself. I will come back if I find the answer.

Django: structuring a complex relationship intended for use with built-in admin site

I have a fairly complex relationship that I am trying to make work with the Django admin site. I have spent quite some time trying to get this right and it just seems like I am not getting the philosophy behind the Django models.
There is a list of Groups. Each Group has multiple departments. There are also Employees. Each Employee belongs to a single group, but some employees also belong to a single Department within a Group. (Some employees might belong to only a Group but no Department, but no Employee will belong only to a Department).
Here is a simplified version of what I currently have:
class Group:
name = models.CharField(max_length=128)
class Department
group = models.ForeignKey(Group)
class Employee
department = models.ForeignKey(Department)
group = models.ForeignKey(Group)
The problem with this is that the Department select box on the Employees page must display all Departments, because a group has not yet been set. I tried to rectify this by making an EmployeeInline for the GroupAdmin page, but it is not good to have 500+ employees on a non-paginated inline. I must be able to use the models.ModelAdmin page for Employees (unless there is a way to search, sort, collapse and perform actions on inlines).
If I make EmployeeInline an inline of DepartmentAdmin (instead of having a DepartmentInline in GroupAdmin), then things are even worse, because it is not possible to have an Employee that does not belong to a Group.
Given my description of the relationships, am I missing out on some part of the Django ORM that will allow me to structure this relationship the way it 'should be' instead of hacking around and trying to make things come together?
Thanks a lot.
It sounds like what you want is for the Department options to only be those that are ForeignKey'ed to Group? The standard answer is that the admin site is only for simple CRUD operations.
But doing what you're supposed to do is boring.
You could probably overcome this limitation with some ninja javascript and JSON.
So first of all, we need an API that can let us know which departments are available for each group.
def api_departments_from_group(request, group_id):
departments = Department.objects.filter(group__id=group_id)
return json(departments) # Note: serialize, however
Once the API is in place we can add some javascript to change the <option>'s on the department select...
$(function() {
// On page load...
if ($('#id_group')) {
// Trap when the group box is changed
$('#id_group').bind('blur', function() {
$.getJSON('/api/get-departments/' + $('#id_group').val() + '/', function(data) {
// Clear existing options
$('#id_department').children().remove();
// Parse JSON and turn into <option> tags
$.each(data, function(i, item) {
$('#id_department').append('<option>' + item.name + '</option>');
});
});
});
}
});
Save that to admin-ninja.js. Then you can include it on the admin model itself...
class EmployeeAdmin(models.ModelAdmin):
# ...
class Media:
js = ('/media/admin-ninja.js',)
Yeah, so I didn't test a drop of this, but you can get some ideas hopefully. Also, I didn't get fancy with anything, for example the javascript doesn't account for an option already already being selected (and then re-select it).