Sending emails with sendgrid - mongodb

I am trying to use sendgrid with MongoDB stitch,and I have a domain name already on namecheap. I set up the domian authentication already,but do I need to have an email address with my domain ready before using sendgrid on MongoDB?I am not quite how everything works with sendgrid and its api. Anyone could help explain it a bit more?

You'll need to verify the sender address that you want to use. You can do that either for the entire domain (with domain authentication) or just a single sender. As you've already done the domain authentication, you are good. This guide should enable you to send emails with a snippet that looks like this:
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization: Bearer <<YOUR_API_KEY>>' \
--header 'Content-Type: application/json' \
--data '{"personalizations":[{"to":[{"email":"john.doe#example.com","name":"John Doe"}],"subject":"Hello, World!"}],"content": [{"type": "text/plain", "value": "Heya!"}],"from":{"email":"sam.smith#example.com","name":"Sam Smith"},"reply_to":{"email":"sam.smith#example.com","name":"Sam Smith"}}'

Related

Auth0 Request and use a Management API token from a Flutter App

We need to allow our Flutter application to save a property in the user_metadata when the application starts.
As I understand this is a task to be done with the Management API and in order for the Flutter application to be able to write in the user_metadata the client has to request a Management API access token.
I found no information on how to request this token, the closest thing is this page in the documentation that has no example and no explanation on how to retrieve this token:
https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-tokens-for-single-page-applications
Can anyone provide an example on how to request this token from a Flutter app?
Even a generic CURL request would be helpful to understand what endpoint to call with which parameters.
Error received when trying to access the Management API to update the user_metadata:
body{
"statusCode":400,
"error":"Bad Request",
"message":"Bad HTTP authentication header format",
"errorCode":"Bearer"
}
2 steps are needed:
Get the authentication token for management API:
sample curl:
curl --location --request POST "https://YOUR_AUTH0_DOMAIN/oauth/token" \
--header "content-type: application/json" \
--data-raw "{
\"grant_type\": \"client_credentials\",
\"audience\": \"https://YOUR_AUTH0_DOMAIN/api/v2/\",
\"client_id\": \"YOUR_AUTH0_APPLICATION_CLIENT_ID\",
\"client_secret\": \"YOUR_AUTH0_APPLICATION_CLIENT_SECRET\"
}"
call the management api to update app_metadata
sample curl:
curl --request PATCH \
--url 'https://YOUR_AUTH0_DOMAIN/api/v2/users/USER_ID' \
--header 'authorization: Bearer TOKEN_FROM_STEP_1' \
--header 'content-type: application/json' \
--data '{"email": "whatever#example.com", "user_metadata": {"hobby": "surfing"}, "app_metadata": {"plan": "full"}}'
Edit: Patch request with userID

get sent or recieved emails from sendgrid

We're using SendGrid for email service for a project backend.
Now, we want to set up e2e tests for the project. To get a well-verified user, we have to know the verification code sent to the user's email at the time of the registration.
I've tried with the messages endpoint as:
curl --request GET \
--url https://api.sendgrid.com/v3/messages \
--header 'Authorization: Bearer SG.xxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json'
But the response says:
{"errors":[{"message":"authorization required"}]}
Is there any way that we can get the sent emails using the SendGrid API?
Thank you in advance.
At the top of the documentation for the email activity API it says:
In order to gain access to the Email Activity Feed API, you must purchase additional email activity history.
I would guess that you are receiving that error because your account does not have that additional email activity history add-on.

Auth0: Let user resend the Verification Email

I enabled the user/password connection in Auth0, and I would like to have the emails verified before proceeding. I enabled the corresponding rule to force the email verification and everything seems to work as expected.
Still, I noticed that the verification email is sent upon signing up. I want a button to allow sending that email again, but this doesn't seems to be possible.
How can a user, from the UI, ask for a verification email?
Calling https://<tenantName>.auth0.com/api/v2/jobs/verification-email won't do, because the token needs the update:users scope. We can get a token with that scope with a request to https://<tenantName>.auth0.com/oauth/token, but that means the client secret would be exposed.
there is a work around for this, I use it as a post email verification signal.
auth0 create a ticket and send us a link with the ticket id as query string to verify the email, the link sent is like below:
https://<domain>/u/email-verification?ticket=h7CtBxPXiej7FtaKo0UHYJtdWPazaHhs#
you can use this api to resend the email verfication link, here is an example of the request:
curl --location --request POST 'https://<domain>/api/v2/tickets/email-verification' \
--header 'Authorization: Bearer <token> \
--header 'Content-Type: application/json' \
--header 'Cookie: __cfduid=d7aa37a65221ad2c0fd17ec71c76f13eb1603727648; did=s%3Av0%3A694d6590-1a83-11eb-877d-d1f701a6b5e1.qweiCQT%2Fah2JbVlHe8mU7En5egRFtrEmjETM%2B%2BIKmzc; did_compat=s%3Av0%3A694d6590-1a83-11eb-877d-d1f701a6b5e1.qweiCQT%2Fah2JbVlHe8mU7En5egRFtrEmjETM%2B%2BIKmzc' \
--data-raw '{
"result_url": "<redirection_url>",
"user_id": <auth0_user_id>,
"ttl_sec": 0,
"includeEmailInRedirect": false,
"identity": {
"user_id": "<user_id>",
"provider": "auth0"
}
}'

update: getting 400 error 'invalid_payment', only when rides are ordered via api, ordering on phone works fine

I'm getting an "invalid_payment" error only when ordering rides via the api. I thought it may have been an account issue so checked my app but I was able to login and order manually on my phone without any problems.
Here is my request and response. Is there anything else you need?
Request:
curl -X POST \
https://api.uber.com/v1/requests \
-H 'authorization: Bearer TOKEN' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: c2e706c0-5bde-c324-1326-8bfc43a37079' \
-d '{
"start_latitude": "43.854816",
"start_longitude": "-79.4368132",
"start_address": "9350 Yonge Street, Richmond Hill, ON L4C 5G2",
"product_id": "d1e548ac-4be5-46c0-8c86-201ac8a36fc6",
"end_latitude":"43.8656588",
"end_longitude":"-79.4411572",
"end_address": "11 Bingham Street, Richmond Hill, ON L4C 8Y6"
}'
Response:
{"meta":{},"errors":[{"status":400,"code":"invalid_payment","title":"The rider's payment method is invalid and they must update their billing info."}]}
Edit: When ordered via the API the request does not come up like it usually does when you have the app on your phone open. Additionally, the API is letting me order rides normally for some addresses, just not all (mainly Canadian) addresses.
Edit 2: I tried refreshing the token thinking it may have been a caching issue but no luck.
Edit 3: This appears to really only be happening for addresses in Canada. API can order rides successfully without invalid_payment error in the U.S.

Uber Rush API Sandbox

Trying to test Uber Rush API (from localhost and from linux server).
Calling Token works - I get the token
trying to implement sanbox example:
curl -X "PUT /v1/sandbox/deliveries/{delivery_id}" \
-H "Authorization: Bearer <OAUTH TOKEN>" \
-d "{\"status\":\"en_route_to_pickup\"}"
with url https://sandbox-api.uber.com/
and I tried the same request with file_get_contents (in PHP)
So, I always get error "405 Method Not Allowed"
{"message":"Method not supported for this endpoint.","code":"method_not_allowed"}
What I need to do to get access to method from this sandbox example https://developer.uber.com/docs/rush/sandbox?
Corrent syntax
curl -X "PUT" -H "Authorization: Bearer <TOKEN>" -H "Content-Type: application/json" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/DELIVERY_ID
EDIT: Updated to reflect both issues in your question...
You have a mismatch in your requests and an incorrect syntax for curl.
First off your CURL request is incorrectly specified. It should be:
curl -X "PUT" -H "Authorization: Bearer <OAUTH TOKEN>" -d "{\"status\":\"en_route_to_pickup\"}" https://sandbox-api.uber.com/v1/sandbox/deliveries/{delivery_id}
In addition, your curl command is trying to issue a PUT request to the uber sandbox PUT API. However, your PHP code is not setting the context correctly and so is probably issuing a GET request. I suspect that the server is therefore rejecting the request as a GET as not allowed to do this sort of operation.
To fix it, see Bad request using file_get_contents for PUT request in PHP. This should give you an example of how to pass in the necessary context to issue a PUT request using file_get_contents().