CallIONAPI
Purpose
A unified interface that sends HTTP requests to IONAPI. The interface manages HTTP methods, headers, request bodies, content negotiation, and response decoding.
- HTTP methods: GET, POST, PUT, DELETE, PATCH (via HttpMethodType).
- Base URL: The API relative Path as per ION API documentation.
e.g. for PLM Process PLMPROCESS/api. For IDM IDM/api etc.
- Defaults: The string-returning overloads assume Content-Type = application/json and Accept = application/json.
- Encoding: The string overloads decodes the response as UTF-8. For other encodings, use the byte[] overload and decode manually.
- Errors: AN exception is thrown.
- GET/DELETE bodies: This parameter is not used in most cases. A null or an empty value is provided unless the endpoint allows a request body.
Overload 1
Purpose
For Get Request
You can send a request with an optional text body (e.g., JSON) and receive a UTF-8 string response.
The JSON or text-based requests can be sent without custom headers.
Syntax
string CallIONAPI(HttpMethodType httpMethodType, string apiPath, string body
= "");
Return Value
The string decodes the response as UTF-8.
Parameters
- httpMethodType (required) — HTTP verb.
- apiPath (required) — Relative ION API path.
- body (optional, default: "") — Request body as string (e.g., JSON).
Examples
string json = CallIONAPI(HttpMethodType.GET,
"/PLMPROCESS/api/ITEM/IT001");
string payload = "{\"class\":\"Item-1\"}";
string json = CallIONAPI(HttpMethodType.POST,
"/PLMPROCESS/api/ITEM/IT001", payload);
Note
- The script uses Content-Type: application/json and Accept: application/json by default.
- The system throws HttpRequestException error when there is a failure.
Overload 2
Purpose
A binary request payload is sent, and a UTF-8 string response is received. This request can be used when the body is serialized to bytes.
Syntax
string CallIONAPI(HttpMethodType httpMethodType, string apiPath, byte[]
body);
Return Value
The string decodes the response as UTF-8.
Parameters
- httpMethodType (required)
- apiPath (required)
- body (required) — Request body as byte[] (file bytes or pre-encoded JSON).
Examples
byte[]Bytes = ……………..;
string result = CallIONAPI(HttpMethodType.PUT, "ANYIONAPI/api/SENDBYTES", Bytes);
Note
- Defaults to Content-Type: application/json, Accept: application/json.
- This method is used for simple API calls where no custom headers are required and when JSON is pre-serialized to bytes or a binary data is passed with JSON response.
Overload 3
Purpose
A text request with custom headers is sent and a UTF-8 string response is received. This request can be used for authorized JSON calls.
Syntax
string CallIONAPI(
HttpMethodType httpMethodType,
string apiPath,
Dictionary<string, string> httpRequestHeaders,
string body = ""
);
Return Value
The string decodes the response as UTF-8.
Parameters
- httpMethodType (required)
- apiPath (required)
- httpRequestHeaders (optional) — e.g., additional headers.
- body (optional, default: "") — Request body as string.
Examples
var headers = new Dictionary<string,string> {
["X-Correlation-Id"] = Guid.NewGuid().ToString() };
string payload = "{\"status\":\"active\"}";
string resp = CallIONAPI(HttpMethodType.POST,
"ANYIONAPI/api/v1/items/10/status", headers, payload);
Note
- Defaults to Content-Type: application/json and Accept: application/json.
- The system throws HttpRequestException error when there is a failure.
Overload 4
Purpose
The API returns raw bytes. You can use the API for binary payloads, file transfers, non-JSON formats, or non-UTF encodings.
Syntax
byte[] CallIONAPI(
HttpMethodType httpMethodType,
string apiPath,
Dictionary<string, string> httpRequestHeaders,
object body,
string contentType,
string accept
);
Show more lines
Return Value
The method returns the response as a byte []. The caller can decide to decode or store.
Parameters
- httpMethodType (required)
- apiPath (required)
- httpRequestHeaders (optional) null if not needed
- body (optional) — Supported:
- string sent as text with contentType
- byte[] sent as raw bytes
- POCO serialized according to contentType (e.g., JSON)
- null no body
- contentType (required) — Request MIME type.
- accept (required) — Expected response MIME type(s).
Examples
Download a PDF
C#
var headers = new Dictionary<string,string> { ["CUSTOM_HEADER"] =
"CUSTOM_HEADER" };
byte[] pdf = CallIONAPI(HttpMethodType.GET,
"ANYIONAPI/api/GetPDFReports/123", headers,null,accept: "application/pdf");
Upload a file
C#
var headers = new Dictionary<string,string> { ["SAP_HEADER"] = $"HEADER" };
byte[] file = …….;
byte[] resp = CallIONAPI(
HttpMethodType.POST,
" ANYIONAPI/api/sendFile ",
headers,
file,
contentType: "application/pdf",
accept: "application/json"
);
string resultJson = Encoding.UTF8.GetString(resp);
Send a POCO as JSON
C#
var headers = new Dictionary<string,string> { ["CUSTOM HEADER "] = "VALUE" };
var model = new { ITEM_CODE = "XYZ", qty = 5 };
byte[] bytes = CallIONAPI(
HttpMethodType.POST,
" ANYIONAPI/api/PostData",
headers,
model,
contentType: "application/json",
accept: "application/json"
);
string json = Encoding.UTF8.GetString(bytes);
- This method is used for file uploads and downloads (PDF, images, CSV, XML).
- This method can be used for non-JSON cases also.
- This method can be usef for application/pdf, image/*, text/csv, application/xml.