Error 400 – Required field [LastName] missing
-
When creating a new User, which creates a Contact in Salesforce and sends the FirstName, LastName, and user_email fields, I get the following error:
URL: https://eu16.salesforce.com/services/data/v43.0/sobjects/Contact
Message: Required fields are missing: [LastName]
Code: 400
Any ideas what the issue could be? LastName is being passed.
-
Sometimes this happens when a WordPress field is not stored until after the Salesforce API call has been made. So for example, when a WordPress post is created, it stores its core data before it stores meta fields. If a meta field’s value is required to create the item in Salesforce, this can fail. This is simply because WordPress stores that first batch of data before it stores its meta fields.
But with the core user object, it stores the default first and last name fields at the beginning and thus it is able to create a contact, unless you’re using another plugin to store those fields. If you are, you’ll need to use the default fields for that to work.
Hi Jonathan,
I’m using Ultimate Member to create the user, but it puts the data in the default WordPress fields.
Do you know of a workaround? It’s a great plugin but this one issue is preventing it working perfectly.
@atomicjack While this plugin does not include extensive code to support third party plugins, I’ve done some investigating into Ultimate Member to see if we could support it without a lot of extra code.
What I’ve determined is that when a user registers, Ultimate Member uses its own methods of storing data, somewhat bypassing the standard WordPress methods (particularly, their user insert method ignores first and last name values at the time of user insert). While they do have abundant hooks, and I thought maybe it would work to use one of those hooks, it does not.
While I think we’d consider including such code if it worked (for example if we could call their
um_user_registerhook for users with the plugin installed), there doesn’t appear to be anything we can do at this time.Thanks for looking into it, really appreciate it.
In this case, is there a way I can call the plugin (via code) to manually push to Salesforce after? I assume this will also need to remove the Mapping Error for it to be successful.
After a user is created in Ultimate Member, there is a hook I currently use to add a custom meta field. I could potentially use this to re-attempt the push to Salesforce, this time being successful as I’m using normal WordPress functions at this point, as the user has already been created.
@atomicjack Actually it does seem like the
um_user_registerhook might work. I need to do a lot of testing on this before I release a plugin update, but here’s what seems like it could work right now. That is, if Ultimate Member is enabled, it uses the hook and it can successfully create a user, and if the plugin is not enabled it works as it was before.I haven’t tested with any more than email, first, last. It’s possible there would be issues there. But it does pass those fields, and it can update them.
Anyway if you’re comfortable with GitHub, you can see the commit here. Feel free to test. If I can be sure that it’s equally reliable with and without the Ultimate Member plugin installed, I’ll release it as a plugin update.
Perfect. I’ll give that a run in the morning – hopefully it works!
Just tested. Unfortunately, it still throws an error of: Provided external ID field does not exist or is not accessible:
But also now get this 405 error:
Message: HTTP Method ‘PATCH’ not allowed. Allowed are GET,HEAD,POST
@atomicjack Normally this error happens when it’s trying to update a record that does not exist, rather than to create a new record.
To see if that’s happening, you should probably delete all the mapping error rows from the plugin settings, so you can start over.
I’ve deleted all Mapping Errors and tried again – it resulted in the same errors as in my previous post.
Message: HTTP Method ‘PATCH’ not allowed. Allowed are GET,HEAD,POST
@atomicjack okay. I am not sure what causes that one. PATCH is always related to an update request instead of an insert, so it seems to be calling for an update when it shouldn’t be. In any case I can’t reproduce that at all.
I’ll keep testing this fix as I have time. I’m inclined to think there’s still some existing mapped data your install doesn’t like, but I’m not sure what to tell you until I can see the same issue.
Think I got it working. It was due to me using the wrong function, I was adding a custom meta field after registration, but I see there’s a function to add it before it saves the details. That, along with your patch, gets it working.
Thanks!
Great. I’ll release it as a plugin update as soon as I can do some thorough testing (with/without cron, with/without ultimate member installed, with/without additional profile fields off the top of my head).
The topic ‘Error 400 – Required field [LastName] missing’ is closed to new replies.