API call sequence in order to update entries between modules that have a relationship

Hello,

First of all I am sorry if this question has already been asked and answered. I wasn’t able to find anything similar, but if you have, feel free to redirect me there.

I am using SuiteCRM Version 7.13.4.

I have created a Many-to-Many relationship between the Projects module and another custom module that I created, named Dependencies.

I wish to simulate the process of adding a new Dependency and then linking it to a specific Project, using API calls. If I understand correctly I will need to:

  1. First send an API call that will create a new Dependency entry.

  2. Get the ID of that entry.

  3. Use this ID in a second API call, in order to link it with one of my Projects.

Is this correct?
Are there any API call examples that I can refer to in order to help me?

Thank you

ok, Try this.

Step 1: Create a new Dependency entry

Send an API call to create a new Dependency entry. Make sure to note the ID of the created record for future use.

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
	"name": "Your Dependency Name",
	"other_fields": "other_values"
  }' \
  -u username:password \
  http://your_suitecrm_url/service/v4_1/rest.php -v

Step 2: Get the ID of the created Dependency

Capture the ID from the response of the first API call. Typically, SuiteCRM will include the ID in the response JSON.

Step 3: Link the Dependency with a specific Project

Send a second API call to link the Dependency with a specific Project using the IDs of both records.
Example API call (using cURL):

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
	"module1": "Projects",
	"module1_id": "project_id",  // Replace with the actual Project ID
	"module2": "Dependencies",
	"module2_id": "dependency_id",  // Replace with the actual Dependency ID
	"link_field_name": "dependencies",  // Replace with the actual link field name
	"name_value_list": {}
  }' \
  -u username:password \
  http://your_suitecrm_url/service/v4_1/rest.php -v

Note: Always ensure the security of your API calls by using HTTPS and secure authentication methods. If possible, consider using OAuth2 for authentication in a production environment.

@Urvi thanks for your helpful answers!

I edited your post - I hope you don’t mind - please check my edits by clicking the “pencil” :pencil2: icon, to learn the kinds of formatting available in these forums.

:+1:

1 Like