Cannot Send Mandrill Handlebars Template API - javascript

I am trying to access a Mandrill template which I made using their template builder in the Mandrill app (mandrillapp.com/templates).
As I read their documentation I am led to make an Ajax call as such:
{
"key": "<my api key>",
"template_name": "<my template name as defined in Mandrill templates>",
"template_content":[],
"message": {
"from_email": "<my from email>",
"to": <[an array of emails defined above]>,
"subject": "<my subject>",
"merge":true,
"global_merge_vars":[
{
"name": "visitorFirst",
"content": visitorFirst
},
"name": "visitorLast",
"content": visitorLast
},
{
"name": "visitorEmail",
"content": visitorEmail
}
]
}
This returns a 500 error. When I put the content inside "template_content" (which documentation says not to do for handlebars, it at least sends, but does not fill any of the merge variables. I have already set Mandrill to expect Handlebars, not Mailchimp variables.
What am I doing wrong?

Change
"template_content":[]
To
"template_content":null
Problem solved.

Related

Why does this fetch request not work with the provided body

Following this documentation https://docs.tcgplayer.com/reference/catalog_getcategories
I have been able to generate a fetch request to get category search manifest from the endpoint. https://docs.tcgplayer.com/reference/catalog_getcategorysearchmanifest
However I am having trouble with this request https://docs.tcgplayer.com/reference/catalog_searchcategory
specifically the body portion. In my local project I am either getting an error "missing body" or when the body is attached "ops something when wrong" I believe that I am following all of the specifications provided in their documentation.
Here is a code snip of the working request and then one that I am having issues with, although the second request just seems to log and empty array in this environment. https://codesandbox.io/s/romantic-khorana-9tcez5?file=/src/App.js
I have been able to get https://docs.tcgplayer.com/reference/catalog_searchcategory to work with Thunderbolt Client vscode extension using this as a body
{
"sort": "ProductName ASC",
"limit": 500,
"offset": 0,
"filters": [
{
"name": "ProductName",
"values": ["Black"]
},
{
"name": "Rarity",
"values": ["T"]
}
]
}

How to access oauthIdToken returned from Firebase?

I'm trying to get the oauthIdToken of the result fetched from signing with firebase using signInWithCredential. I get the following back upon a successful login:
user Object {
"additionalUserInfo": bg {
"isNewUser": false,
"profile": Object {
"at_hash": "aWhmsdfeef32388EYD8YA",
"aud": "100423452193-gvmasfasdfasdfasfda7ee0.apps.googleusercontent.com",
"azp": "100406623293-gvmt0erkkob6asdfadfi7ee0.apps.googleusercontent.com",
"email": "fake#gmail.com",
"email_verified": true,
"exp": 1579142529,
"family_name": "last name",
"given_name": "first name",
"iat": 1579138929,
"iss": "https://accounts.google.com",
"locale": "en",
"name": "first last name",
"nonce": "Ow_sVcasdf50LdbHdTaro",
"picture": "https://lsfasfa.googleusercontent.com/-iKnasfasdf34/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3re9asdfas7_Erg/s96-c/photo.jpg",
"sub": "100824234342680931658",
},
"providerId": "google.com",
},
"credential": Object {
"oauthAccessToken": "ya29.Il-5B47AOKYEQ5NYikv93gYyyhWu_2FEHEaadfaasfasdfasdfBVJCDXG3HJ9MdqalyyxvZ-6jMoqRsaGzhPUg6Cg862vF25xocHR6rnbh_-HuP2MMey4s59Gx8fXLwgQ99dQ",
"oauthIdToken": "eyJhbGciOiJSUzsdfagyZDgyMDQwM2VlODUxOGM0YWFiYjJiOWZlMzEwY2FjMTIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291joiZW4iLCJpYXQiOjE1NzkxMzg5MjksImV4cCI6MTU3OTE0MjUyOX0.i-YiWbokasfiP_-xWCHJUyT_aLWp7eb3YCE6mzRUbbuKsdfsdfHptczrMXB5vMZY_5JFp8ZD2zxoNlvhTpuMY3B_zw_5Irk6HzuHGHXyAgzNJjh5n6cYR8gOiOsfsdfcKATpHcG7H_gOCwns_fI44I820qcmrogaEXuW-i3u9X5aXbTYqW5EaZQvQzuHkYHO2VWoktOTZsfsdfsfOaYYGU-tqW-ygAB_aWD7VPjIuUY4ySPF4k6IRR1x3ZysfdsdfdGGarX3isPGxMrDMtbRtsfsdfVaKsZdRtCpbfNUbFO8NR6x-pIvKsdfA",
"stsTokenManager": Object {
"accessToken": "eyJhbGciOiJSUzI1NiIsASDAFASFVmZTJlZDQyOWI3MzY0M2Y2NTEiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoicmVudGVyaWkgcmVudGVyaGUuY29tIn19.n7z7HlL9lU7VEOA4fGIHvE9UMLSu5uo1rpfTm6m-N5A8CaKQaDu96sAvsG8iOVx8PYnytadffsafSRHyJoS0bzZbpQS6-YItdM5bIPxLMTFYEb0-Ho-tPnhRBSfWfPqJnK0c18YBFtHTG-0TvLNppmuZFG9AJjZZr0ASIkoOWmkI0gdOUAKBkutwMb3oitxeorT-pUdtKB5Rk23ekewz05oi7R5TI4xpBX5LsPvqaCqI4S5wxHe_BilRiiMhxd_lINdWftEkpctKSApJubML7mB9A",
"apiKey": "AIzaSysdfsdfsiWO7_2buk",
"expirationTime": 1579142530341,
"refreshToken": "AEu4IL01n_G6c4_Wg6fzseXRGPJHEAJnhzw7GLZVTS4RICikJ8PUgmmtNWXjcttOSbmYVCJDzGluUvTNKPHa4aS8gG0R3ijmrvPpcyJFPWZ5dRRDIlzxuoSyt70mewdRYgK4Eao7W21550slj7qHu8ZT_1bACJb31e_y7UnL2QjJEuvKwcWII8v8mgMPpYC2RH6fKg0Xrv9XLBgTxso25KfDrlfHBfYp4t35CzcVqODl71663_xV0WHhQ5gpv1hW0N39MMU5S0UEbQ_FnMmcJUFygaRvHndj2yNVhGwv_Re0uut3hUanPO_bo6OT4VEgIEEZ6cuiq8jzpH_T7d6bwI9eLZNS6IC1Fu8EJFmUWAtsdyBErq0s39gj2uta0uqLIGP_wlP5F_eDiw",
},
"tenantId": null,
"uid": "KlGB4adfadfn9ktr1",
},
Trying to access oauthIdToken with console.log(result.credential.oauthIdToken) inevitably provides null even though the variable is clearly present. I'm assuming this is similar to getting the accessToken within stsTokenManager where you can only get it using the method getIdToken() and credential.stsTokenManager.accessToken provides null.
How do I access oauthIdToken?
It took me a day to sort this one out. I was looking at using promises and found the answer by logging the parts of the object.
The output of printing out the result object is very confusing. The issue is that the JSON object representation has keys which don't correspond to the variables on the object. If you use console.log(JSON.stringify(result.credential)) rather than
console.log(JSON.stringify(result)) you will see the different variable names.
To see the OAuth Identity Token use console.log(console.log(result.credential.idToken)) without the oauth prefix. Likewise the access token doesn't have the oauth prefix.
It is important to know that in the Google/Firebase world there are two different types of identity token. The Firebase identity token is obtained from user.getIdToken(). It is sent to the server to allow the client to be verified. Its audience in the project identifier. The other type, which is the subject of the question, is the identity token generated by the Auth provider. If the Auth Provider is Google then this is the token you have to use to authenticate against Cloud Functions and Cloud Run services. The token needs to be sent in a Authorization: Bearer idtoken header on the request.

POST Discord Message Embed

Here is what Im using sending JSON body data.
{
"reactions": [
{
"count": 1,
"me": false,
"emoji": {
"id": null,
"name": "🔥"
}
}
],
"attachments": [],
"tts": false,
"embeds": [],
"timestamp": "2017-07-11T17:27:07.299000+00:00",
"mention_everyone": false,
"id": "334385199974967042",
"pinned": false,
"edited_timestamp": null,
"author": {
"username": "Mason",
"discriminator": "9999",
"id": "53908099506183680",
"avatar": "a_bab14f271d565501444b2ca3be944b25"
},
"mention_roles": [],
"content": "Supa Hot",
"channel_id": "290926798999357250",
"mentions": [],
"type": 0
}
I only recive the image below. I dont get any embed messages or anything I only get where "Content" is located.
So in theory you need JSON body data to embed messages, I am using a program that sends POST & GET requests. Discord will only take "content" data and post it in my webhook channel. I need to embed a message using JSON data. No language here, just the JSON data, its a program that you enter the varable & data then it will send it. SO I am not using java script or anything.
What It Sends Via Webhook
You have a lot of data in your payload that is not recognized by the Discord webhook. Allowed main tags are username, avatar_url, content, embeds, tts, file. So plain text can go to content, which in your case has worked successfully. Everything more fancy needs to be in the sub-content of embeds.
The best reference, I did found so far is this one.
I also suggest to preview your JSON-code in this tool.
So reduced to what works from your example, it is only this stuff:
{
"username": "Mason",
"avatar_url": "http://your.domain.here/a_bab14f271d565501444b2ca3be944b25",
"content": "Supa Hot",
"tts": false
}

Google Developer OAuth Consent: The supplied API key is not configured for use from this referrer

I'm trying to play around a little bit with the Google Calendar API but I can't create a OAuth ID ( as mentioned in this example: Google Calendar JS API.
I created a project, clicked Cerdentials and if you try to create an OAutho-client-Id you will be forwarded to the configure consent tab.
Here you have to enter your email address (is standard google account) and a project name. Then pressing save leads to an error:
{
"error": {
"code": 403,
"message": "The supplied API key is not configured for use from this referrer.",
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/648364020234/apiui/credential"
}
]
}
]
}
}
The URL metioned in this JSON I can't access (no rights).
What can I do to get a simple oAuth ID?
Tried with several new projects, other naming of the consent projet name.
Also tried to create an API key which can be referred by all clients (empty field).
Any ideas anybody?

Share private Google calendar via api

I am trying to access a calendar hosted on google via my node application however I am unable to query it via the given api due to my calendar needing authorisation.
How would I go about disabling this/making the calendar accessible to my application?
Here is my api query:
https://www.googleapis.com/calendar/v3/calendars/heathwallace.com_gpupieshkuc85dd832m9gjrh9g#group.calendar.google.com
And this is the response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
If you check the documentation Calendars: get for example: you will notice it states
Requires authorization
Now normally if you set something to public you will be able to retrieve it using a public API key. I took one of my test calendars set it to public then tried to retrieve it using a public API key. (both key and calendar name have been changed)
https://www.googleapis.com/calendar/v3/calendars/tfaf72h2ubfsftl3h4l5qd87s#group.calendar.google.com?key=AIzaSyBBH88dIQPjcl5nIG-n1mmuQ12J7HThDBL
results are
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Conclusion: You must be authenticated to retrieve data. Either using OAuth2 or a service account. Normally I would suggest you use a service account and grant it access to the Calendar in question. I would not use a service account with JavaScript due to security issues, so I cant help you with that.
Answer to your question you must be authenticated to see a calendar. there is no way around that.
You can easily do this actually (no Oauth required).
The piece of magic is to create a developer key in the developer console console.developers.google.com (in the APIs & Auth -> Credentials -> Public Access Key -> Key for server app)
Make sure to have the calendar API enabled in the console again (APIs & Auth -> Apis)
GET https://www.googleapis.com/calendar/v3/calendars/heathwallace.com_gpupieshkuc85dd832m9gjrh9g%40group.calendar.google.com/events?key={YOUR_API_KEY}
I've just successfully retrieved your calendar that way.

Categories

Resources