CallIONAPI

You can use the CallIONAPI function to send standardised HTTP requests to ION APIs. This function handles request construction, headers, body formatting, timeouts, and returns the response as text or raw bytes based on the use case.

When to use

You can use this function to:

  • Send requests to ION REST endpoints by using a single reusable function that manages HTTP methods, URL construction, headers, and timeout settings.
  • Send different payload types, such as strings, binary data, objects, and retrieve the response as text or a byte array.
  • Offer lightweight overloads for standard JSON calls and full control for custom headers, content types, and binary or file operations.

When not to use

You must not use this function if:

  • Advanced HTTP features are required.
  • Working outside the ION API conventions.

Syntax

  • String body, default JSON content type
    string CallIONAPI(HttpMethodType httpMethodType,string apiPath,string body = "",int timeoutSeconds = 60);
  • Binary body, default JSON content type
    string CallIONAPI(HttpMethodType httpMethodType,string apiPath,byte[] body,int timeoutSeconds = 60);
  • String body with custom request headers, default JSON content type
    string CallIONAPI(HttpMethodType httpMethodType,string apiPath,Dictionary<string, string> httpRequestHeaders,string body = "",int timeoutSeconds = 60);
  • Full control: custom headers, any body type, explicit content type + accept
    byte[] CallIONAPI(HttpMethodType httpMethodType,string apiPath,Dictionary<string, string>httpRequestHeaders,object body,string contentType,string accept,int timeoutSeconds = 60);

Arguments

Parameters Type Required Description
httpMethodType HttpMethodType Yes The HTTP method type used for the request. Possible values:
  • GET
  • POST
  • PUT
  • DELETE
apiPath string Yes The path portion of the ION API URL, for example, /PLMPROCES/api/......).
Note: The leading [/] is added if missing.
httpRequestHeaders Dictionary<string,string> No The additional HTTP headers for the request. The Authorization and Accept headers are set by the function and must not be included. Pass null if additional headers are not required.
contentType string No The MIME type of the request body. This parameter applies only to overload 4.
Timeoutseconds int No

The per-call timeout in seconds. The default value is 60.

Note: The value must be between 1 and 600.

Return Value

  • The API response body is returned as a string in JSON or text format.
    string CallIONAPI(HttpMethodType httpMethodType, string apiPath, string body = "", int timeoutSeconds = 60);
  • The API response body is returned as a string.
    string CallIONAPI(HttpMethodType httpMethodType, string apiPath, byte[] body, int timeoutSeconds = 60);
  • The API response body is returned as a string.
    string CallIONAPI(HttpMethodType httpMethodType, string apiPath, Dictionary<string, string> httpRequestHeaders, string body = "", int timeoutSeconds = 60); 
  • The raw API response body is returned as byte[] for files or non-text responses.
    byte[] CallIONAPI(HttpMethodType httpMethodType, string apiPath, Dictionary<string, string> httpRequestHeaders, object body, string contentType, string accept, int timeoutSeconds = 60);Side

Prerequisites

  • The ION API authorization is required.
  • The timeoutSeconds value must be between 1 and 600. This function is not suitable for long running operations.
  • The large request or response bodies, especially binary data, can impact performance because built-in streaming is not available.

Examples

Example 1
Read data using GET call for ITEM symbol.
using System; 
using Microsoft.VisualBasic; 
using System.Net.Http; 
using Formation.Shared.Defs; 
 
public class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        string json = CallIONAPI( 
            HttpMethodType.GET, 
            "PLMPROCESS/api/ITEM/ITEM_1", 
            "", 
            60 
        ); 
 
        MessageList(json); 
 
        return 0; 
    } 
} 
Description
Invokes an ION API GET endpoint to retrieve item data and displays the returned JSON response using MessageList for logging or debugging purposes.
Example 2
The object is created using POST call with HEADER in JSON body for ITEM symbol.
using System; 
using Formation.Shared.Defs; 
using System.Net.Http; 
public class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        string payload = "{\"FSITEM\": [{\"ITEM_CODE\": \"ITEM_API1\", \"DESCRIPTION\": 
\"ITEM DESC\"}]}"; 
 
        string json = CallIONAPI( 
            HttpMethodType.POST, 
            "PLMPROCESS/api/ITEM/ITEM_API1", 
            payload, 
            100 
        ); 
         MessageList(json); 
        return 0L; 
    } 
} 
Description
Sends a POST request to an ION API endpoint with a structured JSON payload containing item details (for example item code and description), processes the request within a specified timeout, and logs the API response using MessageList for verification and debugging.
Example 3
The object is created using POST call with HEADER & DTL tables in JSON body for SPECIFICATION symbol.
using System; 
using Formation.Shared.Defs; 
using System.Net.Http; 
 
public class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        string payload = 
"{\"FSSPECIFICATION\":[{\"SPECIFICATION_CODE\":\"SPEC_API_01\",\"VERSION\":\"0001\",\"DE
SCRIPTION\":\"SPEC_API_01\"}],\"FSSPECIFICATIONINGR\":[{\"ITEM_CODE\":\"ITEM_MK_1\",\"QU
ANTITY\":200,\"QUANTITY_LO\":10,\"QUANTITY_HI\":300,\"SUB_IND\":0,\"SCALE_IND\":0,\"LINE
_TYPE\":0,\"INSTRUCTION\":\"Created with 
API\"},{\"ITEM_CODE\":\"ITEM_MK_2\",\"QUANTITY\":10,\"QUANTITY_LO\":1,\"QUANTITY_HI\":10
0,\"SUB_IND\":0,\"SCALE_IND\":0,\"LINE_TYPE\":0}],\"FSSPECIFICATIONBYPROD\":[{\"ITEM_COD
E\":\"ITEM_MK_3\",\"QUANTITY\":20,\"QUANTITY_LO\":1,\"QUANTITY_HI\":19,\"SUB_IND\":0,\"S
CALE_IND\":0,\"LINE_TYPE\":2}]}"; 
 
        string json = CallIONAPI( 
            HttpMethodType.POST, 
            "PLMPROCESS/api/SPECIFICATION/SPEC_API_01\\001", 
            payload, 
            100 
        ); 
 
        MessageList(json); 
 
        return 0L; 
    } 
} 
Description
Sends a POST request to an ION API endpoint to create a specification record with associated ingredients and by-products, including structured quantity constraints, scaling rules, and instructions, then captures and logs the API response using MessageList for verification and debugging of the transaction outcome.
Example 4
Update object using PUT call for SPECIFICATION symbol.
using System; 
using Formation.Shared.Defs; 
using System.Net.Http; 
 
public class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        // string payload = "{\"FSITEM\": [{\"ITEM_CODE\": \"ITEM_API_MK\", 
\"DESCRIPTION\": \"ITEM DESC\"}]}"; 
        string payload = 
            
"{\"FSSPECIFICATIONBYPROD\":[{\"ITEM_CODE\":\"ITEM_MK_3\",\"QUANTITY\":200,\"QUANTITY_LO
\":1,\"QUANTITY_HI\":300,\"SUB_IND\":0,\"SCALE_IND\":0,\"ROW_ID\":1,\"LINE_TYPE\":2}]}"; 
 
        string json = CallIONAPI( 
            HttpMethodType.PUT, 
            "PLMPROCESS/api/SPECIFICATION/SPEC_MK/001", 
            payload, 
            600 
        ); 
 
        MessageList(json); 
 
        return 0L; 
    } 
} 
Description
Sends a PUT request to an ION API endpoint to update an existing specification record with by-product details (including quantity limits, row identification, and line type).
Example 5
Update object using PUT call for SPECIFICATION symbol.
using System; 
using Formation.Shared.Defs; 
using System.Net.Http; 
 
public class ActionScript : FcProcFuncSetEventWF 
{ 
    public long wf_start() 
    { 
        byte[] bytes = new byte[] 
        { 
            123, 34, 70, 83, 73, 84, 69, 77, 34, 58, 32, 91, 123, 34, 73, 84, 
            69, 77, 95, 67, 79, 68, 69, 34, 58, 32, 34, 65, 80, 73, 73, 84, 
            69, 77, 49, 52, 34, 44, 32, 34, 68, 69, 83, 67, 82, 73, 80, 84, 
            73, 79, 78, 34, 58, 32, 34, 73, 84, 69, 77, 32, 99, 114, 101, 97, 
            116, 101, 100, 32, 102, 114, 111, 109, 32, 98, 121, 116, 101, 34, 
            125, 93, 125 
        }; 
 
        string json = CallIONAPI( 
            HttpMethodType.POST, 
            "PLMPROCESS/api/ITEM/APIITEMMK11", 
            bytes, 
            90 
        ); 
 
        MessageList(json); 
 
        return 0L; 
    } 
}
Description
This is a POST API call where JSON is manually encoded into bytes and sent as raw payload, and the response is logged for debugging.

The flow of the program:

  1. Creating a binary payload
    byte[] bytes = new byte[] { 123, 34, 70, 83, 73, ... };
    • This is a byte-level representation of a JSON string.
    • If you decode it (ASCII/UTF-8), it becomes:
      { 
        "FSITEM": [ 
          { 
            "ITEM_CODE": "APIITEM14", 
            "DESCRIPTION": "ITEM created from byte" 
          } 
        ] 
      } 
      

    The payload is being manually converted into bytes, instead of writing JSON directly.

  2. Sending the API request
  3. Capturing the response
Example 6
Update object using PUT call for SPECIFICATION symbol.
{ 
  "FSITEM": [ 
    { 
      "ITEM_CODE": "APIITEM14", 
      "DESCRIPTION": "ITEM created from byte" 
    } 
  ] 
} 
Description
This is a POST API call where JSON is manually encoded into bytes and sent as raw payload, and the response is logged for debugging.

The flow of the program:

  1. Creates custom request headers
    var headers = new Dictionary<string, string> 
    { 
         ["X-Correlation-Id"] = Guid.NewGuid().ToString() 
    }; 
    Generates a unique correlation ID (GUID) for each API call, Adds it to the header.  
      "FSITEM": [ 
        { 
          "ITEM_CODE": "APIITEM14", 
          "DESCRIPTION": "ITEM created from byte" 
        } 
      ] 
    }

    The payload is being manually converted into bytes, instead of writing JSON directly.

  2. Build JSON payload using:
    • Specific header
    • Ingredients
    • By-products
  3. Calls the ION API

    This code is used to create a fully traceable API request (via correlation ID) to submit a structured specification with components and log the result.