CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • .NET client for the CiviCRM API (proof of concept)
Pages: [1]

Author Topic: .NET client for the CiviCRM API (proof of concept)  (Read 865 times)

johanv

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 5
  • #chiro #geek #linux #beer
    • my homepage
  • CiviCRM version: 4.7.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.x
.NET client for the CiviCRM API (proof of concept)
September 08, 2013, 01:04:52 pm
Hello all,

I created a proof of concept for a CiviCRM client in .NET using WCF. I thought I might share this for those who are interested: https://github.com/johanv/civicrm.net

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: .NET client for the CiviCRM API (proof of concept)
September 08, 2013, 06:37:39 pm
Hey, good idea!

Quote
I would have preferred to declare it like this: ... This way, WCF sends the contact info as xml (or json) in the post data of the request. But CiviCRM cannot handle this.

I don't know anything about WCF, but... the REST API should accept JSON document if it's embeded in the "json" field, e.g.

Code: [Select]
http://example.com/sites/all/modules/civicrm/extern/rest.php
  ?entity=Contact
  &action=create
  &json={"contact_type":"Individual","first_name":"Alice","last_name":"Alison"}

At a high-level, the submission is still sent with x-www-form-encoded, but most of the data is encoded with JSON. Do you think that's enough?

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: .NET client for the CiviCRM API (proof of concept)
September 08, 2013, 10:41:14 pm
You need to post (http get only works for read actions like get, getcount...) on Tim's example.

Otherwise, the json param works the same.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

johanv

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 5
  • #chiro #geek #linux #beer
    • my homepage
  • CiviCRM version: 4.7.x
  • CMS version: Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.x
Re: .NET client for the CiviCRM API (proof of concept)
September 16, 2013, 08:21:28 am
Sorry for the late reply, I thought I turned on notifications for this thread, but it seems I did not :-)

By default, if you send data to a REST service with WCF, WCF asserts that the actual data has to be in the body of the post request, and not in the URL.
CiviCRM expects the data to be in the URL, so I had to code around this. Which is not a big problem.

At the moment, my code handles adding/changing contacts and addresses.

I had to do some more fiddling, because I had problems with non-existing birth/deceased dates. And the fact that the root element of returned data is always called ResultSet, independently of the type of the results, required me to implement another strange hack to deserialize the data.

It all seems to work. But if you are reading this, and you know something about WCF, I would be very grateful if you could take a look at the code.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: .NET client for the CiviCRM API (proof of concept)
September 16, 2013, 02:52:10 pm
Hi,

At least on the latest versions, civi works the same for post and get. in fact, every "destructive" actions have to be carried over post (everything but get) as the http gods intended.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • .NET client for the CiviCRM API (proof of concept)

This forum was archived on 2017-11-26.