How to use API call templates in a Novulo application to send data (e.g. products)

Hi, I managed to create and test an API call in the application to export products. How can I use it now on my products? And is it possible to trigger the call if my products have a specific status?

Hey Sven,

Happy to hear that you managed to configure M10074 and M7899 to send API calls :+1:
I understood that you want to achieve the following:

  • Send a call with multiple products in the body
  • Send multiple calls per product
  • Optional: View a history of all sent calls/products at the product/call

To send the calls, we will do the following:

  1. Determine the list of products to be sent
  2. Pass the list of products to “N_CallTemplate - Build, Execute, Process Call”
  3. Build the body based on the “products” parameter.
  4. Send a test call

Send a products calls

1. Determine the list of products to be sent

Write a custom expression that returns the list of products that you want to send. For example:

{products, this, status.id.equals(1)}

Customize your expression with the help of the expression debugger until the list contains only the products that you want to send.

2. Pass the list of products to “N_CallTemplate - Build, Execute, Process Call”

In order to send a call where the body contains 1 or more products, you have to pass the custom list of products to the process “N_CallTemplate - Build, Execute, Process Call”. This process is produced in M7899. It is the same process that is also behind the “Execute call” Test button on the page of the call collection.

“N_CallTemplate - Build, Execute, Process Call” has the following input parameters:
1. Call template: Pass the correct call template to the process. The call template should have an export definition or a data definition set to create the body that contains the product data.
2. Call account: Pass the correct call account that matches the call template, or leave it empty if you have properly linked the template to an account.
3. Parameters: This is a list of tuples that are used for multiple purposes, depending on the configuration of the call template. We will use this multipurpose parameter to pass your list of products.
The tuple list needs to have the following format:

[<“key”, value >, <“key2”, value2 >].

In your case, the tuple should contain a “products” key with the whole list as the value. This looks like this:

[<“products”, {products, this, status.id.equals(1)} >].

4. Call: This is an optional parameter that we won’t use in this example.

3. Build the body based on the “products” parameter.

You probably have defined a data definition to create a JSON body for the products.

  1. Open this data definition
  2. Add a new data definition parameter “products” to use it within your data definition:
  3. Place %products at the right data definition field to use it as a filter expression. For example, “this.in(%products)”
  4. The data definition parameter is automatically filled with the list of products that you determined in step 1 when you send a call.
  5. To test out whether the body is created properly, go to the call template collection and execute your call template. Do not forget to enter your custom parameter similar to the one below

[<“products”, {products, this, status.id.equals(1)} >]

4. Schedule the execution of the call

You can either call this process in a workflow, as a scheduled task or in your custom component.
I would recommend using scheduled task for debugging, as they can be configured/tested without having to wait for an update. To do so, follow these instructions: How to add a new scheduled task (geplande taak)

If you have any questions, feel free to ask.

Optional: View a history of all sent calls at the product

You might want to see a grid of all calls that have been executed for a product in a grid on the product page and vice versa, a grid with all products that are contained in a single call.
This is somewhat similar to what I built recently in M10355. You can open the component for inspiration. The difference here is that I do not have a many-to-many relationship between the call and the record to send. I have used a one-to-many relationship where each record has one call, but 1 call can contain multiple records.

You have to do the following:

  1. Create a new process to link a list of products to a new call (required for many-to-many)
  2. Add a products grid at the call page and a calls grid at the product page
  3. Execute the process for linking before building the body
  4. Send a test call
  5. View the list of calls that have been executed per product

1. Create a new process to link a list of products to a new call

To be able to show the history, we need to create a new record for linking the custom list of products to a new call. A “product call link” is a new record with only two fields. A search link to link a N_Product and a search link to link a N_Call.The records that we want to add should look like this:

Then, build a new process to generate these records:

Process name: N_Call - Link products based on parameters
Input parameters:

  • “call” of type N_Call
  • “parameters” of type “List<tuple<string, mixed>>” (Do not deviate from this name and type!)

Return parameters:

  • Success of type boolean
  • Error of type messages

The process should look something like this:

This process extracts your custom list of products from the “parameter” with the “TupleExtLookup” action (tuple extensions plugin) and then loops through your list of products. For each product, we will add a new record called “Product-call link” to the database, if it does not exist yet.

2. Add a products grid at the call page and a calls grid at the product page

  1. At the virtual page of the N_Call record, add a grid of products to a new tabbed panel within in your custom component. This way you can see which product where part of a call.
  2. Add the following filtering to the grid:

this.in({ productcalllinks, this.product, this.call.equals(parent) })

  1. At the virtual page of the N_Product record, add a grid of calls to a new tabbed panel within in your custom component. This way you can see which calls were sent for a product call.
  2. Add the following filtering to the grid:

this.in({ productcalllinks, this.call, this.product.equals(parent) })

  1. Deploy your component and also add “M10388 - Novulo Call template processes” to the composition, if you haven’t yet, for the next steps.

3. Execute the process for linking before building the call

Make sure that “M10388 - Novulo Call template processes” is part of your application.
Call template processes allow you to execute a custom process before/after building/processing a call. In our case, we will configure the execution of “N_Call - Link products based on parameters” right before building the body. This will create all “Product-Call Links” for the call that is beeing executed.

  1. Go to all settings > Process action definitions.

  2. Add a new process action definition for your custom process, like so:


    (1) Choose a proper description
    (2) If you have updated your application with the component that contains “N_Call - Link products based on parameters” your process should be available here as “n_call_link_products_based_on_parameters_…”
    (3) Click this button to ensure that the parameters are loaded
    (4) Double check that both parameters are there, as you defined the in step 3

  3. Open your call template

  4. Navigate to the grid “Call template processes”

  5. Add a new call template process:


    (1) Choose the trigger moment “Before building call”
    (2) Chose the process action definition that we defined in the previous step
    (3) Leave this as “true” for now.

  6. Open the parameter “call” and fill in “this” as an expression. Save it.

  7. We do not need to fill in anything for “parameters” because process parameters with the name ‘parameters’ and the return type ‘[<string,mixed>]’ cannot be defined manually. They are automatically set to the same ‘parameters’ as the parent process ‘N_CallTemplate - Build, Execute, Process Call’.

4. Send a test call

To test out whether “N_Call - Link products based on parameters” is executed properly, go to the call template collection and execute your call template. Do not forget to enter a parameter similar to this one

[<“products”, {products, this, status.id.equals(1)} >]

Double check whether, at the new call that you just created, the grid of “Products” is filled.
Also double check whether, at the page of the products that you just sent, the grid of “Calls” is filled.

3 Likes

As an addition, you might also want to check out this post about sending calls in a one-to-many relationship. Here, one call relates to one single purchase. The record type is interchangeable, the approach stays the same.

Hi Joachim,
I bumped into another issue now.
I wanted to send products to another platform where they ask for using “Content-Type” application/json-patch+json instead of just application/json.
To solve this I left this field on empty and tried to add it in config headers
image
but as I tested this, the response was that the content type can’t be left empty:
image

Hey :slight_smile:
I don’t know which version of 10074 you are currently using but if you use revision 96 or higher the headers that are sent become visible at the call record. Also I remember that there was a bug in the process that build the header.
Updating to revision 99 hopefully helps.

Hi,
I was already on v99 for that component.
The headers were shown like this:
image

Mh that does not look right.
Can you create an SR including a screenshot of the settings of your call template and the trace html file after clicking the button for executing a test call?

@SvenDR thank you for providing the trace data. The bug has been fixed in M10074 revision 100. This are the release notes:

PI51716 - Bugfix in “N_Call - Ensure “Content-Type” header”
The “Content-Type” header was not de duplicated correctly but only “Content-type” headers because the of a spelling mistake.
This has been fixed. Double check the spelling of custom “Content-Type” headers in your calltemplates after the update.