I’ve seen time and time again issues with the set_relationship call in the SOAP and REST web services, when people would think they are doing all the right things in making this call to create a relationship between the two records, only to be given the sad feedback of:
Success: 0 Failures: 1
This can be one of the more confusing web services error messages, since often times it seems like you are doing the right thing and there’s not much in the way of feedback on what went wrong.
So looking at all of the issues I have seen people have using this call, I’ve found it’s usually something fairly simple that is causing the problems. Here’s the list of things to check for when you are trying to set a relationship between records and it’s not working.
- Make sure that the two modules have a relationship between them. While this seems like a no-brainer, you’d be surprised how often people forget about this.
- You need to specify the programmatic name of the module rather than the display name. Custom modules and a few out of the box modules like Targets and Cases are places people run into problems here and use the display name of the module as the second parameter to set_relationship instead of what the name of the module is in the code. So for the Cases module, you’d use ‘aCases‘, and Targets would be ‘Prospects‘.
- The fourth parameter must be the name of link field in the module’s vardefs, not the name of the target module or the relationship. This tends to be the most confusing part for people, as finding this out requires you to dig into the module’s vardefs.php file for more details, as you need to find a field of type ‘link’ that the ‘relationship’ field matching the name of the relationship between the modules. You can find the relationship name in Studio by looking at the ‘Relationships’ screen in Studio for the module.
- Try doing the relationship in reverse. Sometimes the module only defines the link field on one side of the relationship, so in these cases just reversing the order in which you are setting the relationship can make it work.
If you have anyone other tips for solving set_relationships issues, feel free to let us know in the comments.