API CALLS inside DSS

Sid
Level 1
API CALLS inside DSS

Can anyone help me in understanding how to perform API Calling inside DSS? How do i create an API call to fetch data from an external source ?

0 Kudos
7 Replies
Ignacio_Toledo

To what kind of API  do you want to connect? We've working with Jira and Smartsheet api calls, and our approach has two steps: first, we use the python SDK available, and we implement the calls that we want to use; second, if there are some "often used" API calls, we convert those codes into a Plugin.

Does this describe and/or answer your question? If so, I could share some examples we have.

Cheers

Sid
Level 1
Author

Hi ! Thank you so much for your response, basically we want to extract data from PEGA and bring into DataIKU using API calls and plugins . Do you have any examples pertaining to this? 

0 Kudos
Ignacio_Toledo

I do have some examples, but with Jira and Smartsheet APIs. Would this help you?

Also, there is this other ticket in the community, where they provide an example, but for Freshdesk.

Cheers.

0 Kudos
ak12

Hello,

Not the original poster but I'm trying to connect to the smartsheet API within DSS and I was wondering if you'd be willing to share your example?

Thanks!

0 Kudos
Ignacio_Toledo

Hi @ak12 

So, to connect to the smartsheet API you need first:

  • An access token to the API (documentation here)
  • A python environment with the smartsheet SDK installed (smartsheet-python-sdk)

To connect to the smartsheet API, from a python notebook or recipe:

import smartsheet
# You need a Token to authenticate with smartsheet

TOKEN = dataiku.get_custom_variables()['SMARTSHEET_TOKEN'] # we store the token in a custom variable in our DSS instance, but you should change this by the string token

smartsheet_client = smartsheet.Smartsheet(TOKEN)
smartsheet_client.errors_as_exceptions(True)

 

This creates a client that we can use to interact with the sheets, and depending in your token permissions, you can add, update or delete sheets using code. You should start with the tutorial to understand the logic of the api.

But let's say you want to get a sheet as a pandas dataframe, first you need the sheet id, that you can get online from the smartsheet webapp, or by listing all the sheets and their ids:

sheets = smartsheet_client.Sheets.list_sheets(include_all=True)
for s in sheets.data:
    print(f"The sheet \"{s.name}\" has id {s.id}")

Once you have find the id of sheet you need, you should create a python function to automate the parsing into a dataframe:

def simple_sheet_to_dataframe(sheet):
    col_names = [col.title for col in sheet.columns]
    rows = []
    for row in sheet.rows:
        cells = []
        for cell in row.cells:
            cells.append(cell.value)
        rows.append(cells)
    data_frame = pd.DataFrame(rows, columns=col_names)
    return data_frame

Now we open the connection to the sheet on interest and parse the data into a dataframe:

sheet = smartsheet_client.Sheets.get_sheet(id) # id can be a string or an int
df = simple_sheet_to_dataframe(sheet)
df.head() # to inspect the header

 

In the previously linked tutorial you should find examples on how to read excel files and then insert them into smartsheet.

I hope this helps to start!

I.

Gaurav
Level 1

Hi 

I want to know about segment analysis data extraction from Similarweb API

Please guide me

 

0 Kudos
hauwasalisu
Level 1

API calls inside DSS can be a bit tricky at first, but once you get the hang of it, it's super powerful!

To create an API call and fetch data from an external source, you'll need to use DSS's API connector. You can find a step-by-step guide on how to do this here.

If you have any specific questions or run into issues, feel free to ask - the community here is super helpful, and we're all in this together!

0 Kudos

Labels

?
Labels (1)
A banner prompting to get Dataiku