Complex Prepared statement deployment through RESTAPI

Hi Team,

We are in a process of automating the prepared statements through Azure Devops CI/CD pipeline to Couchbase Capella using RESTAPI. We are facing issues while deploying the complex prepared statements. We would need your suggestion for the below Prepared statement query to deploy through RESTAPI.

Prepared statement:

curl.exe -k -v -w “%(http code}” -X POST “https://*.cloud.couchbase.com:18093/query/service” -u username:password -H “Content-Type: application/json” -d
"{“statement”: ‘PREPARE testprepared12 AS
SELECT META(lb).id AS key,
{ “field1” AS type,
“value1” AS Src_type,
lb.field3 AS acct_nb,
LTRIM (lb_deposit_rt, “0”) AS rtgnb,
CONCAT2(‘|’, lb.deposit_act, LTRIM (lb.deposit_rt, “0”)) AS act_rtg_nb,
bnk.BankNumber AS bknb,
bnk.BankCode AS bnk.cd,
cta_ref.CustomerNumber AS cstmr.nb,
“C” AS tx_tp,
trancd_ref.txcd AS tx_cd,
lb.batch_amount AS tx_amt,
lb.deposit_date AS prcss_dt,
lb.deposit_date AS eff_dt,
ref.BhProdCategory AS BhProdCategory,
ref.DetailBaiCede AS dtlbaicode,
ref.DetailBaiCodedesc AS dtlbaidesc,
ref.TranCodeDesc AS desc
{
“ref_nb”: “”,
“bk_nb”: “”
} AS desc1,
{
“ref_nb”: “”,
“bk_ref”: “”,
“desc_1”: “”,
“desc 2”: “”,
“desc_3”: “”,
“desc_4”: “”,
“desc_5”: “”,
“desc 6”: “”
} AS desc2,
CLOCK_TZ(“US/Central”) AS cretd_on,
“proc1” AS cretd_by
} AS value
FROM
bucket01.scp01.coll01 lb
INNER JOIN bucket01.scp02.coll01 bnk
ON LTRIM(lb.deposit_rt, “0”) = bnk.RtNumber
INNER JOIN bucket01.scp02.coll02 trancd.ref
ON UPPER (cancd_cef.Ip.sNm)=‘TESTBOX’
INNER JOIN bucket01.scp02.coll03 ref
ON ref.txCd = ref.txCode
INNER JOIN bucket01.scp02.coll04 to cta_ref
ON lb.dpt_acct = cta_ref.AccountNumber
AND LTRIM(lb.deposit_rt,“0”) = cta_ref.RtgNumber
AND UPPER (cta_ref.Status) = “А”
WHERE
meta(lb).id = $meta_id’ }”

Error:

curl: (3) nested brace in URL position.

It looks like nested brace is not accepting inside the PREPARED statement creation. Could you please suggest how to create complex nested braces prepared statements via RESIAPI commands.

You have an opening parenthesis and a closing brace. They are mis-matched. And it seems that a space in ‘http code’ is problematic. When you post, use the ‘code’ formatting so it doesn’t change your quotes.

Start simple and add to it. Note that double-quotes within ‘statement’ will need to be escaped and that key is a keyword and must be escaped with back-tick.

curl -k -v -w "%{http_code}" -X POST "https://localhost:18093/query/service" -u Administrator:password -H "Content-Type: application/json" -d \
'{"statement": "PREPARE testprepared12 AS SELECT META(lb).id AS `key`, { field1 AS f } from lb WHERE meta(lb).id = 1" }'

In addition

This is not valid syntax with in the object construct it must be “field”: value

{“type”:”field1”, ….}