Can't get min_delivery_date and max_delivery_date when using CarrierService - json

in Shopify
Dawn theme,
I want to display the minimum and maximum delivery date on page checkout.liquid, using CarrierService (Shopify API).
I need to get min_delivery_date and max_delivery_date. And the problem is that I make a request for - /admin/api/2022-01/carrier_services.json, and I get a response that doesn't have min_delivery_date and max_delivery_date.
I get this response:
{
"carrier_services":[
{
"id":57492111453,
"name":"dhl_express",
"active":true,
"service_discovery":true,
"carrier_service_type":"legacy"
},
{
"id":57492144221,
"name":"ups_shipping",
"active":true,
"service_discovery":true,
"carrier_service_type":"legacy"
},
{
"id":57492078685,
"name":"usps",
"active":true,
"service_discovery":true,
"carrier_service_type":"legacy"
}
]
}
Question: Why are the values min_delivery_date and max_delivery_date not displayed?
I can't understand why this is happening.
Please help.

You are asking Shopify to give you a list of carrier services, and it is responding correctly. You are seeing three, DHL, UPS and USPS. Asking Shopify for a list of carrier services has nothing to do with checkout, and a request made to a Carrier Service.
If you wanted to know the delivery dates of a shipping rate response, you'd have to be inspecting the response from the carrier services! And that is not something you get to do. Instead, you get to form the responses themselves when you deploy your carrier services in your own App.
So clearly, if you are interested in min/max delivery dates, open up the code in the App you installed, and discover why no dates are being provided. Also, note that playing with the min/max delivery dates in response is tricky stuff! It requires a deep understanding of business days, weekends, and the results you respond with to get it right.

Related

Shopify get all shipping rates

I'm creating a progress bar for my product pages that show how much you have to spent until you get free shipping. Everything works great, except that I can't get the shipping rates with the rate for which the client will get free shipping. Currently my request looks like this:
if (cart.items.some(i => i.requires_shipping === true)) {
const url = '/cart/shipping_rates.json?' + encodeURI('shipping_address[zip]={$zip}&shipping_address[country]={$country}');
jQuery.getJSON(url, function(shipping_rates) {
console.log(shipping_rates);
});
}
The If statement checks if a Product is in the Cart that requires shipping. With this setup I'm getting the shipping method based on the current cart value. Expl: If the cart value is below the 25€ free shipping threshold the shipping method shows that shipping costs 3.5€ and once the cart value is above the threshold, it show that the shipping is free.
I want to get the threshold based on the country the client lives in. Is there a way to get the Threshold with a request without making complicated logic based around the shipping_rates?
The problem with this approach is that your request is retrieving currently available shipping rates for the given order but they are not showing the next level.
There are a few problems with this approach:
You won't get next-tier details (e.g. how much $ away you are from the next shipping). It would be best if you stored that info somewhere and JS is not a good place for that.
I am not sure if Script Editor / Shopify Functions shipping discount will be calculated at this point. It will be in the checkout step, but I have never heard of that happening on the cart request level. If my concerns are true then this endpoint is not the best choice for being the source of truth.
You are making a javascript request which takes time and assuming you are showing that info somewhere, you are experiencing reflow and CLS issue
3.1 Such a request could fail.
Since you need to define business logic somewhere and you can't get rid of that requirement, I would highly recommend keeping that logic in meta fields/theme customizer (tiers, discount values) and calculating everything using liquid code. On refresh, you can use Section Rendering API to reload a given part of the page. This is how it solves the above problems:
Your tiers setup is stored in fields/theme customizer which can be accessed using liquid.
You don't need to worry about falsy result from API (shipping rate set up in admin panel vs possible discount) because this is defined by you. The downside is you need to keep discount logic in two places - backend and frontend (liquid) and keep it in sync.
Because you calculate everything using liquid you don't get reflows, issues with loading fetch data and content layout shift.

How does pass_thread_control work in Facebook Handover Protocol?

I'm trying to test the pass_thread_control function on Facebook Messenger, to have my Dialogflow bot direct ongoing conversation to a human operator. So far I'm stuck at even trying to get a "success" code in Graph API Explorer. I have reviewed Facebook's documentation ( https://developers.facebook.com/docs/messenger-platform/reference/handover-protocol/pass-thread-control/ ), carefully looked through different threads here or elsewhere. I have:
Subscribed my Facebook Page to receive messaging_handovers.
Set the Dialogflow chatbot app as the Primary Receiver.
Set the Page Inbox as Secondary Receiver.
...And I keep on getting various errors. For example, I try this request in Graph API explorer:
POST to https://graph.facebook.com/v5.0/me/pass_thread_control
with params:
{
"recipient": {
"id": "myPageID"
},
"target_app_id": "263902037430900"
}
{
"error": {
"message": "Unsupported post request. Object with ID 'me' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "AipGijCLKQOwOl6L792ZEgG"
}
}
Maybe the issue is the recipient PSID? This is the only parameter I have no idea where to get. What is the page scoped app-id? How do I get it?
Or maybe I missed some permissions...?
Any help getting me unstuck much appreciated...
Okay, I actually managed to figure it out.
First and foremost - I discovered the Page I was trying to pass the thread control to wasn't linked to my Facebook Business account and the chatbot app was. I added the page in Facebook Business Manager so that it's linked to the same business account as the chatbot app. NOTE: I am not sure that this is a prereq for everyone, so take caution. It might not be required in all scenarios.
To retrieve the Page PSID, which can then be used in the 'recipient' param of the POST request to pass_thread_control, Sent a GET request using Graph API Explorer as shown here: https://developers.facebook.com/docs/facebook-login/connecting-accounts#examples
Even though the example request does not contain the appsecret_proof param, I used it and haven't tested the request without it. A very simple way of generating appsecret_proof using PHP is shown here: https://developers.facebook.com/docs/graph-api/securing-requests#generate-proof
Then when providing the PSID obtained using method shown in point 2., I got "success:true" while testing the pass_thread_control, which did pass the thread control to Secondary Receiver = Page Inbox. Yaaay! 😊
All of the above is described also in this thread, which helped me figure it out, so credit to Sunil: Is Facebook Messenger PSID PageScope constant for User

Get rates for all services in one request

Question
Is it possible to get rates for all possible ups services in the same request?
Background
Although the UPS rates documentation states that the service element is optional
Requests with the service element defined respond successfully while requests without the element defined result in the following error:
["Error"]=>
array(3) {
["ErrorSeverity"]=>
string(4) "Hard"
["ErrorCode"]=>
string(6) "111100"
["ErrorDescription"]=>
string(58) "The requested service is invalid from the selected origin."
}
Additionally, every example and library i've seen either only desired to create requests for one type of service or creates a request for each service the user specifies they want to receive:
// optional, you can specify which rates to look for -- performs multiple requests, so be careful not to do too many
In Summary
Is there a way to return rates for all services from UPS that I am missing or must we query UPS for each service we wish to get a rate for?
You should be able to receive rates for multiple services by setting the /RateRequest/Request/RequestOption to Shop and omitting the /RateRequest/Shipment/Service element.
This is outlined in UPS's documentation for the Rate Webservice endpoints:
Can a customer compare services for a shipment using the Rating API?
Yes. Use the “Shop” value, instead of the “Rate” value, in the RequestOption element of the ../Request container to retrieve the rates for all services for the stated lane pair. The API response will return a rate for each of the available services. This is known as the Shop option.

All metafields fetched via Shopify API got improper owner and all belong to "shop"

I got problem with shopify API and with data it provides. When i try to get list of all meta-fields with my app I end up with invalid data that tell all meta-fields are owned by shop (owner_id, owner_resource in JSON result). In shop I work with there is over 2000 meta-fields, created mostly by installed apps, that most certainly belong directly to resources like page, blog or product and most of them are most certain not associated directly with shop.
What is more strange when i use chrome plugins or free shopify app to edit meta-fields, that in data i recieve present as associated with shop, they are displayed as belonging to particular aspects of shop as it should be. Adding or deleting meta-field does not reflect on the data or count of meta-fields I get in way explained below.
So what I do first is getting count of metafields with following request, to later know how split data requests into pages.
/admin/metafields/count.json
then to get complete set of data i make series of requests like this
/admin/metafields.json?limit=200&page=1
...
As result i get (example data)
{ "id": 2488777, "namespace": "content_value", "key": "[default]3883205", "value": "There are no items in your cart. ", "value_type": "string", "description": "", "owner_id": 2174481, "created_at": "2014-12-30T20:23:56+01:00", "updated_at": "2014-12-30T20:33:56+01:00", "owner_resource": "shop" }
So my question is what wrong I do here making these requests and why i get invalid data, or it is maybe another "shopify thing" to get such behaviour. Can someone direct me how to get full valid list of meta-fields with rightfully associated owners? Is there any caching involved with metafields that could cause lack of update?
When you make a call to /admin/metafields.json without any query parameters then you will see the metafields that belong to the shop.
You can retrieve metafields that belong to another resource by making an authenticated GET request to a URL like this one: /admin/orders/3250063171/metafields.json
An alternate format for the URL is this: /admin/metafields.json?metafield[owner_id]=3250063171&metafield[owner_resource]=order

Google places details API call return NOT_FOUND for an existing autocomplete reference

I have a problem maybe someone had the same issue.
I am calling google places autocomplete api call.
Then i am presenting the user with the results and he can select the place.
Base on the selection i am making places details call and retrieve the details of the place.
My problem is that some cases the details service return NOT_FOUND. the full response looks something like this
{\n \"debug_info\" : [],\n \"html_attributions\" : [],\n \"status\"
: \"NOT_FOUND\"\n}\n
Based on google api documentation, NOT_FOUND for place details is:
NOT_FOUND indicates that the referenced location was not found in the Places database.
But i got this Reference just 1 sec ago from autocomplete service call!
Anyone has the same problem?
Thanks,
Noam
There are two indexes here, one for the autocomplete suggest and one for the map details. You are seeing the results of the two indexes being updated at different times. If you supply the address in question, I can confirm with the appropriate teams, or you can just wait a couple of days for the indexes to come back into sync.
It could also be due to the fact that the business is closed.
https://developers.google.com/maps/documentation/places/web-service/search-find-place#id-errors
I had a similar issue when using the Find Place endpoint. I would get a successful response and a place_id returned and then calling the Details endpoint would return a NOT_FOUND error.
After adding business_status to the fields on my initial request to the FindPlace endpoint would return:
GET https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=gtdc.org&inputtype=textquery&languagecode=en&fields=place_id,business_status&key={{googlePlacesApiKey}}&locationbias=circle:{{radius}}#{{latitude}},{{longitude}}
Response:
{
"candidates": [
{
"business_status": "CLOSED_PERMANENTLY",
"place_id": "ChIJ7buuHhrhwogR_eWFgXkNyjY"
}
],
"status": "OK"
}
Essentially you just have to ignore any results where the status is CLOSED_PERMANENTLY as these will not work on the details endpoint.
Unfortunately there doesn't seem to be any way of returning the business_status on the Autocomplete endpoint but might be the same issue you are seeing.