1

I'm trying to authenticate with the Zendesk API using CF. I've been able to do it successfully via curl. Now I'm trying to figure out where to place the parameters using <cfhttp> so I can authenticate and create a user.

  curl -v -u email@email.com/token:************************* https://test.zendesk.com/api/v2/users.json \
    -H "Content-Type: application/json" -X POST -d '{"user": {"name": "Roger Wilco", "email": "roge@example.org"}}'

I think my issue has to do with the placement of the user details to be authenticated against. As I'm not familiar with curl, I figured someone here might know which parameter type to apply it to.

<cfsavecontent variable="jsonString">
{"user": {"name": "Roger Wilco", "email": "roge@example.org"}}
</cfsavecontent>
<cfhttp url="https://test.zendesk.com/api/v2/users.json" method="post">
<cfhttpparam type="header" name="Content-Type" value="application/json">
<cfhttpparam type="header" name="Accept" value="*/*">
<cfhttpparam type="header" name="-u" value="email@email.com/token:*************************">
<cfhttpparam type="body" value="#jsonString#">
</cfhttp>

Any tips on how I can position / where I position the variables so I can authenticate would be awesome.

Thanks in advance.

Leigh
  • 28,765
  • 10
  • 55
  • 103
user125264
  • 1,809
  • 2
  • 27
  • 54
  • 1
    Possible duplicate of [Converting MailGun cUrl to Coldfusion](http://stackoverflow.com/questions/31925090/converting-mailgun-curl-to-coldfusion/31926343#31926343). In short, try using the "username" and "password" attributes of `cfhttp`. Side note, do not roll your own JSON in the real code :) Better to use serializeJSON (or something similar) which automatically handle things like escaping. – Leigh May 04 '17 at 01:59
  • Thanks alot, i wasnt aware of the username / password fields in cfhttp, i really should have looked into that. :) – user125264 May 04 '17 at 06:38
  • Heh.. I am not very familiar with `curl` either, but ... when it doubt, start with the documentation ;-) [curl options](https://curl.haxx.se/docs/manpage.html) and [cfhttp docs](https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-g-h/cfhttp.html). – Leigh May 04 '17 at 15:10
  • except serializeJSON may change the case of your keys depending on how you define structs. Something to be aware of. Also, keep in mind that different CFML engines do this case conversion differently. Again just something to keep in mind when the output from serializeJSON may be consumed by a case sensitive language. e.g. Java Script. – M.Scherzer May 13 '17 at 03:59

0 Answers0