# Sample code for calling admin/virtual\_graphs/import

**URL:** <https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550>\
**Category:** Support\
**Created:** [August 16, 2023, 5:35am UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550 "2023-08-16T05:35:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_res](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mike\_res](https://community.stardog.com/u/mike_res)\
**Post date:** [August 16, 2023, 5:35am UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/1 "2023-08-16T05:35:49Z")

</div>

I was experimenting with various ETL methods, and whenI went to tinker with `POST admin/virtual_graphs/import` as an option, I was unable to find any documentation.

Ironically, while typing this post, the "topic similarity" window [did turn up a post that I would have liked to have found sooner 😉](https://community.stardog.com/t/load-json-into-a-materialized-graph-via-http-post-possible/1930/12)

In any case, here is a simple Typescript program that I wrote to test my understanding of the endpoint:

```auto
import {Axios} from 'axios'
import FormData from 'form-data' 
const fs = require('fs');

// load the JSON that we want to ingest into a string variable
// alternatively, it could be a stream .. 
const movies_sms = fs.readFileSync('/private/var/opt/stardog/movies.sms');

// load the SMS mapping that we want to use as a string
// alternatively, it could be a stream .. 
const movies_json = fs.readFileSync('/private/var/opt/stardog/movies.json');

// Build up the form
const data = new FormData();
data.append('database', 'etl_local');
data.append('mappings', movies_sms)
data.append('named_graph', 'urn:ingest_movie_using_axios');
data.append('input_file_type', 'JSON');
data.append('input_file', movies_json);

// build up a configuration for the Axios request that we'll be making
const config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'http://localhost:5820/admin/virtual_graphs/import',
  headers: { 
    'Authorization': 'Basic bm90X215X3VzZXJfbmFtZTpub3RfbXlfcGFzc3dvcmQ=', 
    ...data.getHeaders()
  },
  data : data
};

// create a new Axios object, 
// and then use it to post to /admin/virtual_graphs/import
const axios = new Axios({});
axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

```

---

<div class="post-metadata">

**Author:** ![StevePlace](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/steveplace/32/1989_2.png) [@StevePlace](https://community.stardog.com/u/StevePlace)\
**Post date:** [August 16, 2023, 2:49pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/2 "2023-08-16T14:49:50Z")

</div>

Hi Mike,

I was unable to find documentation on this as well, but fortunately we have some smart people at Stardog who pointed it out to me. You can find `admin/virtual_graphs/import` [here](https://stardog-union.github.io/http-docs/#tag/Virtual-Graphs/operation/importFileVG).

Does this give you what you need?

Best,  
Steve

---

<div class="post-metadata">

**Author:** ![mike\_res](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mike\_res](https://community.stardog.com/u/mike_res)\
**Post date:** [August 16, 2023, 3:52pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/3 "2023-08-16T15:52:53Z")

</div>

Not exactly .. which is why I published an example.

The way that I figured out how to use the endpoint was:

- I downloaded the Open API metadata: [https://stardog-union.github.io/http-docs/openapi.json](https://stardog-union.github.io/http-docs/openapi.json)
- I modified it to accept security credentials, as described here: [Creating Swagger UI Wrapper for API Access to Stardog Cloud Server](https://community.stardog.com/t/creating-swagger-ui-wrapper-for-api-access-to-stardog-cloud-hosted-server/4479)
- When I went to call the function, I (eventually) noticed that it used a "multipart/form-data" MIME type (first image)
- So I used POSTMAN to set up the call (2nd image)
- Once that succeeded, I used POSTMAN's code-generation capabilities to generate a Node script .. and then adapted that to the Typescript example above.

In the end it was simple, but it took a few guesses and false starts to stumble my way to success.

Since this seems like a particularly handy ETL method, I figured it was worth publishing a simple example to save fellow travelers some time.

Our use case involves ingesting event records from Veeva Vault QMS, so this method seems almost perfect for building a "Quality Event KG" on an event driven basis .. i.e. our agent subscribes to the event system, and stuffs mapped records into the KG upon receipt .. basically a "one-hop" ingestion pipeline with declarative transformation of content (via SMS) .. pretty much as elegant as it gets.

 ![Screenshot 2023-08-16 at 11.36.43 AM](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/1/16688aaf7a1fd6f5b345af6745e56425ae31abba.jpeg)  
 ![Screenshot 2023-08-16 at 11.40.17 AM](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/6/669ea1df0900f4152a57c886b7727a6020344d03.png)

---

<div class="post-metadata">

**Author:** ![albaker](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/albaker/32/632_2.png) [@albaker](https://community.stardog.com/u/albaker)\
**Post date:** [August 17, 2023, 1:14pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/4 "2023-08-17T13:14:03Z")

</div>

We put together our spark job for materialization of virtual graphs to provide this one stop shopping for ingestion of data and using the SMS language as the language of ETL. While the external compute docs [1] highlight the ease of use feature of integration directly with Databricks or Amazon EMR, it does work on a vanilla apache spark distribution, even on a single developer workstation, submitting the spark job. There are docs at the end there on how to programmatically set that up.

The nice thing about the spark job is that it will do the materialization in parallel, using a batched, streaming, compressed method (think transducer) for efficiently loading data into Stardog. So the translation to RDF happens complete off-board from the Stardog server, and we get to take advantage of Stardog's MVCC transaction to use multiple streaming writers to materialize the data into the server. If a simple "virtual import" for a billion triples was taking an hour or so, the spark job should finish that in 15 minutes. For sub-billion datasets, it should be super fast.

> **[Virtual Graph Materialization](https://docs.stardog.com/external-compute/vg-materialization-external-compute)**
>
> This page discusses how to materialize Virtual Graphs using external compute platform for e.g. Databricks in Stardog.

---

<div class="post-metadata">

**Author:** ![mike\_res](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@mike\_res](https://community.stardog.com/u/mike_res)\
**Post date:** [August 17, 2023, 4:16pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/5 "2023-08-17T16:16:45Z")

</div>

Thanks! This is super-interesting .. and I think that this will raise some eyebrows .. one reason being that it seems like it might be a nice complement for pipelines built using Nextflow.

---

<div class="post-metadata">

**Author:** ![albaker](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/albaker/32/632_2.png) [@albaker](https://community.stardog.com/u/albaker)\
**Post date:** [August 17, 2023, 6:14pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/6 "2023-08-17T18:14:19Z")

</div>

Yes, our intent is to use this for pipeline building in whatever ETL or workflow environment you may have. While clearly it was built with leveraging Spark (it can do the spark partitioning in addition to the parallelism to Stardog), the customer base uses this in things like Apache Airflow, DevOps hooks, and other custom pipeline or workflow configurations.

I think you're already speaking with Tim, we're happy to have more conversations on this topic.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [September 27, 2023, 6:54am UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/7 "2023-09-27T06:54:47Z")

</div>

Automatically bumped on September 27, 2023, 6:54am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [November 12, 2023, 12:30am UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/8 "2023-11-12T00:30:46Z")

</div>

Automatically bumped on November 12, 2023, 12:30am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [December 31, 2023, 5:48pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/9 "2023-12-31T17:48:36Z")

</div>

Automatically bumped on December 31, 2023, 5:48pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [February 23, 2024, 2:13pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/10 "2024-02-23T14:13:07Z")

</div>

Automatically bumped on February 23, 2024, 2:13pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [April 21, 2024, 11:50am UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/11 "2024-04-21T11:50:11Z")

</div>

Automatically bumped on April 21, 2024, 11:50am UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [August 27, 2024, 6:27pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/12 "2024-08-27T18:27:01Z")

</div>

Automatically bumped on August 27, 2024, 6:27pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [March 6, 2025, 3:53pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/13 "2025-03-06T15:53:15Z")

</div>

Automatically bumped on March 6, 2025, 3:53pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [October 14, 2025, 7:19pm UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/14 "2025-10-14T19:19:37Z")

</div>

Automatically bumped on October 14, 2025, 7:19pm UTC



---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [June 15, 2026, 12:21am UTC](https://community.stardog.com/t/sample-code-for-calling-admin-virtual-graphs-import/4550/15 "2026-06-15T00:21:43Z")

</div>

Automatically bumped on June 15, 2026, 12:21am UTC


