Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to create new brandwatch query #38

Open
ukrcbreddy1 opened this issue Nov 20, 2023 · 3 comments
Open

Not able to create new brandwatch query #38

ukrcbreddy1 opened this issue Nov 20, 2023 · 3 comments

Comments

@ukrcbreddy1
Copy link

ukrcbreddy1 commented Nov 20, 2023

Hello,

We are using this package to create a query over brandwatch. Previously we were able to do that with the same code base but right now it seem to be failing with the following error message, not sure if anything have been changed from Brandwatch side and if this API needs to be updated.

Tried the same code with 1.4.0, 1.5.1 version of bcr-api

Code:

project = BWProject(username=YOUR_ACCOUNT, project=YOUR_PROJECT, token_path=YOUR_TOKEN_PATH)
queries = BWQueries(project)

corporation_booleanQuery = '("Sasol" OR "Rio Tinto" OR "DRDGold" OR "Durban Roodepoort Deep Limited") AND (site:cer.org.za)'

queries.upload(name = 'testing 0' ,
             booleanQuery = corporation_booleanQuery,
             startDate = '2019-01-01',
             languages = ['en'],
             contentSources = ['news'])

Error message:

05:22:23 ERROR: There was an error with this request: 
https://api.brandwatch.com/query-validation
{"booleanQuery": "(\"Sasol\" OR \"Rio Tinto\" OR \"DRDGold\" OR \"Durban Roodepoort Deep Limited\") AND (site:cer.org.za)", "language": ["en"]}
[{'code': 0, 'message': "Unrecognized field 'language'"}]
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/var/tmp/ipykernel_6175/1702768516.py in <module>
     17              startDate = query_start_date,
     18              # languages = languages,
---> 19              contentSources = ['news'])
     20     corporation_queries.append(f'{backfill_portfolio_name} Client Onboarding Mentions ' + str(idx)) # entities addition
     21     # corporation_queries.append(f'Corporation Mentions ' + str(idx))  # domains addition

/opt/conda/lib/python3.7/site-packages/bcr_api/bwresources.py in upload(self, create_only, modify_only, **kwargs)
    296             The uploaded query information in a dictionary of the form {query1name: query1id}
    297         """
--> 298         return self.upload_all([kwargs], create_only, modify_only)
    299 
    300     def upload_all(self, data_list, create_only=False, modify_only=False):

/opt/conda/lib/python3.7/site-packages/bcr_api/bwresources.py in upload_all(self, data_list, create_only, modify_only)
    320 
    321         queries = super(BWQueries, self).upload_all(
--> 322             data_list, create_only=False, modify_only=False
    323         )
    324 

/opt/conda/lib/python3.7/site-packages/bcr_api/bwresources.py in upload_all(self, data_list, create_only, modify_only)
    162         for data in data_list:
    163             # eventually make _fill_data() a BWResource func
--> 164             filled_data = self._fill_data(data)
    165             name = data["name"]
    166 

/opt/conda/lib/python3.7/site-packages/bcr_api/bwresources.py in _fill_data(self, data)
    506         # validating the query search - comment this out to skip validation
    507         self.project.validate_query_search(
--> 508             booleanQuery=filled["booleanQuery"], language=["en"]
    509         )
    510         return json.dumps(filled)

/opt/conda/lib/python3.7/site-packages/bcr_api/bwproject.py in validate_query_search(self, **kwargs)
    138 
    139         valid_search = self.request(
--> 140             verb=requests.post, address="query-validation", data=json.dumps(kwargs)
    141         )
    142         return valid_search

/opt/conda/lib/python3.7/site-packages/bcr_api/bwproject.py in request(self, verb, address, params, data)
    182             access_token=self.token,
    183             params=params,
--> 184             data=data,
    185         )
    186 

/opt/conda/lib/python3.7/site-packages/bcr_api/bwproject.py in bare_request(self, verb, address_root, address_suffix, access_token, params, data)
    238                     )
    239                 )
--> 240                 raise RuntimeError(response.json()["errors"])
    241 
    242         logger.debug(response.url)

RuntimeError: [{'code': 0, 'message': "Unrecognized field 'language'"}]
@cloner-gan
Copy link

I am having the same issue. "Unrecognized field 'language'" with default language settings.
image

@ukrcbreddy1
Copy link
Author

Hey @cloner-gan , I believe the work around we did was.. we have used Brandwatch UI to create the queries manually. (Atleast that's what I remember). As we had to only create one query, it was fine in our case.

@cloner-gan
Copy link

Thanks @ukrcbreddy1, unfortunately I need the ability to add new queries. Glad you found a workaround though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants