Debug http.post

(11 posts) (2 voices)

Tags:

No tags yet.

  1. maron, Member

    Hello.

    Is there an option to add verbose debugging output of both the exact request and response for http.post

    I have managed to make a post request using CURL but can not make it properly in mydbr

    Maron

  2. maron, Member

    I'm trying to replicate this request in mydbr

    curl -d '{ "to": DEVICE_ID, "notification": { "title" : " This is my title new ", "body" : " This is the body of my message " } }' \ -i -H "Application/json" \ -H "Content-type: application/json" \ -H "Authorization: key=YOUR_AUTH_KEY \ -X POST https://fcm.googleapis.com/fcm/send

    This is my code


    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Authorization: key=MYKEY';
    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Content-Type: application/json';
    select 'dbr.http.post',
    'https://mydomain/dumppost.php', -- script that dumps post request to file
    "DEVICE_ID" as 'to',
    JSON_OBJECT('body', 'This is the body of my message', 'title', " This is my title new ", 'priority', 'low') 'notification'

    But what I get at the server is

    {"to":"DEVICE_ID","notification":"{\"body\": \"This is the body of my message\", \"title\": \" This is my title new \", \"priority\": \"low\"}"}

    I have tried I believe everything and cannot remove the backslashes from the notification object.

  3. myDBR Team, Key Master

    Maron,
    what you want to pass to the server is one JSON object where the notification property is also a JSON object (you should enclose the DEVICE_ID in quotation marks)

    In your myDBR version, you pass a JSON object where the notification property is a string (containing an encoded JSON).

    If you run the updater, you can use a new feature where you can POST a single JSON object. myDBR detects the content as JSON object if you give it an empty name:

    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Content-Type: application/json';
    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Authorization: key=MYKEY';
    select 'dbr.http.option','curl','CURLOPT_HTTPHEADER','Content-Type: application/json';
    select 'dbr.http.post', 'https://mydomain/dumppost.php',
    JSON_OBJECT('to', 'DEVICE_ID', 'notification', JSON_OBJECT('body', 'This is the body of my message', 'title', " This is my title new ", 'priority', 'low')) as '';

    --
    myDBR Team

  4. maron, Member

    Amazing - thanks - it works perfectly.

  5. maron, Member

    I now am doing a similar thing towards a different api

    However it requires an parameter to be an integer, and no matter how hard I try it seems to be passed as a string

      SELECT 'dbr.http.post', @api_url,
    @message as "message",
    CAST(100 AS UNSIGNED) "max_tokens",
    cast(1 AS UNSIGNED) "n",
    "null" stop,
    0.5 temperature
    ;

    How can I send integers in json unquoted.

    "max_tokens": 100

    { "error": { "message": "'100' is not of type 'integer' - 'max_tokens'", "type": "invalid_request_error", "param": null, "code": null } }

  6. myDBR Team, Key Master

    Maron,
    run the updater and it will work without CAST().

    --
    myDBR Team

  7. maron, Member

    Perfect - works well - thanks

  8. maron, Member

    Last question on this.

    The post object is returning a json object, is there a way for me instead of passing this to a template to pass the output from http.post and http.get on to another report / stored procedure for processing / storage?

  9. myDBR Team, Key Master

    You can use dbr.record to record the output of the dbr.http.post and then use a template with JavaScript to parse the returned JSON for further processing.

    --
    myDBR Team

  10. maron, Member

    It would be a strong feature if we could somehow call a report without having to add javascript parsing, this would make it much easier to use it in scheduler etc.

    With json support in mysql it has become pretty easy to parse most api results in mysql, I find myself doing a bit of this and can see more reports on the horizon. The javascript parsing works, but often I do not want to expose the api data to the client browser.

  11. myDBR Team, Key Master

    It would be a strong feature if we could somehow call a report without having to add javascript parsing, this would make it much easier to use it in scheduler etc.

    With json support in mysql it has become pretty easy to parse most api results in mysql, I find myself doing a bit of this and can see more reports on the horizon. The javascript parsing works, but often I do not want to expose the api data to the client browser.

    Support for this has been added for the latest build. More info can be found in the documentation.

    --
    myDBR Team


Reply

You must log in to post.