Page 1 of 3

JSONWEBSRV.sqlrpgle

Posted: Wed Feb 21, 2024 9:58 pm
by freelance
Hi Scott,

On running this program with the website, the pointer goes here - on-error; and program ends.
So, please advise. -Parag

Code: Select all

50        /free                                     
51         exec SQL set option naming=*SYS;         
52         *inlr = *on;                             
53                                                  
54         monitor;                                 
55            uri = %str(getenv('www.tiktok.com')); 
56         on-error;                                                  <-- here                 
57            success = *off;                       
58            errmsg = 'invalid URI!';              
59            exsr JSON_Start;                      
60            exsr JSON_Finish;                     
61            exsr JSON_Save;                       
62            return;

Re: JSONWEBSRV.sqlrpgle

Posted: Wed Feb 21, 2024 11:24 pm
by jonboy49
You may have misunderstood the use of getenv(). The text 'REQUEST_URI' is a literal and asks that the URI from which the request originated be retrieved. You cannot use it to specify an arbitrary URI (in your case www.tiktok.com) - it wouldn't know what to do with it.

getenv is used to retrieve information about the message received from the program's caller. For example CONTENT_LENGTH and
CONTENT_TYPE. There are a fixed number of options including what was the URI that caused the program to be initiated.

In the case of Scott's sample program JSONWEBSRV the URI is being retrieved so that the code can extract the customer, start date and end date from the URI. The program was called by the Apache web server in response to a request in the form http://whatever/rest/jsonwebsrv/495/20100901/20100930 where "whatever" is the name of the server hosting the service. This is spelled out in the program's comments.

Since you have clearly modified Scott's code, it would be a good idea to tell us what exactly you are trying to do - then we can make suggestions.

Re: JSONWEBSRV.sqlrpgle

Posted: Thu Feb 22, 2024 3:56 pm
by freelance
Hi there,

We are trying to post our AS/400 IFS file data to the website tiktok.com which may not be the exact link. But, all the same, we wanted to see what kind of response we getting. In our case, pointer moved to on-error and the statement thereafter errmsg = 'invalid URI!'; is what we got.

It passed thru -
httpStatus = 500

EVAL bigCharVar
BIGCHARVAR =
....5...10...15...20...25...30...35...40...45...50...55...60
1 '{"success":false,"errmsg":"invalid URI!","list":[]} '
61 ' '

Re: JSONWEBSRV.sqlrpgle

Posted: Thu Feb 22, 2024 4:44 pm
by jonboy49
Which is fine - but why did you think that JSONWEBSRV would be a useful reference? As I tried to explain it is an example of _supplying_ a web service. Not _consumming_ one which is what you are trying to do.

Normally I would use HTTPAPI to send the file (Scott has examples in LIBHTTP of file upload) and there are topics in that section of the forum (https://www.scottklement.com/forums/viewforum.php?f=2) on the topic.

HTTPAPI will give you the tiktok response in a variable. You then parse that variable either by using DATA-INTO with YAJLINTO or by using the raw YAJL APIs. Normally getenv would never be used in this situation.

If you still have issues after reading this please post a bit more code showing how you post the file to tiktok and how you are attempting to process the returned value.

P.S. The error message you are showing appears to indicate that you are passing an invalid URI to the server. Depending on the server, I have seen cases where this response can mean almost anything from invalid authentication credentials to passing a character string where the server is expecting a number.

Re: JSONWEBSRV.sqlrpgle

Posted: Thu Feb 22, 2024 7:06 pm
by freelance
Hi,

I do agree that we need to start the 'apache server'; to enable our IBMi system to communicate with the internet, which we will.

But wanted to confirm if we need to configure our /www/apachedft/conf/httpd.conf as well ?
But as you know that we are using the binding dir YAJL in our pgm. So, is this file present and already configured; is my question ..?

Do let us know .. Thanks

Re: JSONWEBSRV.sqlrpgle

Posted: Thu Feb 22, 2024 8:54 pm
by jonboy49
Why do you think you need Apache to be running? As I pointed out earlier, Scott's JSONWEBSRV example is a SERVER application - and it needs Apache or NGINX to be running. IF you were trying to run Scott's program they Yes - Apache would need to be configured and running.

But if you are UPLOADING files to tiktok then you are normally acting as a CLIENT not a server. In which case you don't need Apache at all.

Questions for you:

1) Are actually using Tiktok?
2) If not who or what is requesting the upload?
3) If tiktok which API are you using the direct post or video upload ?

I'm just trying to get us all on the same page here.

Just tell us what you are trying to do and why.

Re: JSONWEBSRV.sqlrpgle

Posted: Fri Feb 23, 2024 6:58 pm
by freelance
Yes, we are trying to upload our product data onto the tiktok in bulk qnty i.e. my pgm should send out the IFS .json file to tiktok seller center website.
Next, we will upload .jpg/s to that website via a diff tool.

WJSON2WEB.sqlrpgle (diff pgm)

Posted: Fri Feb 23, 2024 7:00 pm
by freelance
I have yet another query on an article titled – ‘Building JSON with RPG and YAJL and writing to Standard Output’

Now, at the bottom of this article, we have ‘The Results’ which brings up you bvdemo.bvtools.com website displaying the resultant data.

Next, on the top of the article, we have ‘The HTTP Server Configuration’ contains the stmts listed below it.

So question is that, we don’t see this website in the config file. But did find /www/bvsdemo/html.

But, they don’t match. So then, where is this .com link coming from ?

Trying to understand this, if you could explain.

Thanks

WJSON2WEB.sqlrpgle (diff pgm)

Posted: Fri Feb 23, 2024 8:42 pm
by freelance
We have, /cgi-bin/(.*)

And the output link is bvsdemo.bvstools.com/cgi-bin/json1

So, need to clarify how this link ending in json1 gets triggered ?

Re: JSONWEBSRV.sqlrpgle

Posted: Fri Feb 23, 2024 9:48 pm
by jonboy49
freelance wrote: Fri Feb 23, 2024 6:58 pm Yes, we are trying to upload our product data onto the tiktok in bulk qnty i.e. my pgm should send out the IFS .json file to tiktok seller center website.
Next, we will upload .jpg/s to that website via a diff tool.
OK - I'm going to try one more time.

We can't help you if you don't give us more specific information.

I have looked at TikTok's web site and one of the APIs they offer for advertisers is the image upload one described here: https://business-api.tiktok.com/portal/ ... 7433456642 - Is that what you are using? If not then which API ? Give me a reference.

If this is the API you are using (or a similar one) I note that one of the options it offers is for you to supply a URL for the image you want uploaded. If this is what you are talking about then you would have to map Apache to the specific directory you want to upload files from.

Is this what you are trying to do?