cloud whatsapp api limit conversations per month - facebook

I'm building a bot using WhatsApp Cloud API,
I'm looking for a way to limit the number of conversations per month per payment, for example, I have a budget of 200USD per month, if I reached it, it will not send more messages/conversations
I checked the API documentation and I didn't see anything about it.

There is no straight way but You can use Conversation Analytics API from WhatsApp Business Management API, to keep track of the total cost, which provides the cost of conversation as per provided granularity, following is the example of response,
{
"conversation_analytics": {
"data": [
{
"data_points": [
{
"start": 1643702400,
"end": 1646121600,
"conversation": 6250,
"phone_number": "1919XXXX58X",
"conversation_type": "REGULAR",
"conversation_direction": "BUSINESS_INITIATED",
"cost": 55.0204
},
...
]
}
]
}
}
It will give cost by groping conversation type, conversation direction, and business phone number,
Conversation Types:
FREE_ENTRY: Conversations originating from a free entry point.
FREE_TIER: Conversations within the monthly free tier.
REGULAR: Any conversations that did not originate from a free entry point or are above the monthly free tier allotment.
Conversation Direction:
business_initiated: Conversations initiated by the business.
user_initiated: Conversations initiated by an end user/customer.

Related

Google Analytics Data API online users [duplicate]

I've recently added a Google Analytics GA4 tag to a website for the purpose of counting the currently active users. Before, I could see the number of real-time users right now (I think it had a one-minute delay, but I'm not sure).
But in the new GA4, I can only see the number corresponding to 30 minutes, which is not what I needed.
I've looked around and found an option to add a time dimension of 1 minute, but it was for the old google analytics, and it didn't seem right to me.
Not sure if it's needed to provide my code for this question, but if it's a must, then I'll add it.
Edit:
#Run a realtime report to get desired metrics.
def run_realtime_report(property_id):
#Runs a realtime report on a Google Analytics 4 property.
client = BetaAnalyticsDataClient()
#Run the request.
request = RunRealtimeReportRequest(
property=f"properties/{property_id}",
metrics=[Metric(name="activeUsers")],
)
#Parse the response.
response = client.run_realtime_report(request)
...
return activeUsers
#Run the realtime report function.
def run_sample():
global property_id
return run_realtime_report(property_id)
The number of users in the last 30 minutes in GA4 is similar to the "active users on site right now" in Universal Analytics (UA). However after about 5 minutes of inactivity, UA sometimes assesses users are no longer active on the site. This realtime report was generated with pageviews in the last 5 minutes:
After 5 minutes of inactivity, the active users on site goes to zero:
In GA4, you could recreate that calculation by specifying the minutesRange in your realtime report request. This page describes the minuteRange parameter. As a JSON request, this report will only count users who were active in the last 5 minutes:
{
"metrics": [
{
"name": "activeUsers"
}
],
"minuteRanges": [
{
"startMinutesAgo": 5,
"endMinutesAgo": 0
}
]
}
This request is different from GA4 realtime reporting which highlights the "users in last 30 minutes" as the primary realtime metric:

API provides pagination functionality - client wants to query beyond bounds of API

For a web project, I am consuming an API that returns Educational Materials (books, videos, etc) -- in simplicity you can request:
API accepted parameters :
type: accepts 1 or many: [book, video, software]
subject matter: accepts 1 or many: [science, math, english, history]
per page: accepts an integer, defaults to 2, 0 returns ALL results
page: accepts an integer, defaults to 1
Important: This is a contrived example of a real use case, so it's not just 1 or 2 requests I'd have to cache, it's almost an infinite amount of combinations.
and it returns objects that look like:
{
"total-results": 15,
"page": 1,
"per-page": 2,
"data": [
{
"title": "Foobar",
"type": "book",
"subject-matter": [
"history",
"science"
],
"age": 10
},
{
"title": "Barfoo",
"type": "video",
"subject-matter": [
"history"
],
"age": 14
}
]
}
The client wants to be able to allow users to filter by age on my site -- so I have to essentially query everything and re-run my pagination.
I'd like to suggest to the API team (which we control) to allow me to query by age as well, but trying to explain this concept to the business is proving fruitless.
Right now all that I can think to solve this are 2 options: (1) convince the API team to allow me to query by age or (2) to cache the life out of my requests and use "0" by default and handle pagination on my end.
Again, Important: This is a contrived example of a real use case, so it's not just 1 or 2 requests I'd have to cache, it's almost an infinite amount of combinations.
Anyone have experience dealing with something similar to this?
Edit: Eric Stein asked a very sound question, here is the Q & A:
His Q: "Your API team does not know how to filter by age?"
My A: "They may it's a HUGE organization and I may get stonewalled because of bureaucracy and want to prepare for the worst."
I worked in a project that we consumed an API and had to make more filters that the API allowed (the API wasn't ours). In that case what we decided was to create a cron script that consumed the API and registered the returned data in an database of our own. We had a lot of problems maintaining that (it was A LOT of data), but kinda worked for us (at least for the time I was working in the project).
I think if it's important to your application (and for your client) that you can age filter, that's a pretty good argument to convince the API team to allow that.

Uber API offers Uber Pool option + ability to send text message to drivers?

Does the Uber API offered "Uber Pool" ride type when we requests price / time estimates? Also, when a ride is coming, do we have access to a phone number in order to text the driver?
This isn't so much of an API issue as it is a feature question / request that a lot of our users wanted. I contacted Uber's support team via email and they told me to post anything API related in StackOverflow...
Does the Uber API offered "Uber Pool" ride type when we requests price / time estimates?
According to the GET /v1/products API endpoint documentation:
Some Products, such as experiments or promotions such as UberPOOL and UberFRESH, will not be returned by this endpoint.
Therefore, UberPOOL products are not avaliable through the Uber API.
Also, when a ride is coming, do we have access to a phone number in order to text the driver?
After you make a ride request using the POST /v1/requests API endpoint the first state the ride will be in is the processing state, to which you'll receive a response similar to:
Status-Code: 202 OK
{
"request_id": "852b8fdd-4369-4659-9628-e122662ad257",
"status": "processing",
"vehicle": null,
"driver": null,
"location": null,
"eta": 5,
"surge_multiplier": null
}
And as you can see you don't have access to any driver information in this state.
Then, as per the life cycle of a request, the request flow needs to move from the processing state to the accepted state, once a driver accepts your request.
The accepted state is the first state where you have access to driver details by either calling the GET /v1/requests/current or GET /v1/requests/{request_id} API endpoints.
You can know when the status changes either via a callback on your webhook or by polling at a 3-5 seconds interval one of the above Uber API endpoints to get the current status.
The HTTP response you receive after making one of the above HTTP requests looks something like this:
{
"request_id":"852b8fdd-4369-4659-9628-e122662ad257",
"status":"accepted",
"location":{
"latitude":37.7886532015,
"longitude":-122.3961987534,
"bearing":135
},
"pickup":{
"latitude":37.7872486012,
"longitude":-122.4026315287,
"eta":5
},
"destination":{
"latitude":37.7766874,
"longitude":-122.394857,
"eta":19
},
"driver": {
"phone_number": "(555)555-5555",
"rating": 5,
"picture_url": "https:\/\/d1w2poirtb3as9.cloudfront.net\/img.jpeg",
"name": "Bob"
},
"vehicle":{
"make": "Bugatti",
"model": "Veyron",
"license_plate": "I<3Uber",
"picture_url": "https:\/\/d1w2poirtb3as9.cloudfront.net\/car.jpeg"
},
"surge_multiplier":1.0,
"eta": 5
}
At this point you have access to the driver's phone number which you can use to call or text.

Facebook Ads Api: Can you Get Timeseries of CPI in 15 minutes intervals?

I've just started playing with API's for the first time and my first attempt is with the facebook ads api. I'm looking through the documentation and can see how to pull all cost per action data. Right now I'm really interested in CPI (Cost Per Install) data for a specific campaign, ad set and ad in 15 minute intervals.
Does anyone know if this is even possible with the current API?
You can get reporting stats through the Ads Insights Api:
https://developers.facebook.com/docs/marketing-api/insights/v2.5
As you mentioned, you can get Cost Per Install data by requesting the cost_per_action_type field in your request.
For instance, a call to v2.5/<AD_SET_ID>/insights?fields=['cost_per_action_type']
Would have the cost of mobile app installs as part of the response
{
"data": [
{
"cost_per_action_type": [
{
"action_type": "mobile_app_install",
"value": ...
}
],
"date_start": ...,
"date_stop": ...
}
}
You can make api calls at your discretion as long as you're within the api rate limits: https://developers.facebook.com/docs/marketing-api/api-rate-limiting

PayPal REST API - Order and Authorization Amounts

Taking the REST API out for a spin, and because my frame of reference is "classic API", specifically Express Checkout, I'm pretty much trying to "map" functionality.
Got things going, so this is more "conceptual" than technical..maybe someday this becomes a "wiki"...
Use case: payment_method:paypal
payer_info (Paypal user) is only available after an execute
in order to successfully (re)calculate totals to account for shipping and tax (based on shipping address), is the proper way of doing this via order (not sale) thereby allowing an authorization and capture after such details become available (to merchant)?
in other words, we don't have the classic GetExpressCheckoutDetails so this seems to be the path(?)
Based on this, and testing, can we assume the "maximum" of 115% (above order total) for the authorization call? Based on testing this seems to be true..otherwise "AUTHORIZATION_AMOUNT_LIMIT_EXCEEDED"
Update: In case you were wondering:
you can't update a payment resource. It's actually stated in the link (but I had to try).
you can't "re-execute" either
At this point the only thing that works so far is to authorize < 115%
The sum of the total open authorizations can’t exceed 115% or $75 (whichever is less) of the amount provided to PayPal when the order was created.
REF: https://developer.paypal.com/docs/integration/direct/create-process-order/
In docs, payer object has status defined as:
Status of the payer’s PayPal account. Currently supported with paypal payment_method only, but available for credit_card payment_method at a later date. Allowed values: VERIFIED or UNVERIFIED.
It doesn't seem to be returned in either sale nor order.
A secondary question therefore becomes, how do you "require" a verified PayPal user (is this now account level setting only - no API override)? See: flow_config
The other "missing" items are documented in the API release notes (e.g. fee).
Thanks!
Both order and authorize intent can be used to accomplish the flow (adjustments to authorization or capture) based on PayPal user info.
execute - returns PayPal payer_info - e.g.
"payer_info": {
"email": "foo#noemail.com",
"first_name": "Ed",
"last_name": "SF",
"payer_id": "ABCDEFG",
"shipping_address": {
"recipient_name": "Ed SF",
"line1": "111 Some street",
"city": "San Francisco",
"country_code": "US",
"postal_code": "94111",
"state": "CA"
}
}
Based on the above info, if there are any adjustments needed (i.e. sales tax, shipping),
order can be authorized for the additional amount* (and subsequently captured)
authorization can be captured for the additional amount*
*additional amount can’t exceed 115% or $75 (whichever is less) of the original order or authorization, otherwise, AUTHORIZATION_AMOUNT_LIMIT_EXCEEDED and CAPTURE_AMOUNT_LIMIT_EXCEEDED errors are raised respectively.
This is displayed to the user when a capture greater than the orginal authorization is made:
As far as I can tell, there isn't a similar message for an order (with adjusted amounts) - the additional authorization amount is displayed in the transaction details (only).