I'm busy integrating onTime API to one of our clients website. All my API requests are successfull (GET, POST).
But for some reason POSTING a new /contacts just always give me:
Missing required fields: customer.id, first_name, last_name
Although they are there correctly inserted as per the API documentation.
This is my json encoded data I'm posting:
{"item":{"customer":{"id":6},"first_name":"CUSTOMER_NAME","last_name":"CUSTOMER_SURNAME","email":"someemail#website.com","phone":"1231231234"}}
I'm out of ideas.
PS: I use an API class so the posting platform uses the same method throughout the project, and all my other posting of data works 100% it is just this action that is giving me issues.
Ok,
I figured this one out also thanks to a fellow developer:
The problem was that the json object was encapsulated in the item{} object. This is incorrect. It should only be a single object of data like:
{"customer":{"id":6},"first_name":"CUSTOMER_NAME","last_name":"CUSTOMER_SURNAME","email":"someemail#website.com","phone":"1231231234"}
Related
I am completely new to salesforce and its API(s). I have rails application with an existing users table. I need to start synchronizing data over to our new salesforce account.
Currently, I am trying to convert existing 'Leads' to 'Accounts'. As I understand it, this can only be accomplished with the old SOAP API. I am trying to use the rforce gem.
I am able to authenticate according to the documentation, like this:
binding = RForce::Binding.new \
'https://www.salesforce.com/services/Soap/u/20.0'
binding.login \
'email', 'password' + 'token'
Then I try to call the convert lead action like this:
binding.convertLead "leadId" => lead_id
but I get the error:
:errors=>{:message=>"valid leadId is required", :statusCode=>"INVALID_CROSS_REFERENCE_KEY"}
I know for sure that the leadId I am using is indeed valid, because I have actually retrieved it just prior to this call (using the REST API).
I believe that the problem may be that the rforce gem is not structuring the underlying SOAP call properly -- which I think is being described in this SO post.
I appreciate any additional information anyone can provide.
Thanks very much,
Matt
Try using lead.Id instead of lead_Id.
The input hash needs to have the key 'leadConverts':
binding.convertLead 'leadConverts' => { 'leadId' => lead_id, 'convertedStatus' => 'Status' }
You may need to add other arguments depending on what is required to convert a Lead on your Salesforce platform.
I have a mobile app that accesses a server running a Rails 3.x app. The data is exchanged in JSON format.
I have a rather complicated issue, that I going to try and simplify here.
In one scenario, the mobile app posts a new sale record to the database which includes an update to an existing order record. To achieve this as a single HTTP request, it passes the order record attributes update as part of the new sale record via nested attributes.
The Rails model for Sales includes the following:
attr_accessible :product_id, :order_id, :order_attributes
accepts_nested_attributes_for :order, :update_only => true
The Rails routings are standard.
As the http request to post the sale will create a new record (i.e. it does not include an existing sale_id), I use HTTP POST.
I can post a new sale record (without the order record update) just fine.
However, when I include the nested attributes to update the order record, I get 404 'not found'.
I suspect that this is because the nested update of the existing order includes an 'id' and therefore should actually be a PUT (to route correctly).
To help diagnose the issue, I've tried changing existing working non-nested POSTs of sales (that don't include an id) to be PUT requests, and in that case, it does break the functionality, and I do get a 404. This suggests to me that the server would indeed report PUT/POST confusion as a 404.
To be clear I can successfully post updates using nested attributes in other circumstances using the same code, so I'm confident that it's not the actual attribute encoding that is the problem.
I'd appreciate thoughts on whether this could be the issue, and if so what I can do about it.
Thank you.
I'm trying call the "lookup" method on multiple users on Twitter. According to the documentation, this is feasible.
http://apiwiki.twitter.com/w/page/24142947/Twitter-REST-API-Method:-users-lookup
I'm calling the method and stringing together 5 IDs separated by commas.
Here's my call:
access_token = twitter_oauth_access_token(user.twitter.token, user.twitter.secret)
response = access_token.get("/users/lookup.json?user_id=#{ids.join(',')}")
ActiveSupport::JSON.decode(response.body)
I've verified that there are multiple IDs in the "ids" variable. The problem is that no matter how I call it, I only get the first one in the list back. So the call is successful, but it doesn't give me the list of results as the documentation says.
Any idea what I might be doing wrong?
I figured it out. The API URL was incorrect. It should've been:
access_token.get("/1/users/lookup.json?user_id=#{ids.join(',')}")
instead of
access_token.get("/users/lookup.json?user_id=#{ids.join(',')}")
I'm playing with the authlogic-example-app and I'm failing to get the email address from the OpenID provider (in my case: Google and Yahoo) when I register a user, resp. I get an empty response instead of an email address (check the comments in code below).
This is how my user model looks like (everything else looks like the "with_openid"-branch of the authlogic-example-app mentioned above). Besides the missing 'email', the openid-authentication-process works as expected:
class User < ActiveRecord::Base
acts_as_authentic do |c|
# not needed because I use OpenID
c.validate_login_field = false
# avoid failed validation before OpenID request
c.validate_email_field = false
# this one sets 'openid.sreg.required=email'
c.required_fields = [:email]
end
private
# overwriting the existing method in '/lib/authlogic_openid/acts_as_authentic.rb'
def map_openid_registration(registration)
# this is my problem: 'registration' is an empty hash
self.email ||= registration[:email] if respond_to?(:email) && !registration[:email].blank?
end
end
Any idea how to solve this? Has anyone here done this before using authlogic? Or even better: Do you have a working example?
Update: I checked the Google Account Authentication API and compared the request submitted by authlogic (using ruby-openid-gem and openid-authentication-plugin) with the example requests on the Google Account Authentication API docs:
Example request to authenticate and fetch email address by Google:
https://www.google.com/accounts/o8/ud
?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.return_to=http%3A%2F%2Fwww.example.com%2Fcheckauth
&openid.realm=http%3A%2F%2Fwww.example.com%2F
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup
&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ext1.mode=fetch_request
&openid.ext1.type.email=http%3A%2F%2Faxschema.org%2Fcontact%2Femail
&openid.ext1.required=email
Request submitted by my appliation:
https://www.google.com/accounts/o8/ud
?openid.assoc_handle=AOQobUcdICerEyK6SXJfukaz8ygXiBqF_gKXv68OBtPXmeafBSdZ6576
&openid.ax.mode=fetch_request
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select
&openid.mode=checkid_setup
&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1
&openid.realm=http%3A%2F%2Flocalhost%3A3000%2F
&openid.return_to=http%3A%2F%2Flocalhost%3A3000%2Faccount%3Ffor_model%3D1%26_method%3Dpost%26open_id_complete%3D1
&openid.sreg.required=email
While debugging the whole setup, I've found out that the openid-authentication-plugin never receives an email in the response it receives from the openid provider, this at least explains why the registration hash in my user-model is empty...
UPDATE: If you're playing around with authlogic and openid, don't forget to check out the latest railscast on this subject!
As nobody could help me, I helped myself. :-)
The short answer to my question is:
c.required_fields = [:email,"http://axschema.org/contact/email"]
Using this line, the application requests the email-address using sreg and ax (request-type supported by Google).
You can find a more detailed answer and a working implementation of authlogic-openid with the Javascript OpenID-Selector right here:
http://github.com/vazqujav/authlogic_openid_selector_example/
While this pointed me in the right direction, what I needed was:
c.openid_required_fields = [:email,"http://axschema.org/contact/email"]
This pulled in the email and set it.
# fetch email by ax
c.openid_required_fields = [
"http://axschema.org/contact/email",
"http://axschema.org/namePerson/first",
"http://axschema.org/namePerson/last",
"http://axschema.org/contact/country/home",
"http://axschema.org/pref/language"
]
This fetches in multiple values as specified # http://code.google.com/apis/accounts/docs/OpenID.html#Parameters
Though I'm still unable to fetch in the country name... name, email, language works perfectly!
Test against an OpenID server you control, since it'll let you debug every part of the OpenID sequence. There are no guarantees that Google's OpenID provider is doing the right thing. Try checking against Verisign's server, since I'm pretty sure that one at least should do the right thing with the openid.sreg.required=email field.
Your code snippet looks right to me.
the thing is i am able to fetch the parameters from the provider but am not able to extract them from the response...
i have used OpenID::AX::FetchResponse.from_success_response(open_id_response)
as the object to hold the response... what method do i use to extract email,nickname,country,etc...
I've been attempting to hook a Rails application up to ActiveDirectory. I'll be synchronizing data about users between AD and a database, currently MySQL (but may turn into SQL Server or PostgreSQL).
I've checked out activedirectory-ruby, and it looks really buggy (for a 1.0 release!?). It wraps Net::LDAP, so I tried using that instead, but it's really close to the actual syntax of LDAP, and I enjoyed the abstraction of ActiveDirectory-Ruby because of its ActiveRecord-like syntax.
Is there an elegant ORM-type tool for a directory server? Better yet, if there were some kind of scaffolding tool for LDAP (CRUD for users, groups, organizational units, and so on). Then I could quickly integrate that with my existing authentication code though Authlogic, and keep all of the data synchronized.
Here is sample code I use with the net-ldap gem to verify user logins from the ActiveDirectory server at my work:
require 'net/ldap' # gem install net-ldap
def name_for_login( email, password )
email = email[/\A\w+/].downcase # Throw out the domain, if it was there
email << "#mycompany.com" # I only check people in my company
ldap = Net::LDAP.new(
host: 'ldap.mycompany.com', # Thankfully this is a standard name
auth: { method: :simple, email: email, password:password }
)
if ldap.bind
# Yay, the login credentials were valid!
# Get the user's full name and return it
ldap.search(
base: "OU=Users,OU=Accounts,DC=mycompany,DC=com",
filter: Net::LDAP::Filter.eq( "mail", email ),
attributes: %w[ displayName ],
return_result:true
).first.displayName.first
end
end
The first.displayName.first code at the end looks a little goofy, and so might benefit from some explanation:
Net::LDAP#search always returns an array of results, even if you end up matching only one entry. The first call to first finds the first (and presumably only) entry that matched the email address.
The Net::LDAP::Entry returned by the search conveniently lets you access attributes via method name, so some_entry.displayName is the same as some_entry['displayName'].
Every attribute in a Net::LDAP::Entry is always an array of values, even when only one value is present. Although it might be silly to have a user with multiple "displayName" values, LDAP's generic nature means that it's possible. The final first invocation turns the array-of-one-string into just the string for the user's full name.
Have you tried looking at these:
http://saush.wordpress.com/2006/07/18/rubyrails-user-authentication-with-microsoft-active-directory/
http://xaop.com/blog/2008/06/17/simple-windows-active-directory-ldap-authentication-with-rails/
This is more anecdotal than a real answer...
I had a similar experience using Samba and OpenLDAP server. I couldn't find a library to really do what I wanted so I rolled my own helper classes.
I used ldapbrowser to see what fields Samba filled in when I created a user the "official" way and and basically duplicated that.
The only tricky/non-standard LDAP thing was the crazy password encryption we have:
userPass:
"{MD5}" + Base64.encode64(Digest::MD5.digest(pass))
sambaNTPassword:
OpenSSL::Digest::MD4.hexdigest(Iconv.iconv("UCS-2", "UTF-8", pass).join).upcase
For the def authenticate(user, pass) function I try to get LDAP to bind to the domain using their credentials, if I catch an exception then the login failed, otherwise let them in.
Sorry, cannot comment yet... perhaps someone can relocate this appropriately.
#Phrogz's solution works well, but bind_simple (inside bind) raises an Net::LDAP::LdapError exception due to auth[:username] not being set as shown here:
https://github.com/ruby-ldap/ruby-net-ldap/blob/master/lib/net/ldap.rb
The corrected replaces:
auth: { method: :simple, email: email, password:password }
with:
auth: { method: :simple, username: email, password:password }
I began using ruby-activedirectory, and even extended it/fixed a few things, hosting judy-activedirectory in Github.
Doing the next iteration, I've discovered ActiveLdap has a much better code base, and I'm seriously contemplating switching to it. Does anyone have personal experience with this?
Have you checked out thoughtbot's ldap-activerecord-gateway? It might be something for you to consider...
http://github.com/thoughtbot/ldap-activerecord-gateway/tree/master