Skip to content
  • Categories
  • Recent
  • Popular
Collapse
Brand Logo
  1. Home
  2. Categories
  3. Technical subjects
  4. GoFast Community API problem integration.

GoFast Community API problem integration.

Scheduled Pinned Locked Moved Technical subjects
11 Posts 2 Posters 320 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Victor_TEOS
    wrote on last edited by
    #1

    Hello,
    I am encountering an issue while attempting to utilize the GoFast API to upload documents to GoFast.
    Each time I make the API call and retrieve the response, I consistently encounter the following error.

    2024-01-08 10:59:26,538 10814 WARNING 2o_slis odoo.addons.intefrace_GoFAST_4_1_odoo_16_0.models.ir_attachement: response {'message': 'file or template_nid is a mandatory parameter'}
    Response Status Code: 400
    Response Content: {"message":"file or template_nid is a mandatory parameter"}
    JSON Response: {'message': 'file or template_nid is a mandatory parameter'}

    4f9c2f1a-6af9-48da-9e90-31360821a6d6-image.png

    And below is the parameters I am using according to the API documentation

    data = {
    'file': (pdf_name, pdf_path, content_type), "I tried this first but it didn't work"
    'template_nid': (pdf_name, pdf_path, content_type),
    'type': 'alfresco_item',
    'title': new_name,
    'locations': str(path),
    'field_document_reference': 'odoo',
    }
    files = {
    'file': (pdf_name, pdf_path, content_type)
    }
    try:
    response = requests.post(url, headers=headers, params=data, files=files) # I added the file directly in the request, still didn't work.

    Below is the header I am using according to the API documentation.

    headers = {
    'Authorization': encoded_credentials,
    'Content-Type': 'multipart/form-data',
    'Accept': 'application/json',
    }

    f8ca0b8c-b6eb-481e-9a88-44353151fb90-image.png

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Raphaël Badawi
      DEV
      wrote on last edited by
      #2

      Hello,

      I don't think that's the root cause of the issue, but since it could cause unexpected behavior: you don't need to specify "template_nid" if "file" is passed. In fact, "template_nid" is only useful if you wish to determine the contents of the file from a template, which is not the case if a file is already passed.

      If you're using the "requests" package in Python, you need to pass the buffered reader of the file, not just the path:

      image.png

      If you try something like this, does it work better?

      Best wishes,
      Raphaël.

      1 Reply Last reply
      1
      • V Offline
        V Offline
        Victor_TEOS
        wrote on last edited by
        #3

        First of all, thanks, @Raphaël-Badawi

        Adding the open() function for the files changed the error message; I don't think the request is being processed at this point. Below is the error message.

        image.png

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Raphaël Badawi
          DEV
          wrote on last edited by
          #4

          Hello,

          This seems to be a Python error message. From what I understand, you have put in the open() call something which was not the relative path to the file (as a string).

          Let's put a complete example.

          Here I have an "example.txt" file in the same folder as my script, and I want to put in in "adm" private folder ("/Sites/_adm").

          image.png

          With the following script :

          import base64
          import requests
          
          encoded_credentials = base64.b64encode(b"adm:MYPASSWORD").decode("utf-8")
          
          url = "https://gofast-integration.ceo-vision.com/api/node/node"
          
          headers = {
              "Authorization": f'Basic ${encoded_credentials}',
          }
          
          data = {
              'type': 'alfresco_item',
              'locations': '["/Sites/_adm"]',
              'title': "example.txt",
          }
          files = {
              'file': open("example.txt", "rb")
          }
          response = requests.post(url, headers=headers, data=data, files=files)
          print(response.text)
          

          I have a working request:

          image.png

          And the content is on the platform:

          image.png

          I hope you will find the way,

          Best regards,
          Raphaël.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Victor_TEOS
            wrote on last edited by
            #5

            Hello @Raphaël-Badawi , thank you for your contribution so far, but from what I can tell, this might be a bug for the API worth looking into. I used the information you displayed above with my minor changes for the GoFast community setup I have.

            image.png

            And I managed to get the same error which was unfortunate. Is it because I am using the Gofast Community or is there something that is hindering this request from working?

            image.png

            Even with Postman, using my Gofast community, I managed to get the same error.

            image.png

            But using your own server which I presume is not community version, I get a fair error that is different, and the difference is that I know what is missing there.

            image.png

            Thanks a lot in advance.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Raphaël Badawi
              DEV
              wrote on last edited by
              #6

              Yes of course you have an authorization error when requesting our server since this credentials check is the very first check done within the API endpoint 😉 So it doesn't actually get until the parameters check (which is the error you've got with your community).

              I will send you some valid temporary test credentials in PM to see if you get an error with the enterprise version and if so what the actual error is. If the discrepancy between community and enterprise regarding this API gets confirmed, I will book some time in my agenda to so some investigation on a community installation.

              Best regards,
              Raphaël.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Victor_TEOS
                wrote on last edited by
                #7

                Hi @Raphaël-Badawi
                This API integration has already been done with our enterprise version, and it is working as expected over here. I do not know if it will be okay for you to test it as well in the community version to check the difference.

                I have a problem with the community version API, not the enterprise version. It works for enterprise Gofast. Thanks a lot.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Raphaël Badawi
                  DEV
                  wrote on last edited by
                  #8

                  Hello again,

                  I took the liberty to make some tests on our community demo platform.

                  image.png

                  It actually works.

                  What version of GoFAST community are you using? Can you give more hints about the request? Is your community instance hosted on a remote host or on localhost? Do you have the same issue when requesting the enterprise demo platform I gave you credentials in PM?

                  If the problem is in the end confirmed to be community-specific, I will make a fresh local community install to investigate further.

                  Raphaël.

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Victor_TEOS
                    wrote on last edited by
                    #9

                    From the indication in the compose file, seems am working on

                    CEO-Vision S.A.S

                    Project : gofast-ng-compose

                    Compose type : Community

                    Template version : 1.0

                    Modification date : 06.10.2023

                    Gofast Version : 4.1.1_hotfix_1.0

                    My setup is on a remote server and not on my localhost, accessible at the url below.
                    https://master-gofast.teoshore.com/

                    I didn't have such issue while requesting with the enterprise credentials in my PM. Thanks a lot.

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      Victor_TEOS
                      wrote on last edited by
                      #10

                      Hello @Raphaël-Badawi It is now working, I just restarted the containers and Gofast, and also I used the request method you showed above, and it is working. Thanks a lot. Please how do I now make it to locate the path I created in my group folder? it seems to allow upload only to my private folder. Is there anything wrong with the location below?

                      ["/Sites/_Groups/_Odoo/_2O SLIS/_Sales/_Sales Order/S00001/"]

                      I keep getting the error below. that my folder cannot be found. Thanks a lot in advance.

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Raphaël Badawi
                        DEV
                        wrote on last edited by
                        #11

                        You definitely can upload in any place you have contributor right into. And yes the path is the same path you see in the URL or in the filebrowser breadcrumb. It's the webdav path. So so far is I can tell the path you provide seems valid.

                        Have you checked that user matching the credentials you used to make the request has contributor privileges in the "Sales Order" space. If so, can you please provide the error message you got making the request?

                        Thanks!
                        Raphaël.

                        1 Reply Last reply
                        1
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Search
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Popular
                        • Search