API3
sfeek at April 5th, 2017 11:31 — #1
I am using the Ruby Client code from Github.
My test program below logs in enough to get a Contact ID, but cannot do a PUT operation due to auth errors.
Do I have to authenticate differently to PUT instead of GET?
Do I have to relogin for each request?
Do I have to do something with the params portion of the .put method?
Does the PUT method of the Ruby Client have a bug?
I have included the output as well. I even output the URL string for the PUT operation to prove that it performed the GET properly to acquire the Contact ID. I verified it via the Web Browser API
Any suggestions?
Ruby Code:
require './ruby-client/lib/onepageapi'
require 'json'
apiconnection = OnePageAPI.new("my username", "mypassword") # Create the connection
apiconnection.login # Login
jobj=apiconnection.get("contacts.json") # Create a json object of the list of contacts
id = jobj["data"]["contacts"][0]["contact"]["id"] # Get the Contact ID of the first contact
urlstring = "contacts/#{id}.json?partial=1&first_name=Shane" # New url string to change the first name to Shane
puts urlstring # Show the url on the screen
puts JSON.pretty_generate(apiconnection.put(urlstring)) # Do a PUT operation to update the contact info, showing results to th$
apiconnection.logout # logout
Output:
contacts/58e3f456efa9dd1617757585.json?partial=1&first_name=Shane
{
"status": 400,
"message": "Invalid auth token",
"error_name": "invalid_auth_token",
"error_message": "Authorization token is invalid",
"errors": {
}
}
liam at April 5th, 2017 11:54 — #2
Hi Shane,
You will need to send the PUT/POST params as a post body, not a query string. Pass a hash as the second param to the put method
urlstring = "contacts/#{id}.json?partial=1"
apiconnection.put(urlString, {first_name: 'Shane'})
The ruby-client is working fine for me, so this will probably fix it for you.
Kind regards,
Liam
sfeek at April 5th, 2017 11:58 — #3
I figured it out. Appears that the older Ruby Client does not work so well. I installed the OnePageCRM gem and the following code works fine.
require 'onepagecrm'
require 'json'
apiconnection = OnePageCRM.new("my user name", "my password") # Create the connection
jobj=apiconnection.get("contacts.json") # Create a json object of the list of contacts
id = jobj["data"]["contacts"][0]["contact"]["id"] # Get the Contact ID of the first contact
urlstring = "contacts/#{id}.json?partial=1" # New url string to do a partial update
puts urlstring # Show the URL on the screen
puts apiconnection.put(urlstring,{'first_name':'Shane'})["message"] # Do a PUT operation to update the contact info and show status
Powered by Discourse, best viewed with JavaScript enabled