Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions docs-v2/pages/connect/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ import { createClient } from "@pipedream/sdk/browser"
import { serverConnectTokenCreate } from "./server"

const { token, expires_at } = await serverConnectTokenCreate({
app_slug: appSlug, // The app's name slug — see the quickstart
oauth_app_id: oauthAppId, // The OAuth app ID, if you're connecting an OAuth app — keep this in config / a DB, pass here
external_id: externalUserId // The end user's ID in your system
});

Expand Down Expand Up @@ -148,9 +146,9 @@ POST /tokens

##### Parameters

- `app_slug` - [The app's name slug](/quickstart#find-your-apps-name-slug)
- `oauth_app_id` - [The OAuth app ID](/quickstart#creating-a-custom-oauth-client), if you're connecting an OAuth app — keep this in config / a DB, pass here
- `external_id` - [The external user ID](#external-users) in your system
- `success_redirect_uri` — _Optional_. The URL to redirect the user to after they successfully connect an account
- `error_redirect_uri` — _Optional_. The URL to redirect the user to if they encounter an error during the connection flow

##### Examples

Expand Down Expand Up @@ -180,8 +178,6 @@ export async function serverConnectTokenCreate(opts: ConnectTokenCreateOpts): Pr
}

const { token, expires_at } = await serverConnectTokenCreate({
app_slug: appSlug, // The app's name slug
oauth_app_id: oauthAppId, // The OAuth app ID, if you're connecting an OAuth app — keep this in config / a DB, pass here
external_id: externalUserId // The end user's ID in your system
});
```
Expand Down Expand Up @@ -225,8 +221,6 @@ const client = new Client({
});

const connectTokenOpts = {
app_slug: "YOUR_APP_SLUG", // The app's name slug
oauth_app_id: "o_abc123", // The OAuth app ID, if you're connecting an OAuth app — keep this in config / a DB, pass here
external_id: "USER_ID" // The end user's ID in your system
}

Expand Down Expand Up @@ -277,8 +271,6 @@ client = Client({
})

connect_token_opts = {
'app_slug': "YOUR_APP_SLUG",
'oauth_app_id': "o_abc123",
'external_id': "USER_ID"
}

Expand Down Expand Up @@ -313,7 +305,7 @@ public class Client {
return "Basic " + encoded;
}

public String connectTokenCreate(String appSlug, String oauthClientId, String externalId) throws Exception {
public String connectTokenCreate(String externalId) throws Exception {
String auth = authorizationHeader();
URL url = new URL(baseURL + "/v1/connect/tokens");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Expand All @@ -322,7 +314,7 @@ public class Client {
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);

String jsonInputString = String.format("{\"app_slug\":\"%s\",\"oauth_app_id\":\"%s\",\"external_id\":\"%s\"}", appSlug, oauthClientId, externalId);
String jsonInputString = String.format("{\"external_id\":\"%s\"}", externalId);

try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
Expand All @@ -336,7 +328,7 @@ public class Client {
Client client = new Client("YOUR_SECRET_KEY", "YOUR_PUBLIC_KEY");

// Expose this code as an API endpoint in your server to fetch the token from the frontend
String response = client.connectTokenCreate("YOUR_APP_SLUG", "o_abc123", "USER_ID");
String response = client.connectTokenCreate("USER_ID");
}
}

Expand Down Expand Up @@ -367,13 +359,13 @@ public class Client {
return $"Basic {encoded}";
}

public async Task<string> ConnectTokenCreate(string appSlug, string oauthClientId, string externalId) {
public async Task<string> ConnectTokenCreate(string externalId) {
string auth = AuthorizationHeader();
using (HttpClient client = new HttpClient()) {
client.DefaultRequestHeaders.Add("Authorization", auth);
client.DefaultRequestHeaders.Add("Content-Type", "application/json");

var content = new StringContent($"{{\"app_slug\":\"{appSlug}\",\"oauth_app_id\":\"{oauthClientId}\",\"external_id\":\"{externalId}\"}}", Encoding.UTF8, "application/json");
var content = new StringContent($"{{\"external_id\":\"{externalId}\"}}", Encoding.UTF8, "application/json");
var response = await client.PostAsync($"{baseURL}/v1/connect/tokens", content);

return await response.Content.ReadAsStringAsync();
Expand All @@ -384,7 +376,7 @@ public class Client {
var client = new Client("YOUR_SECRET_KEY", "YOUR_PUBLIC_KEY");

// Expose this code as an API endpoint in your server to fetch the token from the frontend
string response = await client.ConnectTokenCreate("YOUR_APP_SLUG", "o_abc123", "USER_ID");
string response = await client.ConnectTokenCreate("USER_ID");
}
}

Expand Down Expand Up @@ -424,13 +416,11 @@ func (c *Client) authorizationHeader() string {
return fmt.Sprintf("Basic %s", encoded)
}

func (c *Client) ConnectTokenCreate(appSlug, oauthClientId, externalId string) (map[string]interface{}, error) {
func (c *Client) ConnectTokenCreate(externalId string) (map[string]interface{}, error) {
auth := c.authorizationHeader()
url := fmt.Sprintf("%s/v1/connect/tokens", c.BaseURL)

opts := map[string]string{
"app_slug": appSlug,
"oauth_app_id": oauthClientId,
"external_id": externalId,
}

Expand Down Expand Up @@ -465,7 +455,7 @@ func main() {
client := NewClient("YOUR_SECRET_KEY", "YOUR_PUBLIC_KEY")

// Expose this code as an API endpoint in your server to fetch the token from the frontend
response, err := client.ConnectTokenCreate("YOUR_APP_SLUG", "o_abc123", "USER_ID")
response, err := client.ConnectTokenCreate( "USER_ID")
if err != nil {
fmt.Println("Error:", err)
return
Expand Down Expand Up @@ -496,13 +486,11 @@ class Client {
return "Basic $encoded";
}

public function connectTokenCreate($appSlug, $oauthClientId, $externalId) {
public function connectTokenCreate($externalId) {
$auth = $this->authorizationHeader();
$url = "$this->baseURL/v1/connect/tokens";

$data = json_encode([
'app_slug' => $appSlug,
'oauth_app_id' => $oauthClientId,
'external_id' => $externalId
]);

Expand All @@ -528,13 +516,11 @@ class Client {
$client = new Client('YOUR_SECRET_KEY', 'YOUR_PUBLIC_KEY');

$connectTokenOpts = [
'app_slug' => "YOUR_APP_SLUG",
'oauth_app_id' => "o_abc123",
'external_id' => "USER_ID"
];

// Expose this code as an API endpoint in your server to fetch the token from the frontend
$response = $client->connectTokenCreate($connectTokenOpts['app_slug'], $connectTokenOpts['oauth_app_id'], $connectTokenOpts['external_id']);
$response = $client->connectTokenCreate($connectTokenOpts['external_id']);
?>
```
</Tabs.Tab>
Expand Down Expand Up @@ -564,7 +550,7 @@ class Client
req = Net::HTTP::Post.new(uri)
req['Authorization'] = authorization_header
req['Content-Type'] = 'application/json'
req.body = { app_slug: app_slug, oauth_app_id: oauth_app_id, external_id: external_id }.to_json
req.body = { external_id: external_id }.to_json

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
Expand All @@ -577,13 +563,11 @@ end
client = Client.new('YOUR_SECRET_KEY', 'YOUR_PUBLIC_KEY')

connect_token_opts = {
app_slug: "YOUR_APP_SLUG",
oauth_app_id: "o_abc123",
external_id: "USER_ID"
}

# Expose this code as an API endpoint in your server to fetch the token from the frontend
response = client.connect_token_create(connect_token_opts[:app_slug], connect_token_opts[:oauth_app_id], connect_token_opts[:external_id])
response = client.connect_token_create(connect_token_opts[:external_id])
```
</Tabs.Tab>
</Tabs>
Expand Down
86 changes: 36 additions & 50 deletions docs-v2/pages/connect/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ const client = new Client({
});

const connectTokenOpts = {
app_slug: "YOUR_APP_SLUG", // The app's name slug
oauth_app_id: "o_abc123", // The OAuth app ID, if you're connecting an OAuth app — keep this in config / a DB, pass here
external_id: "USER_ID" // The end user's ID in your system
}

Expand All @@ -187,39 +185,37 @@ import json
import requests

class Client:
def __init__(self, opts):
self.secret_key = opts['secret_key']
self.public_key = opts['public_key']
def __init__(self, opts):
self.secret_key = opts['secret_key']
self.public_key = opts['public_key']

api_host = 'api.pipedream.com'
self.base_url = f"https://{api_host}"

def _authorization_header(self):
encoded = base64.b64encode(f"{self.public_key}:{self.secret_key}".encode()).decode()
return f"Basic {encoded}"

def connect_token_create(self, opts):
auth = self._authorization_header()
response = requests.post(
f"{self.base_url}/v1/connect/tokens",
headers={
"Authorization": auth,
"Content-Type": "application/json",
},
data=json.dumps(opts)
)
return response.json()
api_host = 'api.pipedream.com'
self.base_url = f"https://{api_host}"

def _authorization_header(self):
encoded = base64.b64encode(f"{self.public_key}:{self.secret_key}".encode()).decode()
return f"Basic {encoded}"

def connect_token_create(self, opts):
auth = self._authorization_header()
response = requests.post(
f"{self.base_url}/v1/connect/tokens",
headers={
"Authorization": auth,
"Content-Type": "application/json",
},
data=json.dumps(opts)
)
return response.json()

# Usage example
client = Client({
'public_key': 'YOUR_PUBLIC_KEY',
'secret_key': 'YOUR_SECRET_KEY',
'public_key': 'YOUR_PUBLIC_KEY',
'secret_key': 'YOUR_SECRET_KEY',
})

connect_token_opts = {
'app_slug': "YOUR_APP_SLUG",
'oauth_app_id': "o_abc123",
'external_id': "USER_ID"
'external_id': "USER_ID"
}

# Expose this code as an API endpoint in your server to fetch the token from the frontend
Expand Down Expand Up @@ -253,7 +249,7 @@ public class Client {
return "Basic " + encoded;
}

public String connectTokenCreate(String appSlug, String oauthClientId, String externalId) throws Exception {
public String connectTokenCreate(String externalId) throws Exception {
String auth = authorizationHeader();
URL url = new URL(baseURL + "/v1/connect/tokens");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Expand All @@ -262,7 +258,7 @@ public class Client {
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);

String jsonInputString = String.format("{\"app_slug\":\"%s\",\"oauth_app_id\":\"%s\",\"external_id\":\"%s\"}", appSlug, oauthClientId, externalId);
String jsonInputString = String.format("{\"external_id\":\"%s\"}", externalId);

try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
Expand All @@ -276,7 +272,7 @@ public class Client {
Client client = new Client("YOUR_SECRET_KEY", "YOUR_PUBLIC_KEY");

// Expose this code as an API endpoint in your server to fetch the token from the frontend
String response = client.connectTokenCreate("YOUR_APP_SLUG", "o_abc123", "USER_ID");
String response = client.connectTokenCreate("USER_ID");
}
}

Expand Down Expand Up @@ -307,13 +303,13 @@ public class Client {
return $"Basic {encoded}";
}

public async Task<string> ConnectTokenCreate(string appSlug, string oauthClientId, string externalId) {
public async Task<string> ConnectTokenCreate(string externalId) {
string auth = AuthorizationHeader();
using (HttpClient client = new HttpClient()) {
client.DefaultRequestHeaders.Add("Authorization", auth);
client.DefaultRequestHeaders.Add("Content-Type", "application/json");

var content = new StringContent($"{{\"app_slug\":\"{appSlug}\",\"oauth_app_id\":\"{oauthClientId}\",\"external_id\":\"{externalId}\"}}", Encoding.UTF8, "application/json");
var content = new StringContent($"{{\"external_id\":\"{externalId}\"}}", Encoding.UTF8, "application/json");
var response = await client.PostAsync($"{baseURL}/v1/connect/tokens", content);

return await response.Content.ReadAsStringAsync();
Expand All @@ -324,7 +320,7 @@ public class Client {
var client = new Client("YOUR_SECRET_KEY", "YOUR_PUBLIC_KEY");

// Expose this code as an API endpoint in your server to fetch the token from the frontend
string response = await client.ConnectTokenCreate("YOUR_APP_SLUG", "o_abc123", "USER_ID");
string response = await client.ConnectTokenCreate("USER_ID");
}
}

Expand Down Expand Up @@ -364,13 +360,11 @@ func (c *Client) authorizationHeader() string {
return fmt.Sprintf("Basic %s", encoded)
}

func (c *Client) ConnectTokenCreate(appSlug, oauthClientId, externalId string) (map[string]interface{}, error) {
func (c *Client) ConnectTokenCreate(externalId string) (map[string]interface{}, error) {
auth := c.authorizationHeader()
url := fmt.Sprintf("%s/v1/connect/tokens", c.BaseURL)

opts := map[string]string{
"app_slug": appSlug,
"oauth_app_id": oauthClientId,
"external_id": externalId,
}

Expand Down Expand Up @@ -405,7 +399,7 @@ func main() {
client := NewClient("YOUR_SECRET_KEY", "YOUR_PUBLIC_KEY")

// Expose this code as an API endpoint in your server to fetch the token from the frontend
response, err := client.ConnectTokenCreate("YOUR_APP_SLUG", "o_abc123", "USER_ID")
response, err := client.ConnectTokenCreate("USER_ID")
if err != nil {
fmt.Println("Error:", err)
return
Expand Down Expand Up @@ -436,13 +430,11 @@ class Client {
return "Basic $encoded";
}

public function connectTokenCreate($appSlug, $oauthClientId, $externalId) {
public function connectTokenCreate($externalId) {
$auth = $this->authorizationHeader();
$url = "$this->baseURL/v1/connect/tokens";

$data = json_encode([
'app_slug' => $appSlug,
'oauth_app_id' => $oauthClientId,
'external_id' => $externalId
]);

Expand All @@ -468,13 +460,11 @@ class Client {
$client = new Client('YOUR_SECRET_KEY', 'YOUR_PUBLIC_KEY');

$connectTokenOpts = [
'app_slug' => "YOUR_APP_SLUG",
'oauth_app_id' => "o_abc123",
'external_id' => "USER_ID"
];

// Expose this code as an API endpoint in your server to fetch the token from the frontend
$response = $client->connectTokenCreate($connectTokenOpts['app_slug'], $connectTokenOpts['oauth_app_id'], $connectTokenOpts['external_id']);
$response = $client->connectTokenCreate($connectTokenOpts['external_id']);
?>
```
</Tabs.Tab>
Expand Down Expand Up @@ -504,7 +494,7 @@ class Client
req = Net::HTTP::Post.new(uri)
req['Authorization'] = authorization_header
req['Content-Type'] = 'application/json'
req.body = { app_slug: app_slug, oauth_app_id: oauth_app_id, external_id: external_id }.to_json
req.body = { external_id: external_id }.to_json

res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
Expand All @@ -517,13 +507,11 @@ end
client = Client.new('YOUR_SECRET_KEY', 'YOUR_PUBLIC_KEY')

connect_token_opts = {
app_slug: "YOUR_APP_SLUG",
oauth_app_id: "o_abc123",
external_id: "USER_ID"
}

# Expose this code as an API endpoint in your server to fetch the token from the frontend
response = client.connect_token_create(connect_token_opts[:app_slug], connect_token_opts[:oauth_app_id], connect_token_opts[:external_id])
response = client.connect_token_create(connect_token_opts[:external_id])
```
</Tabs.Tab>
</Tabs>
Expand All @@ -534,8 +522,6 @@ In our Next.js app, we call the `serverConnectTokenCreate` method from the front
import { serverConnectTokenCreate } from "./server"

const { token, expires_at } = await serverConnectTokenCreate({
app_slug: appSlug, // The app's name slug, passed from the frontend
oauth_app_id: oauthAppId, // The OAuth app ID, if you're connecting an OAuth app — keep this in config / a DB, pass here
external_id: externalUserId // The end user's ID in your system
});
```
Expand Down
Loading
Loading