Should I use the API or call the Library directly to create post content programmatically?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pjclas
    New Member
    • Aug 2012
    • 25
    • 4.2.X

    Should I use the API or call the Library directly to create post content programmatically?

    So hopefully I can explain this well enough...

    I am programmatically generating a thread and from what I can see I can do this in two ways:
    1. Call the API interface to add text content - I thought this would be the right approach, but it required a session and did a bunch of session validation I didn't want or need.
    2. Call the Library directly - This seems to avoid most of the need for a session until the afterAdd() method is called which eventually calls validate() when generating a route (while attempting to send moderator emails). The validate again requires a session.

    So either way it appears that I have to generate a session (which I did using vB_Session_Cli), but I'd rather not have to create a session if I don't need to.

    However, my question ultimately becomes, if I have to create a session in either case, which method would be considered the more "correct" method to creating a thread programmatically. I guess I would lean toward the first method since it performs a lot more verification. However, if I don't need that verification then it just adds unnecessary overhead... I did see a comment in content.php indicating in order to avoid hvinput validation, call the library directly instead, which is what led me down that path.

    Any thoughts on this?

    Also, this is a bit more tedious then it used to be to create a thread using the datamanager in vb4... so maybe I'm missing something even easier?
  • glennrocksvb
    Former vBulletin Developer
    • Mar 2011
    • 4021
    • 5.7.X

    #2
    Try using the mobile API. I was able to use it to programmatically register a user in vB5. Note that you need to generate an API key in AdminCP > vBulletin API > API Key.

    http://www.vbulletin.com/vbcms/conte...334-mobile-api

    Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

    Comment

    • pjclas
      New Member
      • Aug 2012
      • 25
      • 4.2.X

      #3
      Originally posted by Glenn Vergara
      Try using the mobile API. I was able to use it to programmatically register a user in vB5. Note that you need to generate an API key in AdminCP > vBulletin API > API Key.

      http://www.vbulletin.com/vbcms/conte...334-mobile-api
      Is that the direction we are supposed to be taking? Seems like an unnecessary http request when called from in code. Or can I call these Apis without generating an http request? Oh and I also don't want to have to be logged in since this is running via a cron job daily. Although I do already create a dummy session with my current approach.
      Last edited by pjclas; Fri 24 Oct '14, 8:52am.

      Comment

      • glennrocksvb
        Former vBulletin Developer
        • Mar 2011
        • 4021
        • 5.7.X

        #4
        Originally posted by pjclas
        Is that the direction we are supposed to be taking? Seems like an unnecessary http request when called from in code. Or can I call these Apis without generating an http request? Oh and I also don't want to have to be logged in since this is running via a cron job daily. Although I do already create a dummy session with my current approach.
        Ok then mobile API is not good in this case as it is normally used for clients outside vBulletin.

        Flag Icon Postbit Insert GIPHY Impersonate User BETTER INITIALS AVATAR Better Name Card Quote Selected Text Bookmark Posts Post Footer Translate Stop Links in Posts +MORE!

        Comment

        • pjclas
          New Member
          • Aug 2012
          • 25
          • 4.2.X

          #5
          Originally posted by Glenn Vergara
          Ok then mobile API is not good in this case as it is normally used for clients outside vBulletin.
          Right that's what I thought. So back to my original question then.

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...