Jimmy Christian · Jul 19, 2019 go to post

Thats a good suggestion.

I will check that option out and see how to use POSTMAN as a proxy. Will let you know.

Thank you Jeffrey.

Jimmy Christian · Jul 19, 2019 go to post

Thanks Sourabh.  I was able to put some debug variables and troubleshoot the issue.

Appreciate your help.

Regards,

Jimmy Christian

Jimmy Christian · Jul 17, 2019 go to post

Thank you Neerav.

The message i pasted doesnt look like  JSON. 

Looks like i may have to use some STRING functions to parse it. 

I will let you know once i get the right specs of the response. Thank you for time.

Regards,

Jimmy Christian.

Jimmy Christian · Jul 16, 2019 go to post

Thank you. Yes, i am going to find out in a day or two.

Appreciate your help and time.

Jimmy Christian · Jul 16, 2019 go to post

The issue is the API  is not set up yet on the project which i am working.

But the specs has the JSON PAYLOAD as request and then the response is what i pasted above. 

So i am trying to get the code ready to parse in the meantime until the API is set up. Hopefully i will have something to work with POSTMAN as soon as API is set up.

Once i receive the response , i need to parse it for any error and then shutdown the operation.  At the most i can convert the response to string and check for error.

Jimmy Christian · Jul 16, 2019 go to post

Thank you Eduard.

So the message i posted is a response to an API call i make with JSON payload.

So i was assuming that the response would be JSON and i can try to parse it.

But if it is not a JSON, is there a utility to parse it or i need to use the provided STRING functions like ZSTRIP and so on?

Thanks,

Jimmy christian.

Jimmy Christian · Jul 16, 2019 go to post

Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT

I tried dynamic objects but gives me an error, unless i am not doing it correctly or if syntax is not correct.

Set objStream = objHttpResponse.Data
     Set json =""
     While ('objStream.AtEnd) {
          Set json = json _ objStream.ReadLine()
  
     }

set iter = json.%FromJSON().%GetIterator()
   while iter.%GetNext(.key , .value )
      {
       write "key = "_key_" , value = "_value,!
             }

Jimmy Christian · Jul 16, 2019 go to post

Good Morning Danny,

I appreciate your help. After  changing the names i was able to  make the POST calls using SEND. Worked perfectly ! Thank you for your time.

Yes,  looks like .Send has some more configurable parameters in the HttpRequest object we send.

In the same context, would you be able to know how to set a Basic Authoriztion using User and Pass while making the call ?

Seems like i have to make Credentials using ENSEMBLE.

Than set the httprequest.username and httprequest.password using that credential object.

Please let me know if you have any information.

Thank you for time.

Regards,

Jimmy Christian.

Jimmy Christian · Jul 15, 2019 go to post

Thank you Danny for help.

Yes this worked. I did not create a seperate HttpRequest but just used the PostURL method as below.

Set tSC=..Adapter.PostURL(tURL,.tHttpResponse,,pRequest1.%ToJSON()).

The code you provided is very helpful. Especially when i have to include the content type while making the http request.

The Adapter object does not have that ContentType property.

By the way i am also trying to understand when to use the PostURL or .Send or  SendFormDataArray method to make a http request?

Do they provide same functionality ? If you have information and can provide me will be much appreciated.

Thank you

Jimmy Christian.

Jimmy Christian · Jul 11, 2019 go to post

Hello Eduard,

i was able to convert the HttpResponse.Data to String and than to the Dynamic Object. Worked great. Thank you.

On the same line, i need to ask you of any template or suggestion to send a JSON data to a REST API.

For eg. below is the JSON

{"name":"abcdefghi","salary":"123","age":"23"}

How do i send it to  http://testing.restapiexample.com/api/v1/createemployee with POST request using the  set tSC=..Adapter.PostURL(tConfig.URL,.tHTTPResponse,,pRequest)

Below code is not working.

Set pRequest=."{"name":"abcdefghi","salary":"123","age":"23" }"

Your help will be appreciated.

Thanks,

Jimmy Christian.

Jimmy Christian · Jul 10, 2019 go to post

Yes, Thank you. I just corrected the URL and it works now. Thank you Robert.  One more question if you can assist in this context.

So the response message i got back is in the HttpResponse object.

How can i convert the HttpResponse.Data property to JSON and parse the values. Since the data i received is Stream, is there a way i can convert the stream to Dynamic Objects and parse  it?

Thank you.

Jimmy Christian.

Jimmy Christian · Jun 27, 2019 go to post

Yes, I did. 

       set tRequest=##class(Ens.StreamContainer).%New(pInput)
      do tRequest.%Save()
      set tSC = ..SendRequestAsync(..TargetConfigNames,tRequest)

Thanks,

Jimmy Christian.

Jimmy Christian · Jun 26, 2019 go to post

Hello Eduard,

I used %Stream.FileCharacter to resolve the error on Operation which is complaining that "No Stream contained in StreamContainer Request".

I am going to use the JSON serialization once i  refer to some document about it. 

Thank you for help.

Jimmy Christian.

Jimmy Christian · Jun 26, 2019 go to post

Thank you Aldo for checking this out. I tried to make it much simpler by using what you suggested. I was hoping the operation to  accept it since pInput is a Stream.

But still the same error. Operation does not find STREAM in the ENS. StreamContainer.

Class Hospital.ApptListFileService Extends Ens.BusinessService
{
Parameter ADAPTER = "EnsLib.File.InboundAdapter";
Parameter SETTINGS = "TargetConfigNames";
Property TargetConfigNames As Ens.DataType.ConfigName;
Property SentMsg As %FileCharacterStream;
Method OnProcessInput(pInput As %FileCharacterStream, Output pOutput As %RegisteredObject) As %Status
{
set tSC = $$$OK
    set pInput.LineTerminator=$c(10)
try 
{
while 'pInput.AtEnd {
          do pInput.ReadLine()
         
          set tRequest=##class(Ens.StreamContainer).%New(pInput)
  
          set tSC = ..SendRequestAsync(..TargetConfigNames,tRequest)
}

Jimmy Christian · Jun 18, 2019 go to post

Thank you Stephen. I will check the link you provided for more understanding on REST.

Jimmy Christian · Jun 18, 2019 go to post

Hello Evgeny,

Yes this worked perfectly. I think i did select %ALL role, but did not click on assign but only SAVED it.

Thank you for all your help. But looks like at some point once i familiarize myself with this web and rest app build, i will need to learn more about security..

Thanks,

Jimmy Christian.

Jimmy Christian · Jun 18, 2019 go to post

Thank you Nigel for the suggestions. Agreed, but since this is just a standalone training env, and for now i only want to have a hands on REST development, i think assigning %All role should be fine to see the output of the code ! Security will be my next hands on once i am familiar with the REST architecture.

Jimmy Christian · Jun 3, 2019 go to post

Yep. Select INTO works great if the source and target tables are in same NAMESPACE. I need to copy the data across namespaces, for which i  have already some another method. 

But i found that copying recordset would also work, since once the object is created i can easily write to another table on a different "NAMESPACE". Only issue is to write to a target table from a recordset i need to loop it and am not aware of a straightforward copy.

Jimmy Christian · May 31, 2019 go to post

Thank you Robert. But looks like i am running into another issue where data is lost and i am unable to create table.

I really would prefer to find out if there is a way to copy directly a RecordSet to a table or any other faster method rather than looping through the entire Recordset.

Jimmy Christian · May 17, 2019 go to post

Vitaliy, This is great !

The code works fine now. Appreciate your help and time.

I have to put some filters on the columns now, which i think i have to use the QueryInfo Object.

Thank you !

Regards,

Jimmy Christian.

Jimmy Christian · May 17, 2019 go to post

Hello Vitaliy,

Thank you for your time. This works good. Issue is that i only see the first page of the results.

Even after adding the tableNavigatorBar, it still shows only one page  and not all the results. I have more than 30,000 rows to display on the page. Let me know.

Thanks,

Jimmy

Jimmy Christian · May 16, 2019 go to post

I cannot share globals on the namepsace i am working on.

Actually i was able to retrieve data from Namespace2  working on a callback method for recordset which the table  is using. But now issue is zenpage only shows the first page.

Will try to find out a reason why the page is hanging. It could be that i have to flip back to Namespace1 once i get the recordset.

Thanks.

Jimmy Christian · May 14, 2019 go to post

Thanks Neerav.

I am referring to the zenpage call back methods, which are called on a zenpage event.

Problem is i cannot create any views in namespace2.

Jimmy Christian · May 14, 2019 go to post

Thanks Neerav.

I still believe  we can do in the code by using a callback method. I am not sure how to use it.

Jimmy Christian · May 8, 2019 go to post

Thanks John. This was helpful. I had to correct the password for that service.

Issue is resolved.

Jimmy Christian · Apr 23, 2019 go to post

Thank you . This is perfect !

I just tweaked it little bit

SET testingddl="CREATE TABLE xxxxxxx"_$USERNAME_"(TNAMESPACE CHAR(100),TINTERFACE CHAR(100),TPORT INT)"
s  ret=##class(%SQL.Statement).%ExecDirect(,.testingddl)
 

Jimmy Christian · Apr 23, 2019 go to post

Thank you all. At this time, i will not be able to map the USER db to rest of it. But i will try to call support .