Reference a connectorstatemap in the body of the request

Which IIQ version are you inquiring about?

8.4p1

How can I reference the connectorStateMap in the body of the post of the operation?

For example i have the following in my before Operation Rule:

Map connectorStateMap = new HashMap();
    connectorStateMap.put("folderId", folderId);
    connectorStateMap.put("userID", userID);
    updatedInfoMap.put("updatedEndPoint", requestEndPoint);
    updatedInfoMap.put("connectorStateMap", connectorStateMap);
return updatedInfoMap;

How can i reference the folderId in the body of the operation:

I tried $application.folderId$ but it wont work.

{
"folderId": $application.folderId$
 }

but it’s not working.

Thank you in advance.

Hi @AhmedWaleed,

The requestEndPoint is accessible in the WebServiceBeforeOperationRule. It includes details such as the header, body, context URL, method type, response attribute map, and response code.

You can adjust the JSON body according to your needs. In your case, you can include the folderId in the JSON body.

Regards,
Arun

Hello @Arun-Kumar,

Thank you for your reply.

Could you elaborate how can I include folderId in the JSON Body?

1 Like

Add the below logic into before operation rule.

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

 Map requestMap = requestEndPoint.getBody();
// Assuming mapper is your ObjectMapper instance
String jsonBody = (String) requestMap.get("jsonBody");
JsonNode jsonNode = mapper.readTree(jsonBody);

// Create a new ObjectNode based on the existing jsonNode
ObjectNode updatedJsonNode = (ObjectNode) jsonNode.deepCopy();


String folderId = "yourFolderId"; // Replace with your actual folderId value
updatedJsonNode.put("folderId", folderId);

String updatedJsonBody = mapper.writeValueAsString(updatedJsonNode);

// Use updatedJsonBody as needed
requestMap.put("jsonBody",updatedJsonBody);
 requestEndPoint.setBody(requestMap);
2 Likes