SendGrid API: Get Campaign Stats - php

I've been looking for a way to get SendGrid stats for specific campaigns. I can see the stats on the Campaigns page of the SendGrid dashboard, but I can't find an API endpoint to get that data.
I could retrieve the Global and Overview stats, no problem, but in this case, those are not helpful for me. I need per-campaign stats. Is there a way to get those reports through the API?

Campaign level stats are not available via the official Sendgrid API, at least not that I could find.
However, there are a couple of undocumented URLs you can use to get campaign level stats:
https://sendgrid.com/marketing_campaigns/campaigns/CAMPAIGN_ID/stats.csv
^ this returns data in CSV format
https://sendgrid.com/marketing_campaigns/campaigns/CAMPAIGN_ID/stats.json
^ this returns data in JSON format
Note that these are the endpoints used by the Sendgrid web client, and so require authentication via Cookie token.
To obtain a token you can use the https://api.sendgrid.com/v3/public/tokens endpoint, and send your username and password in the payload.
Then you can send that token as a Cookie along with your requests to the above Sendgrid web client endpoints. Note, you must use cookie name mako_auth_token.

I solved my situation by creating unique (ID-like) categories for each campaign. This way, I can use the Category Stats API Endpoint. It's not a semantically correct usage of categories, but this is the only way I found to achieve this.
Update July 2017:
I also achieved this goal + much more by using SendGrid Subusers and the on-behalf-of: subuser_<username> header (search on behalf of subuser in the left searchbox). This header allows you to create requests using the parent account on behalf the subuser.

Related

How to set multiple ClientCustomerId in Google Adwords API in php?

I have multiple client Id (i.e. xxx-xxx-xxxx) under one main account. I can access API by using one account id (xxx-xxx-xxxx) and get the API response.
But in my current application I need to get API response of multiple account id (i.e. xxx-xxx-xxxx, yyy-yyy-yyyy). Actually I want to avoid the API call in loop of multiple account id.
Now in my php library I can set one account that is
$user = new AdWordsUser();
$user->SetClientCustomerId($clientId);
Is there any way, so that I can set multiple account and get data in one single API call in google adwords ?
The SetClientCustomerId($clientId); method only accepts 1 parameter (1 client id), so no, you can't set multiple accounts and get data in one single API call.

How to send FCM Notification to a list of specific device tokens using the v1 API

I want to use the new FCM HTTP v1 API, which is documented here
FCM HTTP v1 API Documentation, to send a notification to multiple devices at once, but without using topics, or groups (let's say I want to send a notification to 10 random winners of some lottery). I know that in the previous version (Legacy FCM HTTP Protocol), this was possible by using the registration_ids parameter, but I don't see anything similar in the current API. Am I missing something? Is there a way to do this without using the legacy API?
There is currently no other way to send to multiple tokens besides using topics for FCM v1.
In your mentioned use case, if I'm using v1, I would probably go at something like, after selecting the winning tokens, you subscribe them to a topic like winningTokens<date_here> then send the message.
For other use cases, the best way to send to multiple devices via v1 API depends on your application. For example, the accepted answer would not be a good solution for a private chat application where another user can guess the topic name and evesdrop on the conversation by subscribing to the topic. In that scenario iterating over the device list and making multiple send calls to a single device would be better.

Is it possible for me to exchange information with Twilio APIs?

I'm trying to identify the user who is making Twilio requests from my system. Is there a way I can encrypt the information of this user, send it to Twilio along with the allowed parameters & receive the same along with Twilio's response?
EDIT: I may not have been very clear. I'm trying to make calls using Twilio's API from a web-app (PHP). I need to send the user (who is trying to establish the call)'s details & our API key to Twilio so that I can identify the user when I receive the response from Twilio.
You can include custom URL parameters in Twilio's webhook callback URL. Although the Twilio system itself will not make use of this information, it will be passed back to your php application when the call is answered. You can use this information to correlate the call to a user or other application specific concept. Here's an example:
$call = $client->account->calls->create(
'9991231234', // From a valid Twilio number
'8881231234', // Call this number
// Call this URL when a call connects and include the custom user_id parameter
'http://www.yoursite.com/handle_call.php?user_id=41423’
);
You can find more information about how the Twilio REST API and webhooks work together in the Twilio Skills training.
I doubt if it is twilio's responsibility to store additional information that you need to be otherwise handling yourself on your system. Why would twilio take operational overload from your end? Twilio probably has a confirmation token or request id for the twilio request that your system makes (returned via XML/ Json by its API server). You can take that ID and store it against the user_id inside your database (SQL / Mongo / Redis). Use that table to extrapolate information you need such as.
The number of requests each user made initiated.
The kind of requests made.
What time each request went out.
Result / Response from each request.
Hope this helps.

How to get current customer id magento rest api

I want to use magento rest api authorization for my web application customers, I found in docs that there is /customers/:customerId request, to get information about user, but I can't understand, how to get customerId to make this request. Is there such a method in Magento REST API and if not, how I can get authorized customer Id via REST API.
There is a REST service to get a list of all existing customers and their customerId. Its a GET request to /customers. You can find its description in the REST API docs http://www.magentocommerce.com/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-GET-customers
Unfortunately there is no service to authenticate users using username and password that I know of. Not even in the SOAP API that has much more services than the REST API.

Google Contacts Data API and PHP

I'm developing a PHP application to retrieve the list of contacts from a GMail account. I'm looking for a solution which would enable the user of my application to provide the login and password to their Gmail account in my application (as opposed to getting redirected to Google) and then automatically do the retrieval. The retrieval process can be run in PHP or JavaScript (which would then feed the list of contacts back to PHP using Ajax).
Is it possible to do that? Which JavaScript API should I use for that? Can someone point me at the right chapter in Google Contacts Data API documentation?
This is really not advised - google provide OAuth for a reason - so that users won't have to give their credentials to 3'rd parties.
Check out http://code.google.com/apis/accounts/docs/OAuth.html
Speaking only for my self (and all other developers I know), having to hand over my credentials to 3'rd parties is a real no-no.
It would be best to use the Google Contacts Data API using JavaScript for your case.
I haven't tested it myself but it looks nice: http://gmail-lite.sourceforge.net/wordpress/
//edit:
You probably should use: http://code.google.com/apis/contacts/

Categories