Body: <p>I'm trying to create inherited memberships in the <code>civicrm_post</code> hook. I feel like there is something wrong with the api itself. The API doesn't even recognize my only membership id in the database.</p>
  
  <p><strong>Here is the one membership record in the db:</strong></p>
  
  <p><a href="https://i.sstatic.net/hFUk6.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hFUk6.jpg" alt="enter image description here"></a></p>
  
  <p><strong>When I try to create the API create statement, I can't even select the only ID in the database, which is 4:</strong></p>
  
  <p><a href="https://i.sstatic.net/zaxSk.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zaxSk.jpg" alt="enter image description here"></a></p>
  
  <p><strong>My actual code looks like this:</strong></p>
  
  <p><a href="https://i.sstatic.net/KjwHI.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KjwHI.jpg" alt="enter image description here"></a></p>
  
  <p><strong>The resulting logs from that function are here:</strong>
  <a href="https://i.sstatic.net/oi0tc.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/oi0tc.jpg" alt="enter image description here"></a></p>
  
  <p>When submitting the form, I get no error on the front end and you can see the log showing no error as well, but nothing gets submitted to the membership table. I'd also like to note that in another hook (the <code>civicrm_postProcess</code> hook), I am successfully taking values from a contribution form and creating relationships between an organization and the primary member submitting the form and the additional members provided in the form values.</p>
  
  <p><strong>The main question is, How can I add new, inherited memberships to the members table with code?</strong></p>
  
  <p>This question is based on part of an extension I am making to try to solve this problem:</p>
  
  <p><a href="https://civicrm.stackexchange.com/questions/35121/membership-for-group-of-people-one-payer">Membership for Group of people. One payer</a></p>
  
  <p>I'm using Joomla! 3.9.16 CiviCRM 5.23.3</p>
  
  <p><strong>Extra Information / Edits:</strong></p>
  
  <p><strong>Here is my <code>relationship</code> table, showing that there are relationships to the primary members already:</strong></p>
  
  <p><a href="https://i.sstatic.net/E6d5U.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/E6d5U.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Here is my <code>relationship_type</code> table:</strong></p>
  
  <p><a href="https://i.sstatic.net/pZQtE.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pZQtE.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Here is my <code>membership_type</code>:</strong></p>
  
  <p><a href="https://i.sstatic.net/0T5RZ.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0T5RZ.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Here is my organization contact from the <code>contact</code> that holds the parent membership:</strong></p>
  
  <p><a href="https://i.sstatic.net/b6uiP.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/b6uiP.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Here is the individual contact from the <code>contact</code> table that I am trying to give an inherited membership:</strong></p>
  
  <p><a href="https://i.sstatic.net/LcXKE.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LcXKE.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Edit - Membership Type Screenshot:</strong></p>
  
  <p><a href="https://i.sstatic.net/Dh12y.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Dh12y.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.sstatic.net/8VCWS.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8VCWS.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Relationship Types :</strong></p>
  
  <p><a href="https://i.sstatic.net/XbjNu.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XbjNu.jpg" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-16T14:36:14.927Z
Comments.Text: The related memberships are also automatically created/deleted by civicrm. They are based on the relationship of the primary member. So for example when we have a family membership the head of the household, household members are also a member when the household has the membership.
  
  So it might be that your membership gets deleted by core civicrm as there is no relationship in your membership type or with the primary member.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-16T18:49:08.883Z
Comments.Text: @Jaap  I added some more images to show that I do have relationships with the primary member. What did you mean by relationship in "membership type"?
Comments.UserDisplayName: Kurt Leadley
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-20T07:06:43.827Z
Comments.Text: When you configure your membership type (and only when creating a new one) you can select which related people should get a related membership. This is based on a relationship. See also the documentation: https://docs.civicrm.org/user/en/latest/membership/defining-memberships/#membership-types
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-20T07:41:55.063Z
Comments.Text: @JaapJansma-CiviCooP  When I look at my settings for Membership Type, I can see that I have it assigned to "Group Member of" already.  Which is a custom relationship. Maybe I need to change that since I need a parent and then child membership types?
Comments.UserDisplayName: Kurt Leadley
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-20T07:55:15.073Z
Comments.Text: @JaapJansma-CiviCooP I added three more screenshots. I thought I had correctly implemented what you mentioned in the last comment you sent to me. Is there anything obviously wrong?
Comments.UserDisplayName: Kurt Leadley
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-21T07:32:42.640Z
Comments.Text: Regarding what I see from your screenshot. The individual is the member and every organization gets a related membership. So at the membership type you need the relationship name from B -> A (Group member for). Then you assign the primary membership on the organisation and every individual with this relationship will get a related membership.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Tags: <civimember><extension><hooks>
Title: Creating membership with civicrm_api3, inherited membership
ThreadText: # Creating membership with civicrm_api3, inherited membership
  
  (Asked by: username_0 on 2020-04-16)
  
  I'm trying to create inherited memberships in the `civicrm_post` hook. I feel like there is something wrong with the api itself. The API doesn't even recognize my only membership id in the database.
  
  **Here is the one membership record in the db:**
  
  [![enter image description here](https://i.sstatic.net/hFUk6.jpg)](https://i.sstatic.net/hFUk6.jpg)
  
  **When I try to create the API create statement, I can't even select the only ID in the database, which is 4:**
  
  [![enter image description here](https://i.sstatic.net/zaxSk.jpg)](https://i.sstatic.net/zaxSk.jpg)
  
  **My actual code looks like this:**
  
  [![enter image description here](https://i.sstatic.net/KjwHI.jpg)](https://i.sstatic.net/KjwHI.jpg)
  
  **The resulting logs from that function are here:**
  [![enter image description here](https://i.sstatic.net/oi0tc.jpg)](https://i.sstatic.net/oi0tc.jpg)
  
  When submitting the form, I get no error on the front end and you can see the log showing no error as well, but nothing gets submitted to the membership table. I'd also like to note that in another hook (the `civicrm_postProcess` hook), I am successfully taking values from a contribution form and creating relationships between an organization and the primary member submitting the form and the additional members provided in the form values.
  
  **The main question is, How can I add new, inherited memberships to the members table with code?**
  
  This question is based on part of an extension I am making to try to solve this problem:
  
  [Membership for Group of people. One payer](https://civicrm.stackexchange.com/questions/35121/membership-for-group-of-people-one-payer)
  
  I'm using Joomla! 3.9.16 CiviCRM 5.23.3
  
  **Extra Information / Edits:**
  
  **Here is my `relationship` table, showing that there are relationships to the primary members already:**
  
  [![enter image description here](https://i.sstatic.net/E6d5U.jpg)](https://i.sstatic.net/E6d5U.jpg)
  
  **Here is my `relationship_type` table:**
  
  [![enter image description here](https://i.sstatic.net/pZQtE.jpg)](https://i.sstatic.net/pZQtE.jpg)
  
  **Here is my `membership_type`:**
  
  [![enter image description here](https://i.sstatic.net/0T5RZ.jpg)](https://i.sstatic.net/0T5RZ.jpg)
  
  **Here is my organization contact from the `contact` that holds the parent membership:**
  
  [![enter image description here](https://i.sstatic.net/b6uiP.jpg)](https://i.sstatic.net/b6uiP.jpg)
  
  **Here is the individual contact from the `contact` table that I am trying to give an inherited membership:**
  
  [![enter image description here](https://i.sstatic.net/LcXKE.jpg)](https://i.sstatic.net/LcXKE.jpg)
  
  **Edit - Membership Type Screenshot:**
  
  [![enter image description here](https://i.sstatic.net/Dh12y.jpg)](https://i.sstatic.net/Dh12y.jpg)
  
  [![enter image description here](https://i.sstatic.net/8VCWS.jpg)](https://i.sstatic.net/8VCWS.jpg)
  
  **Relationship Types :**
  
  [![enter image description here](https://i.sstatic.net/XbjNu.jpg)](https://i.sstatic.net/XbjNu.jpg)
  
  **Tags:** civimember, extension, hooks
  
  > **Comments:**
  > **username_1**: The related memberships are also automatically created/deleted by civicrm. They are based on the relationship of the primary member. So for example when we have a family membership the head of the household, household members are also a member when the household has the membership.  So it might be that your membership gets deleted by core civicrm as there is no relationship in your membership type or with the primary member.  
  > **username_0**: @Jaap  I added some more images to show that I do have relationships with the primary member. What did you mean by relationship in "membership type"?  
  > **username_1**: When you configure your membership type (and only when creating a new one) you can select which related people should get a related membership. This is based on a relationship. See also the documentation: https://docs.civicrm.org/user/en/latest/membership/defining-memberships/#membership-types  
  > **username_0**: @JaapJansma-CiviCooP  When I look at my settings for Membership Type, I can see that I have it assigned to "Group Member of" already.  Which is a custom relationship. Maybe I need to change that since I need a parent and then child membership types?  
  > **username_0**: @JaapJansma-CiviCooP I added three more screenshots. I thought I had correctly implemented what you mentioned in the last comment you sent to me. Is there anything obviously wrong?  
  > **username_1**: Regarding what I see from your screenshot. The individual is the member and every organization gets a related membership. So at the membership type you need the relationship name from B -> A (Group member for). Then you assign the primary membership on the organisation and every individual with this relationship will get a related membership.  
  
  ---
  
  ## 0 answers
  
  