Skip to content

Instantly share code, notes, and snippets.

@rahulbanerjee26
Created September 25, 2022 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulbanerjee26/7dd4c6d75614eb20fb2fcf2cb4631050 to your computer and use it in GitHub Desktop.
Save rahulbanerjee26/7dd4c6d75614eb20fb2fcf2cb4631050 to your computer and use it in GitHub Desktop.
def get_category_ids(self, categories):
category_ids = []
category_endpoint = f"{self._endpoint}categories"
for category in categories:
response = self.session.post(category_endpoint, json={"name": category})
# The term already exists
if "data" in response.json():
category_ids.append(response.json()["data"]["term_id"])
elif "id" in response.json():
category_ids.append(response.json()["id"])
return category_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment