I'm having issues getting my ColdFusion application to integrate with Sendgrid's v2 API using API Keys. My solution has worked for years using username/password, but with the switch over to API Keys, something is amiss that I cannot figure out. I've tried a few different configs, but none have worked thus far:
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json?api_user=apikey&api_key=[my key]" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
</cfhttp>
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="formField" name="api_user" value="apikey">
<cfhttpparam type="formField" name="api_key" value="[my key]">
</cfhttp>
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="header" name="api_user" value="apikey">
<cfhttpparam type="header" name="api_key" value="[my key]">
</cfhttp>
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="cgi" name="api_user" value="apikey">
<cfhttpparam type="cgi" name="api_key" value="[my key]">
</cfhttp>
Help?
I think I figured it out. After poking around in this codebase:
https://github.com/mjclemente/sendgrid.cfc/blob/master/sendgrid.cfc
...it looks like the syntax needs to be:
<cfhttp method="POST" url="https://sendgrid.com/api/mail.send.json" resolveurl="no" timeout="60" result="mailSent">
<cfhttpparam type="formField" name="to" value="to@email.com">
<cfhttpparam type="formField" name="from" value="from@email.com">
<cfhttpparam type="formField" name="fromname" value="Test User">
<cfhttpparam type="formField" name="subject" value="Test Send">
<cfhttpparam type="formField" name="text" value="This is a test">
<cfhttpparam type="header" name="Authorization" value="Bearer [my key]">
</cfhttp>