Jump to content

Recommended Posts

goodmorning autoit team

today am comming with some winhttp problems, i hope that you can help me to solve them.

the first problem

is when opening a request

my forums api allow me to delete any post using the api key

all functions work, i mean post / get

but when i tried to use the delete verb it's gave me an html 404 error

here is what am tried

#include "WinHttp.au3"

; Open needed handles
Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, "xxxxxxxx.com")
; Specify the reguest:

Global $hRequest = _WinHttpOpenRequest($hConnect, "Delete", "/vb/Api/posts/10447/?hard_delete=true", default, default)
_WinHttpAddRequestHeaders($hRequest, "XF-Api-Key:xxxxx")
_WinHttpAddRequestHeaders($hRequest, "XF-Api-User:xxxxx")

; Send request
_WinHttpSendRequest($hRequest)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

Global $sHeader = 0, $sReturned = 0
; If there is data available...
If _WinHttpQueryDataAvailable($hRequest) Then 
$sHeader = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_DISPOSITION)
;Or maybe:
; $sHeader = _WinHttpQueryHeaders($hRequest, BitOR($WINHTTP_QUERY_RAW_HEADERS_CRLF, $WINHTTP_QUERY_CUSTOM), "Content-Disposition")

    Do
        $sReturned &= _WinHttpReadData($hRequest)
    Until @error
msgBox(64, "", $sReturned)
endIf


; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 

and here is the error message

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /vb/Api/posts/10447/
on this server.<br />
</p>
</body></html>

 

i hope you can help me 

thanks in advance

Share this post


Link to post
Share on other sites

so,
@Jos
when i use Post verb or Get it work
e.g here is the result when i use the same example with the Get command
 

{
    "post": {
        "attach_count": 0,
        "can_edit": true,
        "can_hard_delete": true,
        "can_react": true,
        "can_soft_delete": true,
        "can_view_attachments": true,
        "is_first_post": false,
        "is_last_post": true,
        "is_reacted_to": false,
        "last_edit_date": 1593265281,
        "message": "\u0627\u0644\u0633\u0644\u0627\u0645 \u0639\u0644\u064a\u0643\u0645 \u0645\u0648\u0636\u0648\u0639 \u062c\u0645\u064a\u0644 \u0628\u0627\u0631\u0643 \u0627\u0644\u0644\u0647 \u0641\u064a\u0643 \u064a\u0627 \u062d\u0648\u062f\u0649",
        "message_state": "visible",
        "position": 5,
        "post_date": 1593264635,
        "post_id": 10447,
        "reaction_score": 0,
        "Thread": {
            "BaUser": null,
            "can_edit": true,
            "can_edit_tags": true,
            "can_hard_delete": true,
            "can_reply": true,
            "can_soft_delete": true,
            "can_view_attachments": true,
            "custom_fields": {},
            "discussion_open": true,
            "discussion_state": "visible",
            "discussion_type": "",
            "first_post_id": 10289,
            "first_post_reaction_score": 3,
            "Forum": {
                "breadcrumbs": [
                    {
                        "node_id": 48,
                        "title": "\u0627\u0644\u0642\u0633\u0645 \u0627\u0644\u0639\u0627\u0645",
                        "node_type_id": "Category"
                    }
                ],
                "description": "",
                "display_in_list": true,
                "display_order": 100,
                "node_id": 49,
                "node_name": null,
                "node_type_id": "Forum",
                "parent_node_id": 48,
                "title": "\u0627\u0644\u0645\u0646\u062a\u062f\u0649 \u0627\u0644\u0639\u0627\u0645",
                "type_data": {
                    "allow_poll": true,
                    "allow_posting": true,
                    "can_create_thread": true,
                    "can_upload_attachment": true,
                    "discussion_count": 85,
                    "last_post_date": 1593264635,
                    "last_post_id": 10447,
                    "last_post_username": "MesterPerfect",
                    "last_thread_id": 4884,
                    "last_thread_prefix_id": 0,
                    "last_thread_title": "\u0645\u0627 \u0647\u0648 \u0645\u0641\u0647\u0648\u0645 \u0627\u0644\u0623\u0645\u0646 \u0627\u0644\u0633\u064a\u0628\u0631\u0627\u0646\u064a",
                    "message_count": 172,
                    "min_tags": 0,
                    "require_prefix": false
                }
            },
            "is_watching": true,
            "last_post_date": 1593264635,
            "last_post_id": 10447,
            "last_post_user_id": 2,
            "last_post_username": "MesterPerfect",
            "node_id": 49,
            "post_date": 1592577213,
            "prefix_id": 0,
            "reply_count": 5,
            "sticky": false,
            "tags": [
                "\u0625\u0644\u0649",
                "\u0627\u0644\u0623\u0645\u0646",
                "\u0627\u0644\u0633\u064a\u0628\u0631\u0627\u0646\u064a",
                "\u0627\u0644\u0645\u0639\u0644\u0648\u0645\u0627\u062a",
                "\u0639\u0644\u0649"
            ],
            "thread_id": 4884,
            "title": "\u0645\u0627 \u0647\u0648 \u0645\u0641\u0647\u0648\u0645 \u0627\u0644\u0623\u0645\u0646 \u0627\u0644\u0633\u064a\u0628\u0631\u0627\u0646\u064a",
            "User": {
                "activity_visible": true,
                "age": 21,
                "avatar_urls": {
                    "o": null,
                    "h": null,
                    "l": null,
                    "m": null,
                    "s": null
                },
                "can_ban": false,
                "can_converse": true,
                "can_edit": true,
                "can_follow": true,
                "can_ignore": true,
                "can_post_profile": true,
                "can_view_profile": true,
                "can_view_profile_posts": true,
                "can_warn": false,
                "custom_fields": {
                    "facebook": "mahmoud.atef.000",
                    "gender": "male",
                    "screen_readers": "1",
                    "skype": "mahmoud.atef.000",
                    "twitter": "",
                    "windows": "4"
                },
                "custom_title": "",
                "dob": {
                    "year": 1999,
                    "month": 4,
                    "day": 4
                },
                "is_admin": true,
                "is_banned": false,
                "is_discouraged": false,
                "is_followed": false,
                "is_ignored": false,
                "is_moderator": false,
                "is_staff": false,
                "is_super_admin": true,
                "last_activity": 1593209942,
                "location": "\u0627\u0644\u0642\u0627\u0647\u0631\u0629",
                "message_count": 91,
                "reaction_score": 141,
                "register_date": 1533659760,
                "secondary_group_ids": [
                    3,
                    4
                ],
                "signature": "",
                "trophy_points": 93,
                "user_group_id": 2,
                "user_id": 6,
                "user_state": "valid",
                "user_title": "\u0639\u0636\u0648 \u0641\u0639\u0627\u0644",
                "username": "mahmoud.atef",
                "visible": true,
                "warning_points": 0,
                "website": "https://mx-blind.com"
            },
            "user_id": 6,
            "username": "mahmoud.atef",
            "view_count": 92,
            "visitor_post_count": 1
        },
        "thread_id": 4884,
        "User": {
            "activity_visible": true,
            "avatar_urls": {
                "o": "https://secure.gravatar.com/avatar/324bc0d4e2add5deec287b874280734d?s=384",
                "h": "https://secure.gravatar.com/avatar/324bc0d4e2add5deec287b874280734d?s=384",
                "l": "https://secure.gravatar.com/avatar/324bc0d4e2add5deec287b874280734d?s=192",
                "m": "https://secure.gravatar.com/avatar/324bc0d4e2add5deec287b874280734d?s=96",
                "s": "https://secure.gravatar.com/avatar/324bc0d4e2add5deec287b874280734d?s=48"
            },
            "can_ban": false,
            "can_converse": true,
            "can_edit": true,
            "can_follow": true,
            "can_ignore": false,
            "can_post_profile": true,
            "can_view_profile": true,
            "can_view_profile_posts": true,
            "can_warn": false,
            "custom_fields": {
                "facebook": "my.nvda.1",
                "gender": "male",
                "screen_readers": "1",
                "skype": "live:AhmedBakr012",
                "twitter": "my_nvda",
                "windows": "3",
                "Telegram": "MesterPerfect"
            },
            "custom_title": "",
            "dob": {
                "year": null,
                "month": 10,
                "day": 1
            },
            "is_admin": true,
            "is_banned": false,
            "is_discouraged": false,
            "is_followed": false,
            "is_ignored": false,
            "is_moderator": true,
            "is_staff": true,
            "is_super_admin": true,
            "last_activity": 1593268517,
            "location": "sohag, Egypt",
            "message_count": 3042,
            "reaction_score": 2073,
            "register_date": 1533539769,
            "secondary_group_ids": [
                3,
                4
            ],
            "signature": "[CENTER][SIZE=5]\u2022\u2022\u2022 \uf0d7 The Elimination Chamber is back\u2022\u2022\u2022 \uf0d7[/SIZE][/CENTER]\n[YOUTUBESUBSCRIBER]UC-JaR2UmCzOjz7TFPHS9YHg[/YOUTUBESUBSCRIBER]",
            "trophy_points": 595,
            "user_group_id": 2,
            "user_id": 2,
            "user_state": "valid",
            "user_title": "\u0627\u0644\u0648\u0633\u0627\u0645 \u0627\u0644\u0645\u0627\u0633\u064a",
            "username": "MesterPerfect",
            "visible": true,
            "warning_points": 0,
            "website": "https://mx-blind.com"
        },
        "user_id": 2,
        "username": "MesterPerfect",
        "warning_message": ""
    }
}

 

Share this post


Link to post
Share on other sites

I removed my post earlier as I misread the error code....   but either way ...  there isn't much we can do unless we can test. the 403 is an access issue.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

i tried to Read the UDF and do a small compairation with the Microsoft Doc, i can't find any problem, only post and get working, the others no

what i need to is

post, delete, put, and get

i can't know where is the problem

Share this post


Link to post
Share on other sites

Why are you asking what appears to be a XenForo Forum API related questions in an AutoIt forum?  Looking at the response to the DELETE API request that you posted earlier, you got back a 403 Forbidden response.  Given that your GET requests are successful, that probably means that either your API call is not correct or that the XF-Api-User does not have permission to delete the specified post.

Share this post


Link to post
Share on other sites

@TheXman

i can not know if the problem is from the API function

or from the winhttp i posted here just to know where is the problem, ifit not from winhttp and not from the udf

i will go to xenforo cominity and i will post a thread there 

Share this post


Link to post
Share on other sites
Posted (edited)

Are you using a Super-User api-key?  I assume that you are because you supplied an api-user in the header.  If that user does not have permission to delete posts, that is why you are getting a 403 response.  If you want to bypass the user's context and delete the post as a super user, then you must do it on a per-request basis.  The following is taken from the API documentation:

If the request is made with a super user key and you wish to bypass the context user's permissions, this may be done on a per-request basis by setting the api_bypass_permissions parameter to 1. (This can be passed via a query string or as part of the request body.)

That information above can be found on the following page of the API doc:

https://xenforo.com/xf2-docs/dev/rest-api/

Edited by TheXman

Share this post


Link to post
Share on other sites

the api key is a super key

i put an admin user

by the way i don't know how i can pass this param using winhttp, can you gid me to do that and test please?

note: when i tried to create e.g a new thread using a guest api key it gave me an error msg as json string told me that the api does not have the permitions to do that

Share this post


Link to post
Share on other sites

Assuming that everything else in your script is correct, then you can try changing the follow line from:

Global $hRequest = _WinHttpOpenRequest($hConnect, "Delete", "/vb/Api/posts/10447/?hard_delete=true", default, default)

To

Global $hRequest = _WinHttpOpenRequest($hConnect, "Delete", "/vb/Api/posts/10447?hard_delete=true&api_bypass_permissions=1", default, default)

 

Share this post


Link to post
Share on other sites

hello again,

i confermed that the problem from the xenforo api i conntacted them

now i have a small problem with json

i hope that i can find here a reply

i have this data

{
    "success": true,
    "conversation": {
        "can_edit": true,
        "can_invite": true,
        "can_reply": true,
        "can_upload_attachment": true,
        "conversation_id": 955,
        "conversation_open": true,
        "first_message_id": 1710,
        "is_starred": false,
        "last_message_date": 1593345206,
        "last_message_id": 1710,
        "last_message_user_id": 5,
        "open_invite": false,
        "recipient_count": 2,
        "recipients": {
            "2": "MesterPerfect"
        },
        "reply_count": 0,
        "start_date": 1593345206,
        "Starter": {
            "activity_visible": false,
            "avatar_urls": {
                "o": "https://mx-blind.com/vb/data/avatars/o/0/5.jpg?1534192853",
                "h": "https://mx-blind.com/vb/data/avatars/h/0/5.jpg?1534192853",
                "l": "https://mx-blind.com/vb/data/avatars/l/0/5.jpg?1534192853",
                "m": "https://mx-blind.com/vb/data/avatars/m/0/5.jpg?1534192853",
                "s": "https://mx-blind.com/vb/data/avatars/s/0/5.jpg?1534192853"
            },
            "can_ban": false,
            "can_converse": false,
            "can_edit": true,
            "can_follow": false,
            "can_ignore": false,
            "can_post_profile": true,
            "can_view_profile": true,
            "can_view_profile_posts": true,
            "can_warn": false,
            "custom_fields": {
                "facebook": "baaziznacer1",
                "gender": "male",
                "screen_readers": "2",
                "skype": "simple-blind",
                "twitter": "baaziznacer",
                "windows": "4"
            },
            "custom_title": "",
            "is_admin": true,
            "is_banned": false,
            "is_discouraged": false,
            "is_followed": false,
            "is_ignored": false,
            "is_moderator": true,
            "is_staff": true,
            "is_super_admin": true,
            "last_activity": 1593287145,
            "location": "\u0627\u0644\u062c\u0632\u0627\u0626\u0631",
            "message_count": 597,
            "reaction_score": 569,
            "register_date": 1533642994,
            "secondary_group_ids": [
                3,
                4
            ],
            "signature": "\u2022 \u0627\u0644\u062f\u0646\u064a\u0627 \u062b\u0644\u0627\u062b\u0629 \u0623\u064a\u0627\u0645: \u0627\u0644\u0623\u0645\u0633 \u0639\u0634\u0646\u0627\u0647 \u0648\u0644\u0646 \u064a\u0639\u0648\u062f\u060c \u0627\u0644\u064a\u0648\u0645 \u0646\u0639\u064a\u0634\u0647 \u0648\u0644\u0646 \u064a\u062f\u0648\u0645\u060c \u0648\u0627\u0644\u063a\u062f: \u0644\u0627 \u0646\u062f\u0631\u064a \u0623\u064a\u0646 \u0633\u0646\u0643\u0648\u0646 \u0641\u0635\u0627\u0641\u062d\u060c \u0648\u0633\u0627\u0645\u062d\u060c \u0648\u062f\u0639 \u0627\u0644\u062e\u0644\u0642 \u0644\u0644\u062e\u0627\u0644\u0642\u060c \u0641\u0623\u0646\u0627 \u0648\u0623\u0646\u062a \u0648\u0647\u0645 \u0648\u0646\u062d\u0646 \u0631\u0627\u062d\u0644\u0648\u0646\u060c \u0641\u0645\u0646 \u0623\u0639\u0645\u0627\u0642 \u0642\u0644\u0628\u0643 \u0633\u0627\u0645\u062d \u0645\u0646 \u0623\u0633\u0627\u0621 \u0625\u0644\u064a\u0643.",
            "trophy_points": 210,
            "user_group_id": 2,
            "user_id": 5,
            "user_state": "valid",
            "user_title": "\u0639\u0636\u0648 \u0645\u062d\u062a\u0631\u0641",
            "username": "\u0646\u0627\u0635\u0631 \u0628\u0639\u0632\u064a\u0632",
            "visible": true,
            "warning_points": 0,
            "website": "http://mx-blind.com/"
        },
        "title": "\u0623\u0646\u0627 \u0632\u0641\u062a",
        "user_id": 5,
        "username": "\u0646\u0627\u0635\u0631 \u0628\u0639\u0632\u064a\u0632"
    }
}

 

i need to decode it using json

can we do that using autoit?

because the utf8 text here is encoded

thanks in advance

Share this post


Link to post
Share on other sites

This is an example script that will read your posted data from "data.txt" and then display 2 of the keys of which one is containing Unicode characters:

#include "Json.au3"
$data = FileRead("data.txt")
Json_dump($data)
$object = json_decode($data)
$register_date=json_get($object, '.conversation.Starter.register_date')
MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$register_date' & @CRLF & @CRLF & 'Return:' & @CRLF & $register_date) ;### Debug MSGBOX
$signature=json_get($object, '.conversation.Starter.signature')
MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$signature' & @CRLF & @CRLF & 'Return:' & @CRLF & $signature) ;### Debug MSGBOX

The json.au3 can be found here:  

 

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By tarretarretarre
      About AutoIt-API-WS
      AutoIt-API-WS is a light weight web server with expressive syntax, with the sole purpose of wrapping your existing AutoIt app with little to no effort.
      With AutoIt-API-WS you can send and receive data between any application or framework, as long they can handle HTTP requests, which is an industry standard today.
      Like my other communcations UDF AutoIt-Socket-IO AutoIt-API-WS is heavily inspired from the big boys, but this time its Laravel and Ruby on Rails.
      Features Highlights
      No external or internal dependencies required RESTful mindset when designed Expressive syntax Small codebase Heavy use of Michelsofts Dictionary object Limitations
      Not complient with any RFC, so something important could be missing. Time will tell! One persons slow loris attack will kill the process forever. Example of implemetnation (With screenshots)
      This is a basic cRud operation with the RESTful mindset in use.
      #include "API.au3" #include <Array.au3> _API_MGR_SetName("My APP DB adapter") _API_MGR_SetVer("1.0 BETA") _API_MGR_SetDescription("This adapter allows you to get this n that") _API_MGR_Init(3000) _API_MGR_ROUTER_GET('/users', CB_GetUsers, 'string sortBy', 'Get all users, sortBy can be either asc or desc. asc is default') _API_MGR_ROUTER_GET('/users/{id}', CB_GetUsersById, 'int id*', 'Get user by id') While _API_MGR_ROUTER_HANDLE() WEnd Func DB_GetUsers() Local $userA = ObjCreate("Scripting.Dictionary") Local $userB = ObjCreate("Scripting.Dictionary") $userA.add('id', 1) $userA.add('name', 'TarreTarreTarre') $userA.add('age', 27) $userB.add('id', 2) $userB.add('name', @UserName) $userB.add('age', 22) Local $aRet = [$userA, $userB] Return $aRet EndFunc Func CB_GetUsers(Const $oRequest) Local $aUsers = DB_GetUsers() If $oRequest.exists('sortBy') Then Switch $oRequest.item('sortBy') Case Default Case 'asc' Case 'desc' _ArrayReverse($aUsers) EndSwitch EndIf Return $aUsers EndFunc Func CB_GetUsersById(Const $oRequest) Local Const $aUsers = DB_GetUsers() Local $foundUser = Null For $i = 0 To UBound($aUsers) -1 Local $curUser = $aUsers[$i] If $curUser.item('id') == $oRequest.item('#id') Then $foundUser = $curUser ExitLoop EndIf Next If Not IsObj($foundUser) Then Return _API_RES_NotFound(StringFormat("Could not find user with ID %d", $oRequest.item('#id'))) EndIf return $foundUser EndFunc When you visit http://localhost:3000 you are greeted with this pleasent view that will show you all your registred routes and some extra info you have provided.

      When you visit http://localhost:3000/users the UDF will return the array of objects as Json
       
      And here is an example of http://localhost:3000/users/1

       
      More examples can be found here
       
       
      Autoit-API-WS-1.0.0-beta.zip (OLD!)
      Autoit-API-WS-1.0.1-beta.zip (NEWEST 2020-06-29)
    • By argumentum
      I can TCP/IP in AutoIt, hence, make a HTTP deamon. Now, how can I HTTPS to use SSL !??
      Well, Apache has this "mod_proxy.so" module that can let me have SSL and what not is in Apache.
      All that is needed is to tell Apache what I wanna do by editing httpd.conf .
      # Implements a proxy/gateway for Apache. # 1. Open /Applications/XAMPP/etc/httpd.conf # 2. Enable the following Modules by removing the # at the front of the line. # - LoadModule rewrite_module modules/mod_rewrite.so # - LoadModule proxy_module modules/mod_proxy.so # - LoadModule proxy_http_module modules/mod_proxy_http.so # # 3. Copy and Paste below to the bottom of httpd.conf # <IfModule mod_proxy.c> ProxyRequests On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyVia Off ProxyPreserveHost Off ProxyPass /home/ http://127.0.0.1:84/home/ ProxyPassReverse /home/ http://127.0.0.1:84/home/ SetEnv proxy-nokeepalive 1 # ..since we are not using "keep-alive", we are using "close" </IfModule> ...et voila  
      I'm using XAMPP ( https://www.apachefriends.org/download.html )
      and this is my solution to avoid coding in PHP, as I feel more comfortable coding in AutoIt.
      A "muli-thread or concurrency" can be done by forking the socket ( https://www.autoitscript.com/forum/topic/199177-fork-udf-ish/ )
      but responses are under 20 ms., so I feel fine with a single thread.
      I modified an example ( attached below ), so can try out the concept.
      PS: I am not an Apache guru. I just discovered this and it opens a world of possibilities. In my case, I'm thinking of an API to query SQLite 
      PS2: I'm not gonna make Poll but do click like if you do  
       
      201673-json-http-post-serverlistener.au3
    • By MichaelSDeVries
      Has anyone successfully developed  integration with the E*TRADE API in AutoIt?


       
      If so, then would you be willing and able to share some of your AutoIt code to do so with me? and/or help me successfully develop an AutoIt interface with the E*TRADE API?

       
      Please also Reply at: http://blog.thevcf.com/forums/topic/etrade-api/#post-4032

       
      Thank You and Have a Great Day!
      - Michael S. DeVries
×
×
  • Create New...