Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all
iam trying to post the below body data to data base through REST api
the test connection is working fine abd able to create single record
[
{
"dcId": 770,
"year": 2022,
"month": 1,
"serviceName": "VSI Silver",
"networkName": "ESF",
"demandAttr": {
"OSI": 236.795
}
}
]
when i try this with WIthConnection ,the script throwing the below error, any one help on this
Unexpected character encountered while parsing value: D. Path '', line 0, position 0.
script :
Let vRequestBody ='[';
Let vRequestBody = vRequestBody&'{';
Let vRequestBody = vRequestBody&'"dcId":778,';
Let vRequestBody = vRequestBody&'"year":2022,';
Let vRequestBody = vRequestBody&'"month":1,';
Let vRequestBody = vRequestBody&'"serviceName":"VSI Silver",';
Let vRequestBody = vRequestBody&'"networkName":"ESF",';
Let vRequestBody = vRequestBody&'"demandAttr":{';
Let vRequestBody = vRequestBody&'"OSI":236.795';
Let vRequestBody = vRequestBody&'}';
Let vRequestBody = vRequestBody&'}';
Let vRequestBody = vRequestBody&']';
let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34));
LIB CONNECT TO 'REST_helius_PostMethod';
RestConnectorMasterTable:
SQL SELECT
"__KEY_root",
(SELECT
"dcId",
"year",
"month",
"serviceName",
"networkName",
"__KEY_data",
"__FK_data",
(SELECT
"OSI",
"__KEY_demandAttr",
"__FK_demandAttr"
FROM "demandAttr" PK "__KEY_demandAttr" FK "__FK_demandAttr")
FROM "data" PK "__KEY_data" FK "__FK_data"
)
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(
BODY "$(vRequestBody)"
);
any help qlikadmins
Does this work when you don't use WITH CONNECTION and have that payload in the BODY of the REST_helius_PostMethod connection?
Are you sure that concatenating all of the parts of vRequestBody give you exactly what you are after? If you do an EXIT SCRIPT; after the let statements and then look at the contents of the variable in the variables dialog does it give you what you expect? My guess is that it is missing carriage returns, which may be required.
Actually, scrolling down in the error message will show you what is actually being passed.
Have you tried the code not using the variable, but putting the whole payload in the BODY of the WITH CONNECT in the code. Does this work?
Are you sure that the way that you escape double quotes is to have double-double quotes? This is not something I have tried.
Have you tried just not using double quotes at all in the payload?
It is entirely possible that this connector does not allow you to do the update that you wish. The Qlik connector and syntax can not be aware of what is required for every API that is out there. It's more likely to work for a GET endpoint than a POST, because the Qlik load script is primarily there to ingest data into Qlik.
Hope that helps.
Steve