Is there a way to retrieve or export cards data to csv using Domo API?

Gus
Gus ⚪️
edited November 2021 in Domo Developer

I have a page created with a number of cards. Is it possible to retrieve card data or export to a csv using the API?

I know API allows to export datasets to csv, but I can't find a way to do the same for cards.

If not possible, is there any workaround to set it up in Domo so I can only retrieve card data with the API and not whole dataset?

Answers

  • GrantSmith
    GrantSmith Indiana 🥷

    Hi @Gus

    Card definitions are stored in JSON format. You can utilize the Java CLI (https://domohelp.domo.com/hc/en-us/articles/360043437733-Command-Line-Interface-CLI-Tool) and the backup-card command to export a card definition to a file. It also gives you the ability to backup the drillpath as well.



    **Was this post helpful? Click Agree or Like below**

    **Did this solve your problem? Accept it as a solution!**
  • MarkSnodgrass
    MarkSnodgrass Portland, Oregon 🥷

    It sounds like you are wanting the card data and not the card definition, which you can get my choosing Send/Export and choosing CSV. To do that via API, I would suggest watching the network traffic using the Inspect option when you click those options on the card and see what APIs they call.




    **Make sure to <3 any users posts that helped you.
    **Please mark as accepted the ones who solved your issue.
  • GrantSmith
    GrantSmith Indiana 🥷

    Ah I misunderstood the request. There is an export-data option with the CLI to export a dataset which can take a query so you could attempt to replicate the query your card is using and pass that along through the CLI but as @MarkSnodgrass mentioned you may need to watch the traffic to get the exact query it’s using



    **Was this post helpful? Click Agree or Like below**

    **Did this solve your problem? Accept it as a solution!**
  • Thanks for the answers.

    Right, I want the card data and not the definition.

    I found the API call that it's done by checking Network Inspect as @MarkSnodgrass suggested, it seems to be a POST request to:

    /api/content/v1/cards/<card_id>/export

    So, then I tried to replicated that call using my credentials etc for API auth as explained here:

    https://developer.domo.com/docs/authentication/overview-4

    I can get the access token just fine, but when I try the card export endpoint (using the access token), I'm getting the following error as response:

    {"status": 401, "statusReason": "Unauthorized", "path": "/api/content/v1/cards/<card_id>/export", "message": "Full authentication is required to access this resource", "toe": "9RIG0EVAZK-KK34M-HW29Z"}

    Any ideas?

  • GrantSmith
    GrantSmith Indiana 🥷

    @Gus

    You need to pass your API token in under the X-DOMO-DEVELOPER-TOKEN header variable (assuming you generated it under More - Admin - Authentication - Access Token) not the Authorization header.


    curl -v -H X-DOMO-DEVELOPER-TOKEN:'{access-token}' "https://[INSTANCE].domo.com/api/content/v1/cards/<card_id>/export"
    


    **Was this post helpful? Click Agree or Like below**

    **Did this solve your problem? Accept it as a solution!**
  • @GrantSmith - Thanks again to your replies above, I was able to extract the card definitions into JSON files, repoint the datasetId and import the cards into another instance. However, I have been stuck for a few days trying to reconstruct the card back into the original dashboard layout.

    1) I looked at the Page API but it only lists the collectionIds.

    2) I also tried the export-dashboard in the DOMO CLI but it exports into a pdf :(

    Are you able to point me the right direction? Many thanks

  • GrantSmith
    GrantSmith Indiana 🥷

    You can use the page layout API to get the definition and to also save the updated definition.

    https://[INSTANCE].domo.com/api/content/v4/pages/layouts/[PAGEID]

    use a GET request to get the definition and a PUT request (with the JSON definition as the body of your request) to save the updated definition


    Note: This is not officially supported by Domo. Use at your own risk. If not done properly can completely break you page and cause it to fail to load. Also, these APIs can change at any time.



    **Was this post helpful? Click Agree or Like below**

    **Did this solve your problem? Accept it as a solution!**
  • Thanks for that @GrantSmith, that was really helpful. Took me a while to realize the v# on my instance is different :(

    Whilst I managed to get a 200 response, the title on the dashboard remain unchanged even after running the PUT & refreshing the page. Is below the right way to update the Page Layout ?


  • GrantSmith
    GrantSmith Indiana 🥷

    Make sure you're using the correct layout id. Also you may need to do a PUT request to the writelock endpoint (https://[INSTANCE].domo.com/api/content/v3/pages/layouts/[LAYOUT_ID]/writelock ) to establish a write lock before attempting to save your layout and then issue a DELETE request to the same writelock endpoint to release the writelock.

    The JSON structure that is sent in the PUT request to save the actual layout is slightly different than what you get back from the GET request. You'll need to monitor network traffic to get the exact structure needed (right-click in the browser, select inspect element, then select the network tab. Click Save on the layout to see what request is being sent)



    **Was this post helpful? Click Agree or Like below**

    **Did this solve your problem? Accept it as a solution!**
  • @GrantSmith Wowee !! That was it, the lock & release. Thanx for the tips :)