I want to get an email from my gmail sent items via c#.
I used this
service.Users.Messages.Get("me",id);
but it get 404 error.
All other apis works properly.
Thanks.
404 means that the Id you are requesting does not exist. I would run a List first then a get after.
If you want to see messages that are in the sent folder you should do a message.list
and search for what is in the sent folder.
var request = service.Users.Messages.List("me");
request.Q = "is:sent";
var result = request.Execute();
If you know when it was sent you could add a date.
var request = service.Users.Messages.List("me");
request.Q = "is:sent after:2021/3/28 before:2021/3/31";
var result = request.Execute();
Tip Q works just like the search function in the Gmail web application so if you can get that to return what you want just add it to Q
Related
I followed this page to setup a MicrosoftGraphProvider: http://www.keithmsmith.com/get-started-microsoft-graph-api-calls-net-core-3/
This is working correctly, as I am able to get a list of all of my users with the following request.
var user = await _graphServiceClient.Users.Request().GetAsync();
However, I don't always want all of the users returned, so I have a filter on a user by email.
The example says to do this
var user = await _graphServiceClient.Users[email].Request().GetAsync();
But this always results in user not found, even if I pass a valid email from the response of all users.
So I tried to build a filter, and do it this way.
var test = await _graphServiceClient.Users["$filter=startswith(mail,'test#email.com')"].Request().GetAsync();
var test = await _graphServiceClient.Users["$filter=(startswith(mail,'test#email.com'))"].Request().GetAsync();
Both of these returned the error:
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: BadRequest
Message: The $filter path segment must be in the form $filter(expression), where the expression resolves to a boolean.
This filter works fine when I use it in Postman calling the url directly. But I am trying to use their sdk and it is not working as expected.
What is wrong with this filter query?
$filter should be specified in Filter method. The article you followed does not reflect the current API.
var users = await _graphServiceClient.Users
.Request()
.Filter("startswith(mail,'test#email.com')")
.GetAsync();
Check documentation
I have the following functions to get messages using Graph API
var client = new GraphServiceClient(authenticationProvider);
var messages = await client.Users["useer#domain.com"].Messages
.Request()
.GetAsync();
I am only able to get the latest 10 messages. How do I get all the messages? I tried to have a look at the microsoft documentation here: https://learn.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=csharp but unable to find any clues.
Found the answer after googling and trial error.
IUserMessagesCollectionPage msgs = await _client.Users[user#domain.com].Messages.Request()
.Filter("put your filter here")
.GetAsync();
List<Message> messages = new List<Message>();
messages.AddRange(msgs.CurrentPage);
while (msgs.NextPageRequest != null)
{
msgs = await msgs.NextPageRequest.GetAsync();
messages.AddRange(msgs.CurrentPage);
}
You can do it with .Top():
var client = new GraphServiceClient(authenticationProvider);
var messages = await client.Users["user#domain.com"].Messages
.Request()
.Top(100)
.GetAsync();
I think you should refer to this document:
Depending on the page size and mailbox data, getting messages from a mailbox can incur multiple requests. The default page size is 10 messages. To get the next page of messages, simply apply the entire URL returned in #odata.nextLink to the next get-messages request. This URL includes any query parameters you may have specified in the initial request.
We're trying to receive payment with cryptocurrencies using coinpayment IPN. We are able to create a request and able to do a payment. However, not able to get success or failure response while user come back to the seller side.
Here is how payment request created:
public ActionResult IPN()
{
var uri = new UriBuilder("https://www.coinpayments.net/index.php");
uri.SetQueryParam("cmd", "_pay_auto");
uri.SetQueryParam("merchant", "merchant_key");
uri.SetQueryParam("allow_extra", "0");
uri.SetQueryParam("currency", "USD");
uri.SetQueryParam("reset", "1");
uri.SetQueryParam("success_url", "http://localhost:49725/home/SuccessResponse"); //todo: redirect to confirm success page
uri.SetQueryParam("key", "wc_order_5b7b84b91a882");
uri.SetQueryParam("cancel_url", "http://localhost:49725/home/FailiureResponse");
uri.SetQueryParam("order_id", "36");
uri.SetQueryParam("invoice", "PREFIX-36");
uri.SetQueryParam("ipn_url", "http://localhost:49725/?wc-api=WC_Gateway_Coinpayments");
uri.SetQueryParam("first_name", "John");
uri.SetQueryParam("last_name", "Smith");
uri.SetQueryParam("email", "a#a.com");
uri.SetQueryParam("want_shipping", "1");
uri.SetQueryParam("address1", "228 Park Ave S&address2");
uri.SetQueryParam("city", "New York");
uri.SetQueryParam("state", "NY");
uri.SetQueryParam("zip", "10003-1502");
uri.SetQueryParam("country", "US");
uri.SetQueryParam("item_name", "Order 33");
uri.SetQueryParam("quantity", "1");
uri.SetQueryParam("amountf", "100.00000000");
uri.SetQueryParam("shippingf", "0.00000000");
return Redirect(uri.ToString());
}
This will be redirected to the coinpayment site, once payment done, it is showing the following screen.
And trying to get data when user click on back to seller's site, I have tried to get data using Request.Form, but not getting any value in form.
The same thing, working with this woocommerce code, but I have no idea of PHP and how they are dealing with it.
Any thought to get IPN response?
Note: there is no development documentation or sample code available for IPN in .NET
Edit
I'm trying to get value from IPN success
Public ActionResult SuccessResponse()
{
var ipn_version = Request.Form["ipn_version"];
var ipn_id = Request.Form["ipn_id"];
var ipn_mode = Request.Form["ipn_mode"];
var merchant = Request.Form["merchant"];
var txn_id = Request.Form["txn_id"];
var status = Request.Form["status"];
return Content(status);
}
You cannot use localhost for a IPN callback. You must use a public domain name.
As an example I would change the following parameters:
var uri = new UriBuilder("https://www.coinpayments.net/api.php");
uri.SetQueryParam("success_url", "http://kugugshivom-001-site1.atempurl.com/Home/SuccessResponse");
uri.SetQueryParam("cancel_url", "http://kugugshivom-001-site1.atempurl.com/Home/FailiureResponse");
uri.SetQueryParam("ipn_url", "http://kugugshivom-001-site1.atempurl.com/Home/CoinPaymentsIPN"); // Public ActionResult CoinPaymentsIPN()
Since you are creating your own gateway you also need to implement it properly as described in the documentation at CoinPayments API and Instant Payment Notifications (IPN).
I have tested your success_url endpoint, and got status code: 100 (when entering status:100). I see you use form-data, but I don't know if that's on purpose / required.
Postman POST http://kugugshivom-001-site1.atempurl.com/Home/SuccessResponse
In Body tab form-data is selected with Bulk Edit values:
ipn_version:1.0
ipn_type:api
ipn_mode:hmac
ipn_id:your_ipn_id
merchant:your_merchant_id
txn_id:your_transaction_id
status:100
As updated answer stated by #Gillsoft AB, you should need to use valid IPN URL from the code end. Also webhook would not work with localhost. thus, you should listen the request with live server.
Simplest way to check webhook response is to use online tool such as Webhook Tester, it will provide an URL which you have to set as your IPN URL, whenever server will sends the data, you can simply see it to the web. To check that, create one URL and set as your IPN URL as below:
uri.SetQueryParam("ipn_url", "https://webhook.site/#/457f5c55-c9ce-4db4-8f57-20194c17d0ae");
After that run the payment cycle from local machine, payment server will sends notification to that IPN URL.
Make sure you understood it right! success_url and cancel_url are for user redirection, you will not get any response code over there, inspection of seller's store URL give your exact same URL that you have been passing though, so it is recommended to use unique URLs for each order(i.e add order id at last to the URL) which will give you an idea which order payment has been done or canceled.
http://localhost:49725/home/SuccessResponse?orderid=123
In order to test your local code, add following changes and deployed it to server.
1) Add one new method which will listen IPN response
[ValidateInput(false)]
public ActionResult IPNHandler()
{
byte[] param = Request.BinaryRead(Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
//TODO: print string request
//nothing should be rendered to visitor
return Content("");
}
2) Pass IPN URL while creating a request:
public ActionResult IPN()
{
var uri = new UriBuilder("https://www.coinpayments.net/index.php");
...
..
uri.SetQueryParam("success_url", "http://localhost:49725/home/SuccessResponse");
uri.SetQueryParam("cancel_url", "http://localhost:49725/home/FailiureResponse");
uri.SetQueryParam("ipn_url", "http://localhost:49725/home/IPNHandler");
....
..
return Redirect(uri.ToString());
}
You will get all status code responses in IPNHandler method.
Hope this helps!
I have a c# project sending firebase messages via http post to clients having ios and android.
When clients uninstall my app their firebase device IDs are not deleted from my database unfortunately.
The next time I send a message to the device id witch corresponds to an user who uninstalled my app, of course the message is not delivered.
Is there any way to know if the message was not delivered ?
Unfortunately the response is always successful even if the message is not delivered.
My current code:
var firebaseMessage = new FirebaseMessage();
firebaseMessage.data = notificationMessages;
firebaseMessage.to = device.DeviceRegistrationId; <-- maybe this device is no longer valid
firebaseMessage.priority = "high";
firebaseMessage.notification = new ExpandoObject();
firebaseMessage.notification.title = "myApp";
firebaseMessage.notification.body = "testMessage";
firebaseMessage.notification.sound = "default";
firebaseMessage.notification.click_action = "FCM_PLUGIN_ACTIVITY";
firebaseMessage.notification.icon = "fcm_push_icon";
firebaseMessage.notification.delivery_receipt_requested= true;
var client = new HttpClient();
var appKey = "key=" + ApplicationConfig.FirebasKey;
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", appKey);
var response = await client.PostAsJsonAsync("https://fcm.googleapis.com/fcm/send", message);
return response;
When your app is uninstalled from a device, the corresponding registration token would then be invalidated by the FCM server, so any messages sent to that specific token would result to a NotRegistered response (also see my post here). In that event, you could proceed with deleting the token (or archiving it).
If your use-case intentionally wants to know if the message was received on the client side, you're gonna have to implement Delivery receipts.
I am creating users via the C# Management Api. Using passwordless, this automatically causes an email to go out. That part works great!
When I click the link in the email, it pops up my Auth0 instance, and I'm getting the "Oops! Something went wrong" message... In the querystring, I can clearly see that redirect_uri is empty, and I assume that must be the problem. Hitting F12, this seems to be confirmed - it's failing on something called VerifyRedirect.
So how do I set this redirect_uri? I am using the C# SDK, and I don't see a way to set it in UserCreateRequest. I also don't see it in the dashboard. What am I missing?
Here's my test code:
var request = new UserCreateRequest()
{
Connection = "email",
Email = email,
EmailVerified = false,
VerifyEmail = true,
FirstName = first,
LastName = last,
FullName = first + " " + last,
AppMetadata = new
{
roles = "Admin"
}
};
// Just dodging async while I test - remember, this part works.
var result = client.Users
.CreateAsync(request)
.GetAwaiter()
.GetResult();
When you create an user via the management API, the redirect URI is set to the first available callback URLs in your client. You can check the client ID in the query string to determine the client and add the redirect URI in its settings.
Note that you don't have to actually create a user like this to start the passwordless flow on an email. If you use the Passwordless​Email​Request object, you can set the client ID and redirect URI (inside AuthenticationParameters) explicitly, so they will not be implicitly deduced.