Saltar al contenido principal

Una publicaci贸n etiquetados con "sdk"

Ver Todas las Etiquetas

3 min de lectura
Alex Mullans

The Drive APIs bring the power of DoorDash鈥檚 same-day local delivery to your application. You can build an app, using any programming language and runtime you want, to deliver goods from you to your customers鈥搊r from your customers back to you! Your application calls the APIs, and Dashers deliver your goods. Now, to make it even faster to add delivery to your application, we鈥檙e introducing SDKs for common languages, starting with JavaScript.

The new DoorDash Node.js SDK takes care of the boilerplate work of using our API, like setting up the authentication token and making HTTP requests. SDKs generally make it faster to use an API because they take care of this boilerplate work so you can get right to the task you鈥檙e trying to achieve鈥搒ay, creating a delivery and requesting a Dasher. They can also help you write code more quickly because your code editor can provide inline documentation and autocomplete suggestions.

In the screenshot below, the code on the left creates a delivery using the Create Delivery API directly; the code on the right, using the DoorDash Node.js SDK.

A screenshot comparing JavaScript code calling the APIs directly vs. using the DoorDash Node.js SDK

Install the SDK to get started

Getting started with our Node.js SDK is easy: just run npm i --save @doordash/sdk to install it from npm and then reference it in your application.

The SDK's readme contains snippets showing you how to use the SDK in both JavaScript and TypeScript. If you don鈥檛 have the access key details needed to create the client, you can create them in the Developer Portal.

Note: You must be using the new Drive APIs, not the Drive (Classic) APIs, to use the DoorDash Node.js SDK.

Examples of using the SDK

Here鈥檚 a simple example of creating a delivery in JavaScript:

import { DoorDashClient } from '@doordash/sdk'
import { v4 as uuidv4 } from 'uuid'

const client = new DoorDashClient({
developer_id: '{your developer_id}',
key_id: '{your key_id}',
signing_secret: '{your signing_secret}',
})

const response = await client.createDelivery({
external_delivery_id: uuidv4(),
pickup_address: '1000 4th Ave, Seattle, WA, 98104',
pickup_phone_number: '+1(650)5555555',
dropoff_address: '1201 3rd Ave, Seattle, WA, 98101',
dropoff_phone_number: '+1(650)5555555',
})

And here鈥檚 one in TypeScript:

import {
DeliveryResponse,
DoorDashAuthorizationError,
DoorDashClient,
DoorDashResponse,
} from '@doordash/sdk'

import { v4 as uuidv4 } from 'uuid'

const client = new DoorDashClient({
developer_id: '{your developer_id}',
key_id: '{your key_id}',
signing_secret: '{your signing_secret}',
})

client
.createDelivery({
external_delivery_id: uuidv4(),
pickup_address: '1000 4th Ave, Seattle, WA, 98104',
pickup_phone_number: '+1(650)5555555',
dropoff_address: '1201 3rd Ave, Seattle, WA, 98101',
dropoff_phone_number: '+1(650)5555555',
})
.then((response: DoorDashResponse<DeliveryResponse>) => {
// do something
})
.catch((err: any) => {
// handle error
})

As the DoorDash Developer community grows, we expect to create more SDKs in additional languages. Bookmark our blog to stay updated.