Study plan for GraphQL in Salesforce Marketing Cloud
Tags: salesforce, database, etl
Published: 2020-09-17 13:01:01

---
title: Study plan for GraphQL in Salesforce Marketing Cloud
description: "Can SSJS callouts to APIs work for you?"
published: true
date: 2020-09-15 15:00:00 UTC
tags: salesforce, database, etl
canonical_url: https://katiekodes.com/practice-sfmc-graphql/
---

I’ve been collaborating again with Salesforce Marketing Cloud expert [Kyle Griffin](https://sailsforce.org/salesforce-blog/), this time thinking through what it would require to build SFMC data extensions from queries against an Oracle database.

The traditional way to fetch data from a remote Oracle database is to connect to it over [ODBC](https://en.wikipedia.org/wiki/Open_Database_Connectivity) and send plain text representing [SQL queries](https://en.wikipedia.org/wiki/SQL) over the ODBC connection.

The software with which you want to fetch the data _(in this case, Marketing Cloud)_ is typically responsible for handling the details of ODBC as well as for helping you turn the data that comes back into some sort of useful table-shaped data structure within your software _(e.g. a data extension)_.

* * *

Unfortunately, neither of our Google skills have turned up any hint that Marketing Cloud is capable of doing all this for Kyle.

Instead, if Kyle wanted to turn SQL queries into SFMC data extensions, he’d have to type those queries into some sort of [ETL tool](https://en.wikipedia.org/wiki/Extract,_transform,_load) capable of:

1. connecting to the database over ODBC and downloading data as queried with SQL
2. generating [CSV files](https://en.wikipedia.org/wiki/Comma-separated_values) from the downloading data
3. connecting to Marketing Cloud over SFTP and sending it the CSV files

* * *

However, this particular Oracle database also has an [HTTP](https://dev.to/katiekodes/intro-to-http-for-data-folks-managers-especially-24n6)-based [GraphQL](https://katiekodes.com/graphql-notes/) application programming interface _([API](https://katiekodes.com/introduction-salesforce-rest-apis/#3--call-a-3rd-partys-endpoint-living-outside-salesforce))_.

Theoretically, I think this might give Kyle another option.

{% link https://dev.to/katiekodes/intro-to-http-for-data-folks-managers-especially-24n6 %}

According to Ivan Razine, you can [create a SFMC Data Extension with Server-Side JavaScript _(SSJS)_ code](https://ampscript.xyz/how-tos/how-to-create-a-data-extension-with-server-side-javascript/).

[If you can also populate a data extension’s contents with SSJS and/or AMPscript](https://salesforce.stackexchange.com/a/279560), and if SSJS/AMPscript can make callouts to HTTP-based APIs sitting outside of Marketing Cloud, then I don’t see why code couldn’t be written to query the data from Oracle over its GraphQL interface.

Kyle is curious about this option because leaving the text of all the queries against Oracle inside of Marketing Cloud gives him more control over their maintenance than he would have if an ETL tool were in the way.

* * *

I don’t know enough about Marketing Cloud to dive in deep at this point, but here’s the game plan I told Kyle I’d follow if I were looking into it:

1. Make a “hello world” project in Marketing Cloud that builds a Data Extension based on data retrieved from a `GET` HTTP operation against `https://yesno.wtf/api`.    
  - Treat the data that comes back as a 3-column, 1-row result set.
  - Be sure to leverage Postman or other GUI-based HTTP-request-making desktop software to ensure you’ve got the requests to YesNo working before you try to implement them in MarketingCloud.
2. Repeat the success from step 2 with another API whose dummy data you like _(based on exploring it with Postman)_ from [this list of public APIs](https://github.com/public-apis/public-apis).    
  - Presuming the returned data is different, note the different steps you have to go through to turn it into something “table-shaped” and put it into a Data Extension.
3. Try again, this time forcing Marketing Cloud to make an HTTP request to a [Postman Echo](https://docs.postman-echo.com/) that requires authentication.    
  - Your goal is to verify that you and your security team are comfortable with the mechanisms Marketing Cloud offers for storing secrets _ **secretly** _ and for using them later in HTTP-request-making SSJS/AMPscript.
4. Play with fetching data from an API that asks for you to pass it “GraphQL” queries, such as a `POST` request to `https://api.graphql.jobs`.    
  - Here’s some text representing a nice little 4-column, many-row query against that API:

```
  {\r\n jobs\r\n {\r\n title\r\n postedAt\r\n description\r\n applyUrl\r\n }\r\n}

```

If, after completing these projects _(and learning a heck of a lot of coding in the process!)_, you feel like this is an exciting and maintainable data integration architecture, reach out to your Oracle database experts to discuss the details of the GraphQL API it offers.

Don’t worry if you hit dead ends: remember that your organization’s trusty ETL tool optimized for SQL & SFTP will be excited to see you again.