# Create Or Update Order — AmeriCommerce

> Creates a new order or updates an existing one. See the documentation here and here.

- Key: `americommerce-create-update-order`
- Type: Action (Write)
- Version: 0.0.2
- App: AmeriCommerce (`americommerce`) — https://pipedream.com/apps/americommerce.md
- This page (HTML): https://pipedream.com/apps/americommerce/actions/create-update-order
- Hints: destructive · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/americommerce/actions/create-update-order/create-update-order.mjs

## Description

Creates a new order or updates an existing one. [See the documentation here](https://developers.cart.com/docs/rest-api/3f2ab73188031-create-an-order) and [here](https://developers.cart.com/docs/rest-api/e2649bb3adba9-update-an-order).

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `orderId` | `string` | No | The unique identifier for the order. Required for updating or changing the status of an order. Options are loaded from the connected account. |
| `customerId` | `string` | No | The unique identifier for the customer. This ID is optional. Options are loaded from the connected account. |
| `orderStatusId` | `string` | No | The ID of the order status. Options are loaded from the connected account. |
| `orderShippingAddressId` | `string` | No | The ID of the order's shipping address. Options are loaded from the connected account. |
| `orderBillingAddressId` | `string` | No | The ID of the order's billing address. Options are loaded from the connected account. |
| `customerTypeId` | `string` | No | The customer type ID for the customer. Options are loaded from the connected account. |
| `specialInstructions` | `string` | No | Special instructions for the order. |
| `subtotal` | `string` | No | The subtotal of the order. |
| `taxTotal` | `string` | No | The total tax for the order or tax added to the order. |
| `shippingTotal` | `string` | No | The total shipping cost for the order or shipping added to the order. |
| `discountTotal` | `string` | No | The total discount for the order. |
| `grandTotal` | `string` | No | The grand total of the order. |
| `costTotal` | `string` | No | The total cost of the order. |
| `selectedShippingMethod` | `string` | No | The selected shipping method for the order. Options are loaded from the connected account. |
| `referrer` | `string` | No | The referrer for the order. |
| `adminComments` | `string` | No | Comments from the admin about the order. |
| `source` | `string` | No | The source of the order. |
| `searchPhrase` | `string` | No | The search phrase for the order. |
| `storeId` | `string` | No | The ID of the store. Options are loaded from the connected account. |
| `isPpc` | `boolean` | No | Whether the order is a PPC order. |
| `ppcKeyword` | `string` | No | The PPC keyword for the order. |
| `handlingTotal` | `string` | No | The handling total for the order. |
| `isPaymentOrderOnly` | `boolean` | No | Whether the order is a payment order only. |
| `selectedShippingProviderService` | `string` | No | The selected shipping provider service for the order. |
| `additionalFees` | `string` | No | Additional fees for the order. |
| `adcodeId` | `string` | No | The adcode ID for the customer. Options are loaded from the connected account. |
| `isGift` | `boolean` | No | Whether the order is a gift. |
| `giftMessage` | `string` | No | The gift message for the order. |
| `publicComments` | `string` | No | Public comments about the order. |
| `instructions` | `string` | No | Instructions for the order. |
| `sourceGroup` | `string` | No | The source group for the order. |
| `fromSubscriptionId` | `string` | No | The ID of the subscription. Options are loaded from the connected account. |
| `discountedShippingTotal` | `string` | No | The discounted shipping total for the order. |
| `orderNumber` | `string` | No | The order number. |
| `couponCode` | `string` | No | The coupon code for the order. |
| `orderType` | `string` | No | The type of order. |
| `expires` | `boolean` | No | Whether the order expires. |
| `campaignCode` | `string` | No | The campaign code for the order. |
| `rewardPointsCredited` | `boolean` | No | Whether the reward points are credited. |
| `channel` | `string` | No | The channel for the order. |
| `device` | `string` | No | The device for the order. |
| `dueDate` | `string` | No | The due date for the order. Eg. 2021-05-14 |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "americommerce",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "americommerce-create-update-order",
  arguments: {
    orderId: "Order ID",
    customerId: "Customer ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "americommerce-create-update-order",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    americommerce: { authProvisionId: "apn_xxxxxxx" },
    orderId: "Order ID",
    customerId: "Customer ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "americommerce-create-update-order",
    "configured_props": {
      "americommerce": { "authProvisionId": "apn_xxxxxxx" },
      "orderId": "Order ID",
      "customerId": "Customer ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/americommerce.md · All apps: https://pipedream.com/apps
