Use BigCommerce API to get a list of prices and name only - bigcommerce

I have an bigcommerce headless ecom site. I keep data synced to my own database so I dont have to rely on bc api calls for every user.
Problem now is that certain data changes often. Like prices. — How can i use the BigCommerce api to get a list of only prices/name/id the list would loook like the below.
[
{
name: xxx,
id: xxx,
calculated_price: xxx,
},
{
name: xxx,
id: xxx,
calculated_price: xxx,
},
]

You can use the ?include_fields parameter to control the fields in the response when using the V3 Catalog API.
For example:
GET /v3/catalog/products?include_fields=calculated_price,name
IDs will always be returned.
From there you could apply other filters to control which items are returned in the collection.
If you also need variant prices, try including the variants with ?include=variants

Related

Zapier lazy load input fields choices

I'm building a Zapier app for a platform that have dynamic fields. I have an API that returns the list of fields for one of my resource (for example) :
[
{ name: "First Name", key: "first_name", type: "String" },
{ name: "Civility", key: "civility", type: "Multiple" }
]
I build my action's inputFields based on this API :
create: {
[...],
operation: {
inputFields: [
fetchFields()
],
[...]
},
}
The API returns type that are list of values (i.e : Civility), but to get these values I have to make another API call.
For now, what I have done is in my fetchFields function, each time I encounter a type: "Multiple", I do another API call to get the possible values and set it as choices in my input field. However this is expensive and the page on Zapier takes too much time to display the fields.
I tried to use the z.dehydrate feature provided by Zapier but it doesn't work for input choices.
I can't use a dynamic dropdown here as I can't pass the key of the field possible value I'm looking for. For example, to get back the possible values for Civility, I'll need to pass the civility key to my API.
What are the options in this case?
David here, from the Zapier Platform team.
Thanks for writing in! I think what you're doing is possible, but I'm also not 100% that I understand what you're asking.
You can have multiple API calls in the function (which it sounds like you are). In the end, the function should return an array of Field objects (as descried here).
The key thing you might not be aware of is that subsequent steps have access to a partially-filled bundle.inputData, so you can have a first function that gets field options and allows a user to select something, then a second function that runs and pulls in fields based on that choice.
Otherwise, I think a function that does 2 api calls (one to fetch the field types and one to turn them into Zapier field objects) is the best bet.
If this didn't answer your question, feel free to email partners#zapier.com or join the slack org (linked at the bottom of the readme) and we'll try to solve it there.

Square Connect API: Retrieving all items within a category

I have been reading over the Square Connect API and messing around with the catalog portion.
I am unable to find how to retrieve all items and their data associated with a particular category. Can someone please point me in the right direction.
I thought it was the
BatchRetrieveCatalogObjects endpoint
I was using the category ID but it was only returning the catalog's data. I need each of the IDs of the items to retrieve their individual data.
I was looking to propagate a list of all the items and their data in one request in JSON.
JSON data to be passed to endpoint:
data = {
"object_ids": [
"category id"
],
"include_related_objects": True
}
My connection to the API:
category_item_endpoint = self.connection.post('/v2/catalog/batch-retrieve', data)
I am using python3 and the requests library.
In order to list items in a category I found it easiest to use the /v2/catalog/search endpoint. Simply follow the documentation on what parameters are accepted. Below are the search parameters that I used to list items by category id.
let sParams: JSON = [
"object_types": [
"ITEM"
],
"include_related_objects": true,
"include_deleted_objects": false,
"query": [
"exact_query": [
"attribute_name": "category_id",
"attribute_value": id
]
],
"limit": 1000
]
You'd probably have the most luck listing your entire catalog GET /v2/catalog/list and then applying filtering (in this case specific catagory_ids ) after you get the data. Based on the documentation doing what you desire doesn't seem possible with an endpoint/query combitionation.

Shopify - Client side order Tagging

As per the requirements I got, In the Shopify shop, admin should be able to search for the orders from a customer chosen delivery date. The only feasible thing I could find was to tag the orders with their delivery and to filter the orders from the tag. My question is whether there a proper way to tag the orders with a customer given delivery date when a order is created? (I'm not allowed use any paid app/plug-in)
There are two approaches I could figure out with the admin orders API, but both has issues,
Write a webhook (for order confirmation event) to an external server that could get the user selected delivery date and call the admin order API from there to tag the order - The issues are it's an overhead to maintain a server only for tagging the order and even if I do since admin API doesn't allow CORS is this feasible? (and since the shop owner doesn't even want to pay for a paid plugin, maintaining server is also not practical)
Call the admin API from the client-side after the order is confirmed. I tried this and it works as it's expected but the issue is I have to keep the admin API credentials for orders and transactions stored in the client-side JavaScript which is not a good practice at all, as per my knowledge.
It's allowed to create additional details about the order at the client side using cart-attributes, and they are shown at the admin order's page as well, but Shoify doesn't allow to search orders using cart-attributes added to the order.
I would be grateful if someone can suggest a solution for this.
You can actually do this with a Chrome plugin (or really complex bookmarklet) with no server side requirements. see https://developer.chrome.com/extensions/overview
your api calls would look something like the following POC scripts. API calls won't search the order by tags so you could skip that and filter by a note_attribute set via your theme's .liquid code. Your chrome plugin would then list open orders and display them by requested delivery date.
get an existing order and update its note attribute:
jQuery.get('/admin/orders/5803440262.json').then(function(d) {
console.log(d.order);
var so = {
id: d.order.id,
note_attributes: [{
name: 'Test Value',
value: 'Test'
}]
};
jQuery.ajax({
url: '/admin/orders/' + so.id + '.json',
type: 'PUT',
data: JSON.stringify({
order: so
}),
contentType: 'application/json'
}).then(function(d) {
console.log(JSON.stringify(d, null, ' '));
});
});
and reading orders:
jQuery.get('/admin/orders.json?limit=250').then(function(d) {
var count = 0;
d.orders.forEach(function(so) {
if (so.tags.indexOf('__amazon_pending') != -1) count++;
});
console.log(count + ' matching orders');
});

Office365 REST v1.0 API How to query global category list

I am using the new Office365 REST API: https://msdn.microsoft.com/en-us/office/office365/api/api-catalog and am successfully querying calendar events, which include their categories as a list of strings: https://outlook.office365.com/api/v1.0/me/events
How do I query the global list of all categories associated with a calendar, as well as the colour associated with each category? The colours I setup via the Outlook client appear to persist across client instances, and yet I can't find a way to access these data via the API.
Great question! You can't access that information currently with the REST APIs, but it's a great idea.
If you're curious, all the gory details on how the category list is stored are documented in [MS-OXOCFG].
You can actually do this now with the current version of the Graph API. If you want to list the categories that have been defined for a user, you can use either of these endpoints:
GET /me/outlook/masterCategories
GET /users/{id|userPrincipalName}/outlook/masterCategories
and get something like this:
HTTP/1.1 200 OK
Content-type: application/json
Content-length: 727
{
"#odata.context":"https://graph.microsoft.com/beta/$metadata#users('8ae6f565-0d7f-4ead-853e-7db94c912a1f')/outlook/masterCategories",
"value":[
{
"id":"5a9a6aa8-b65f-4357-b1f9-60c6bf6330d8",
"displayName":"Red category",
"color":"preset0"
},
{
"id":"4b1c2495-54c9-4a5e-90a2-0ab0b31987d8",
"displayName":"Orange category",
"color":"preset1"
},
{
"id":"de912e4d-c790-4da9-949c-ccd933aaa0f7",
"displayName":"Yellow category",
"color":"preset3"
}
]
}

Instagram API error

I using Instagram API to get user info
api = InstagramAPI(access_token=access_token)
profile = api.user(user_id="kallaucyahoocojp") # I try to put output data to profile variable here
And I get the below error:
DownloadError: Unable to fetch URL: https://api.instagram.com/v1/users/kallaucyahoocojp.json?access_token=(u'1191812153.f78cd79.d2d99595c79d4c23a7994d85ea0d412c', {u'username': u'kallaucyahoocojp', u'bio': u'\u30c4\u30a4\u30c3\u30bf\u30d5\u30a9\u30ed\u30ef\u30fc\u5897\u52a0\u30b5\u30fc\u30d3\u30b9', u'website': u'http://twitter\u30d5\u30a9\u30ed\u30ef\u30fc.jp', u'profile_picture': u'http://images.ak.instagram.com/profiles/anonymousUser.jpg', u'full_name': u'Kallauc', u'id': u'1191812153'})
Can anybody help me to fix it?
You need to pass the numeric-based user id, rather than the username. For example, instead of passing kallaucyahoocojp, you might pass 1234 if t
Here's how to get the ID if you don't have it:
Search for the instagram user id using this endpoint. In the python api:
api.user_search(q="kallaucyahoocojp", count=100)
Check the results for an exact string match on each user name while iterating through the results (calling .lower() to be sure to ignore potential case issues).
If you don't find the user in the first page of results, call to the next page using the max id returned.
Get the user id object from the returned from the matching users search result, then call your original function again with the numeric id.
A couple of very important notes:
Notice that I called the search function for users with a count of 100. You can pick any number, but contrary to other SO posts, the first user is not always the user you want in a search. The search can and will match partials, and not always according to an exact match first. How do I know? I have production instagram apps. I will qualify and say that usually the results are in the first 2-3 matches. Decide what is cheaper; repeated API calls that bring you closer to the limit, or 1 large bulk call where you are certain to get all the results.
The python Instagram API last I checked does a terrible job returning paging information. You actually get the paging URL which defeats the purpose of the python API itself to get additional pages. Your options are extract the next id parameter from the URL using urlparse or something similar, or fix the API to return the paging data as an object per the json (I've done both). What happens is the API itself is discarding part of the json and only giving you the URL which normally you don't want/need.
In your example, here's the search response:
{
"meta": {
"code": 200
},
"data": [
{
"username": "kallaucyahoocojp",
"bio": "ツイッタフォロワー増加サービス",
"website": "http://twitterフォロワー.jp",
"profile_picture": "http://images.ak.instagram.com/profiles/anonymousUser.jpg",
"full_name": "Kallauc",
"id": "1191812153"
}
]
}
Revising your call:
api = InstagramAPI(access_token=access_token)
profile = api.user(user_id="1191812153")
I should note that you may not need to call the user call if you did a search because you may simply have all the info you need. It will depend on what you are doing of course, so I am giving you the general method to use the rest of the user api.
For extracting profile info using Instagram API, userid is required.
The endpoint for extracting userID:
https://api.instagram.com/v1/users/search?q=[username]&access_token=[HERE]
The endpoint for extracting profile info:
https://api.instagram.com/v1/users/[userid]/?access_token=[HERE]
Note that before extracting information, check the login permissions for your access token.