I ran into a problem when I created the variable. I specify "Infer from a sample JSON payload" scheme:
{
"Source": "string",
"Data": {
"Request": {
"Top": 0,
"Skip": 0
}
}
}
and also filling in the Default Value (because you can't do a SetProperty in DataMapping task without it):
{
"Source": "",
"Data": {
"Request": {
"Top": 0,
"Skip": 0
}
}
}
Then this value is changed in the DataMapping task and passed to the body Rest Api call task
The problem is that I need to get an integer (0), but it sends a double (0.0).
Api response error:
{"apiRequest.Data.Request.Top":["Input string '0.0' is not a valid integer. Path 'Data.Request.Top', line 16, position 16."],"apiRequest.Data.Request.Skip":["Input string '0.0' is not a valid integer. Path 'Data.Request.Skip', line 17, position 17."]}
As I see in the received json scheme:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Data": {
"type": "object",
"properties": {
"Request": {
"type": "object",
"properties": {
"Top": {
"type": "number"
},
"Skip": {
"type": "number"
},
}
}
}
}
}
}
Is it possible to explicitly specify integer type in json scheme, because when I change type to integer - I get an error:
Failed to save changes. Please try again later. Error: Message: instance type (number) does not match any allowed primitive type (allowed: ["integer"]) Schema Path:"/properties/Data/properties/Request/properties/Skip" Message: instance type (number) does not match any allowed primitive type (allowed: ["integer"]) Schema Path:"/properties/Data/properties/Request/properties/Top"
The second part of the question - Can I not set a default value for a variable? If I need to create a variable and then set values for it, I use the DataMapping task Json.SetProperty() method. But if the value hasn't been set to default (for example: "[]" for an array) - an error happens.
'Failed to fetch the input value. Reason: [Failed to evaluate transform expression value. Reason: [Value null does not represent a JSON array.]]'
Solved! Go to Solution.
Q. Is it possible to explicitly specify integer type in json scheme, because when I change type to integer.
A. You can change the schema version to draft-07 then the integer validation should succeed and you will no longer get this error.
"$schema": "http://json-schema.org/draft-07/schema#"
Q. Using JSON.SetProperty without default value
A. I was able to use JSON.SetProperty without any default value. Here is a sample data mapping:
If you are still not able to get JSON.SetProperty work, can you ping me your data mapping and JSON variable schema ?
Q. Is it possible to explicitly specify integer type in json scheme, because when I change type to integer.
A. You can change the schema version to draft-07 then the integer validation should succeed and you will no longer get this error.
"$schema": "http://json-schema.org/draft-07/schema#"
Q. Using JSON.SetProperty without default value
A. I was able to use JSON.SetProperty without any default value. Here is a sample data mapping:
If you are still not able to get JSON.SetProperty work, can you ping me your data mapping and JSON variable schema ?
You can also try Data Transformer Script Task to prepare your body for Rest Api Call Task by converting into String. The script would look something like this:
local f = import "functions";
// Assuming your variable is named as "jsonPayload"
local jsonPayload = std.extVar("jsonPayload");
// Perform the modifications
local modifiedPayload = {
"Source": "string",
"Data": {
"Request": {
"Top": 123,
"Skip": 456
}
}
}
// Map the result to integration variable called "restCallBody"
{
restCallBody: f.toString(modifiedPayload)
}
Let me know if you have any questions.