-1

[{"Id":"605a321e-7c10-49e4-9d34-ba03c4b34f69","Url":"","Type":"INBOUND_OUTBOUND", "ClearCurrentData":true,"FillOutFormFields":true,"RequestProtocol":"HTTP_REQUEST", "FileToSend":"NONE","SendDefaultData":false,"SendDetectionData":false,"ShowDialogMessage":false,"IsActive":false,"SendingTrigger":"MANUALLY","TCPSocketMethod":"","TriggerButtonName":"Get data"}]

This is an External API Call JSON file how can i get the data in ODOO Any Solutions please ?

Mentioned Above code API JSON file i had only External JSON File,don't have a table name & Database name is it possible to get data in ODOO

kometen
  • 6,536
  • 6
  • 41
  • 51
Mohamed
  • 1
  • 4

3 Answers3

0

create a model for this data for example

class apiCall(models.Model):
    _name = 'apiCall.api'
    id = fields.Char(string='Id')
    url = fields.Char(string='url')
    @api.model
    def call_api(self):
    ### result of calling external api is "result"
    for line of self:
        id =  result[0].Id
        url = result[0].url
mohammad Naimi
  • 2,259
  • 1
  • 5
  • 15
0

You can call a method on button click and access the json file. Below is the code for accessing json file:-

import json
def api_call(self):
   

   # Opening JSON file
   f = open('file_name.json',)

   # returns JSON object as 
   # a dictionary
   data = json.load(f)

   # Iterating through the json
   # list
   for i in self:
       print(i)

   # Closing file
   f.close()

Below is the button code which is applied in xml file:-

<button name="api_call" type="object" string="Call API" class="oe_highlight" />

by this way you can call the json file with external api in odoo.

Gautam Bothra
  • 565
  • 1
  • 8
  • 23
0

In your custom module (my_custom_module), move your json file to its subdirectory static/src:

import json
from odoo.modules.module import get_module_resource 

def call_api(self)
    json_filepath = get_module_resource('my_custom_module', 'static/src/', 'my_api_cred.json')
    with open(json_filepath) as f:
        data = json.load(f)
sylvain
  • 853
  • 1
  • 7
  • 20