# @gojob/sfmc-rest-sdk

> Salesforce Marketing Cloud REST API client

Latest version **1.0.3** (published 2021-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @gojob/sfmc-rest-sdk
pnpm add @gojob/sfmc-rest-sdk
yarn add @gojob/sfmc-rest-sdk
bun add @gojob/sfmc-rest-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-01-13 |
| First published | 2020-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 51.3 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yannis Torres |
| Maintainers | vinceops, davidolivier1337, miramo, typedef |
| Keywords | sfmc, salesforce, client |

## Links

- npm: https://www.npmjs.com/package/@gojob/sfmc-rest-sdk
- Repository: https://github.com/gojob-1337/sfmc-rest-sdk
- Homepage: https://github.com/gojob-1337/sfmc-rest-sdk#readme
- Issues: https://github.com/gojob-1337/sfmc-rest-sdk/issues
- npm.io page: https://npm.io/package/@gojob/sfmc-rest-sdk

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-01-13
- 1.0.2 — 2021-01-12
- 1.0.1 — 2020-07-07
- 1.0.0 — 2020-07-07

## README

# @gojob/sfmc-rest-sdk

## NPM publish

**To publish a new version of this package, you have to build the project before run `npm publish`.**

## Description

The purpose of this library is to provide a Typescript wrapper around Salesforce Marketing Cloud API: [SFMC](https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/index-api.htm).

## Installation

```
yarn add @gojob/sfmc-rest-sdk
```

## Usage example

```typescript
import SFMC from '@gojob/sfmc-rest-sdk';

const sdk = new SFMC({
  domain: "mcdomainname",
  clientId: "123",
  clientSecret: "456",
  grantType: "client_credentials",
});

// ...

const makeSyncRequest = async () => {
  try {
    await sdk.dataEvents.sync.insertRows(
      [{
        keys: { subscriber_key: '123' },
        values: { email: 'test-123@example.com' },
      }],
      "DATAEXTENSION_KEY"
    );
  } catch (e) {
    console.log(e);
  }
};

await makeSyncRequest();
```

## Documentation

### Authentification

When dealing with SFMC REST API, all requests have to be authentified through a OAuth token that has a time based expiration. 
All requests must also be correctly declaring permission roles.
__This sdk handle automatic authentification and token renewal through the v2/token Marketing Cloud APIs__


### Requestable

In addition to authentification, the Requestable class can be used to request any REST endpoint of the Marketing Cloud APIs that wouldn't be wrapped into existing classes

```typescript
import { Requestable } from '@gojob/sfmc-rest-sdk';

const req = new Requestable();

req.authenticatedRequest({
  type: RequestType.POST,
  endpoint: `hub/whatever/mc/endpoint`,
  scope: Scope.according_scope,
  data,
});


```

### API wrapper classes

|       Class    |                                            REST API Doc                                                   |  Description                      |
|:--------------:|:---------------------------------------------------------------------------------------------------------:|-----------------------------------|
| Auth           | [SFMC.Auth](https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/getBaseURLs.htm)            | Authentification V2 token API     |
| DataEventsSync | [SFMC.DataEvents](https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/asynchronous_processing_scenarios.htm)                                                | Sync operations on dataextensions |
| DataEventsASync | [SFMC.DataEvents](https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/asynchronous_processing_scenarios.htm)                                                | Sync operations on dataextensions |

#### Data Events API

---
_Source: https://npm.io/package/@gojob/sfmc-rest-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
