Gopi2000
(Gopi S)
December 12, 2024, 7:40am
1
Hi,
I’m trying to update the payload using provisioning plan attribute and it ends up in 400 bad request, invalid or empty payload
here’s how my payload looks like in postman
[{
"roleId": 3,
"productId": "T"
}]
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.tools.GeneralException;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
Map payload = new HashMap<>();
if (plan != null && plan.getAccountRequests() != null) {
for (AccountRequest accountRequest : plan.getAccountRequests()) {
List<AttributeRequest> attributeRequests = accountRequest.getAttributeRequests();
if (attributeRequests != null) {
for (AttributeRequest attributeRequest : attributeRequests) {
if ("roles-products".equalsIgnoreCase(attributeRequest.getName())) {
String rolesProductsValue = (String) attributeRequest.getValue();
if (StringUtils.isNotEmpty(rolesProductsValue)) {
String[] parts = rolesProductsValue.split(":");
if (parts.length == 2) {
String roleId = parts[0];
String productId = parts[1];
String jsonBody = "[{\"roleid\":\"" + roleId + "\", \"productid\":\"" + productId + "\"}]";
payload.put("jsonBody", jsonBody);
}
}
}
}
}
}
}
2 Likes
schattopadhy
(SHANTANU CHATTOPADHYAY)
December 12, 2024, 7:50am
2
@Gopi2000 you can try this if it works
“[\r\n {\r\n "roleId": 3,\r\n "productId": "T"\r\n }\r\n]”
Rohit_Sahu
(Rohit Sahu)
December 12, 2024, 9:07am
3
Hi @Gopi2000 ,
Your code looks fine to me. Please add the following line to your code after <payload.put(“jsonBody”, jsonBody)> line:
requestEndPoint.setBody(payload);
I hope this will work.
2 Likes
Gopi2000
(Gopi S)
December 12, 2024, 11:11am
4
Hi Shanthanu,
I updated the payload code snippet but still same error occurs…
Gopi2000
(Gopi S)
December 12, 2024, 11:19am
5
HI @Rohit_Sahu ,
I updated the code snippet to include the requestEndPoint
, but the error still persists(400 bad request).
When pushing the payload from a rule, are there any specific conditions or steps that need to be followed on the HTTP operation side?
The body is expected to be empty initially since we are constructing and sending the body directly from the rule. Is this the correct approach?
Rohit_Sahu
(Rohit Sahu)
December 12, 2024, 12:12pm
6
Hi @Gopi2000 ,
Make sure you have patched that rule with the appropriate HTTPS operation.
The body is expected to be empty initially since we are constructing and sending the body directly from the rule. Is this the correct approach? — Yes
Please try the below code:
import sailpoint.connector.webservices.WebServicesClient;
import sailpoint.connector.webservices.EndPoint;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import org.json.JSONObject;
import sailpoint.tools.Util;
import sailpoint.tools.GeneralException;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
Map payload = new HashMap<>();
if (provisioningPlan != null && provisioningPlan.getAccountRequests() != null) {
for (AccountRequest accountRequest : provisioningPlan.getAccountRequests()) {
List<AttributeRequest> attributeRequests = accountRequest.getAttributeRequests();
if (attributeRequests != null) {
for (AttributeRequest attributeRequest : attributeRequests) {
if ("roles-products".equalsIgnoreCase(attributeRequest.getName())) {
String rolesProductsValue = (String) attributeRequest.getValue();
if (StringUtils.isNotEmpty(rolesProductsValue)) {
String[ ] parts = rolesProductsValue.split(":");
if (parts.length == 2) {
String roleId = parts[0];
String productId = parts[1];
String jsonBody = "[{\"roleid\":\"" + roleId + "\", \"productid\":\"" + productId + "\"}]";
payload.put("jsonBody", jsonBody);
requestEndPoint.setBody(payload);
log.info("-------------------Payload------------------------------"+payload);
}
}
}
}
}
}
}
Also, check the CCG log to see if it is printing the payload value.
7 Likes
Gopi2000
(Gopi S)
December 12, 2024, 2:39pm
7
Thank you for your responses, @schattopadhy and @Rohit_Sahu ! I implemented both of your suggestions, and after fine-tuning the code, it worked perfectly. I really appreciate your help!
1 Like
system
(system)
Closed
February 10, 2025, 2:39pm
8
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.