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:
|
| 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.
- 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.
- 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.
- 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.
- 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.
- 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:
- 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.
- Sending the API request
- Capturing the response
- Example 6
- Update object using PUT call for SPECIFICATION symbol.
- 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:
- 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.
- Build JSON payload using:
- Specific header
- Ingredients
- By-products
- 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.