working on the square API to get a refresh token, running into an issue with a JSON array but not sure what to do about it. There are two records in mydb and the first one works correctly and does the insert, the second go round fails when it goes to get "contents" from cf_1.GetContent to populate the fields for the next update to the db.
cf_1.getcontent() is concatenating the values from the for each banana array.
I tried ce_close() as you can see in the code and setting the value manually but again when it calls the value from the header its a concatenated value from both records, my guess is if I had 25 values for each banana I would see 25 values returned in the header. To me it looks like the TCP keepalive is doing justs that even though I am closing the curl connection ( or am I?)
I just want to run the curl command for each merchant_id, get the contents back from square and update my DB
Hopefully this will make sense to somebody here who can guide me in the right direction. I did think about waiting until the whole thing runs and use a json array to then plow through each value and perform all updates but it seems like it would be easier to just re-use the curl cmd and it certainly seems like we do this all the time when sending multiple emails, or sms using curl...
Here is a copy of the xbasic code with some modified values for security sake
Any ideas would be greatly appreciated!
cf_1.getcontent() is concatenating the values from the for each banana array.
I tried ce_close() as you can see in the code and setting the value manually but again when it calls the value from the header its a concatenated value from both records, my guess is if I had 25 values for each banana I would see 25 values returned in the header. To me it looks like the TCP keepalive is doing justs that even though I am closing the curl connection ( or am I?)
I just want to run the curl command for each merchant_id, get the contents back from square and update my DB
Hopefully this will make sense to somebody here who can guide me in the right direction. I did think about waiting until the whole thing runs and use a json array to then plow through each value and perform all updates but it seems like it would be easier to just re-use the curl cmd and it certainly seems like we do this all the time when sending multiple emails, or sms using curl...
Here is a copy of the xbasic code with some modified values for security sake
Code:
function getnewoauth as c (e as p) dim getnewoauth as c 'debug(1) dim cn as sql::Connection dim result as l = .f. dim args as sql::Arguments dim rs as sql::ResultSet dim sqlstm as c dim vResult[0] as p dim merchid as c dim flag_1 as l dim slist1[0] as c = [ "Square-Version: 2022-08-23" , "Content-Type: application/json" ] result = cn.open("::Name::Connection1") sqlstm = "SELECT * FROM squaredata" result = cn.Execute(sqlstm) rs = cn.ResultSet merchid = rs.ToPropertyArray(vResult) debug(1) for each banana in vResult f.client_id = "sq0iyow" f.client_secret = "sq0csthK0Bc" f.grant_type = "refresh_token" f.refresh_token = banana.refresh_token js = json_generate(f) posted_fields = js dim ce as extension::Curl dim jso as extension::JSON dim cf_1 as extension::CurlFile ce = extension::Curl.Init() ce.setOpt("BUFFERSIZE",102400) ce.setOpt("URL","https://connect.squareup.com/oauth2/token") ce.setOpt("HTTPHEADER",slist1) ce.setOpt("USERAGENT","curl/7.81.0") ce.setOpt("MAXREDIRS",50) ce.setOpt("CAINFO",a5.Get_Exe_Path()+"\caroot\ca-cert.pem") ce.setOpt("CAPATH",a5.Get_Exe_Path()+"\caroot") ce.setOpt("PROXY_CAPATH", a5.get_exe_path() + "\caroot") ce.setOpt("CUSTOMREQUEST","POST") ce.setOpt("FTP_SKIP_PASV_IP",1) ce.setOpt("TCP_KEEPALIVE",1) dim f as p dim js as c dim posted_fields as c ce.setOpt("POSTFIELDS",posted_fields) ce.setOpt("POSTFIELDSIZE_LARGE", len(posted_fields) ) ce.SetOpt("FILE",cf_1) flag_1 = ce.Exec() if flag_1 then dim headers as c dim contents as c = "Failed" headers = cf_1.GetHeaders() contents = cf_1.GetContent() end if jso.setJson(contents) dim mytoken as c mytoken = jso.getProperty("access_token") dim myrefresh as c myrefresh = jso.getProperty("refresh_token") dim expdate as c expdate = jso.getProperty("expires_at") dim merchid as c merchid = jso.getProperty("merchant_id") args.Add("mytoken",mytoken) args.Add("reftoken",myrefresh) args.Add("expdate",expdate) args.Add("merchid",merchid) updatedata = "UPDATE alphanwcopro.mysquaredata set access_token = :mytoken, expiration_date = :expdate WHERE merchant_id = :merchid" cn.execute(updatedata,args) ce.close() next ce.close() cn.close() end function
Comment