APIPost
You can use the APIPost function to create new records or data by sending a request to the server with a JSON payload.
When to use
You can use this function to:
- Create new Item, Formulas, Projects, or other Optiva objects programmatically from within the scripts or workflows.
- Create or update multiple records in batch processes, data migrations, or automated workflows.
When not to use
You cannot use this function when you are working within the objects context and can set properties directly without making server calls (reduces overhead).
Syntax
FsSrvAppResponse APIPost(string objSymbol, string ObjectKey, string inputJSON);
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| objSymbol | string | Optional |
The symbol of the object.
Note: You can use empty quotation marks ("") for the current workflow symbol.
|
| objKey | string | Optional |
The key of the object.
Note: You can use empty quotation marks ("") for the current workflow symbol.
|
| inputJSON | string | Yes | The JSON-formatted string that contains the data to save. |
Return Value
The application returns an FsSrvAppResponse object containing:
- The success or failure status.
- The status information about the request.
- Any error messages if the request fails.
Examples
- Example 1
-
APIPost create FSITEM and report API errors.
using System; using Formation.Shared.Defs; class ActionScript : FcProcFuncSetEventWF { public long wf_start() { try { // JSON payload string jsonString = "{ \"FSITEM\": [{ \"ITEM_CODE\": \"MKPTEST2\", \"DESCRIPTION\": \"Mkp2 Desc\" }] }"; // Call APIPost against the current symbol (_OBJECTSYMBOL) and target key "MKPTEST2" FsSrvAppResponse createresponse = APIPost(_OBJECTSYMBOL, "MKPTEST2", jsonString); if (createresponse == null) { MessageList("APIPost returned null response."); return 0L; } // If the API reported an error, log summary and then individual error messages if (createresponse.hasErrors) { MessageList("Error Occurred while creating"); APIResponseErrors responseError = createresponse.ProcessErrors(); if (responseError != null && responseError.errors != null) { foreach (string errorMessage in responseError.errors) { MessageList(errorMessage); } } return 0L; } else { MessageList("Item created"); return 1L; } } catch (Exception ex) { MessageList("Exception in wf_start: " + ex.Message); return 0L; } } }