question

adamc avatar image
adamc asked ·

Add a customer to an order through the REST API?

I posted to create an order, then tried adding a customer by posting to that order's url with

{"customers":[{"id": "a customer id"}]}

as the body. But the customer does not seem to be associated with the order, eg, when I get the order with expand=customers.

How can I associate a customer with an order through the REST API?

EDIT: The create call with {"state": "open"} is working fine. Here is the update call I'm making (using a bit of clojure notation, but I'll edit it if it isn't clear):

{:query-params {:expand "lineItems,customers,discounts"},
 :headers {"Authorization" "Bearer [redacted]",
           "Content-Type" "application/json"},
 :body "{\"customers\":[{\"id\":\"P66PMHWPYATD6\"}]}",
 :method :post,
 :url "https://apisandbox.dev.clover.com/v3/merchants/BQJ0X97C7Y6R0/orders/"}

And the response body:

{"clientCreatedTime" 1447295250000,
 "manualTransaction" false,
 "currency" "USD",
 "groupLineItems" true,
 "id" "GQY6HNYM2ZFD8",
 "createdTime" 1447295250000,
 "href" "https://sandbox.dev.clover.com/v3/merchants/BQJ0X97C7Y6R0/orders/GQY6HNYM2ZFD8",
 "isVat" false,
 "modifiedTime" 1447295250000,
 "testMode" false,
 "taxRemoved" false}

And getting that order with expand=customers through the API confirms that the order has no customers.

If I get https://apisandbox.dev.clover.com/v3/... the response is

{"href": "https://sandbox.dev.clover.com/v3/merchants/BQJ0X97C7Y6R0/customers/P66PMHWPYATD6",
 "id": "P66PMHWPYATD6",
 "firstName": "fae",
 "marketingAllowed": false,
 "customerSince": 1447204452000}

So the customer is there.

EDIT 2: I was posting to the wrong route. I didn't get the order id from the response properly and wound up with nil, concatenated it on to the order url, and got /v3/merchants/BQJ0X97C7Y6R0/orders/ instead of /v3/merchants/BQJ0X97C7Y6R0/orders/GQY6HNYM2ZFD8, which was still a valid URL to post to, so I missed the error.

OrdersCustomers
1 comment
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I see the issue. I had a bug that wasn't including the order id in the URL for the second POST.

0 Likes 0 · ·
Jacob Abrams avatar image
Jacob Abrams answered ·

Everything you are doing seems correct. The JSON you are posting looks fine. Some things to try are:

  1. Double check the customer id you are using exists by doing a GET on the customer endpoint /v3/merchants/{mId}/customers/{customerId}
  2. Try updating something else in the order like the total to see if that is working for you.
  3. You are doing a POST to /v3/merchants/{mId}/orders/{orderId}, right?
1 comment Share
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ah, it was #3 and I didn't realize I was posting to the wrong URL. Thanks.

0 Likes 0 · ·
michael avatar image
michael answered ·

Hi I just tried this and it worked fine for me. Here are the exact calls I made:

Request

POST https://api.clover.com/v3/merchants/current/orders?expand=customers&access_token=
{
    "state":"open"
}

Response

    {
      "href": "https://www.clover.com/v3/merchants/HBK58EWYDM6FP/orders/S1R1BASS2RD1T",
      "id": "S1R1BASS2RD1T",
      "currency": "USD",
      "taxRemoved": false,
      "isVat": false,
      "state": "open",
      "manualTransaction": false,
      "groupLineItems": true,
      "testMode": false,
      "createdTime": 1447274614000,
      "clientCreatedTime": 1447274614000,
      "modifiedTime": 1447274614000
    }

Request

    POST https://api.clover.com/v3/merchants/current/orders/S1R1BASS2RD1T?expand=customers&access_token=
    {
        "customers" : [{"id":"MDGRBQZN6C9V0"}]
    }

Response

{
  "href": "https://www.clover.com/v3/merchants/HBK58EWYDM6FP/orders/S1R1BASS2RD1T",
  "id": "S1R1BASS2RD1T",
  "currency": "USD",
  "customers": {
    "elements": [
      {
        "href": "https://www.clover.com/v3/merchants/HBK58EWYDM6FP/customers/MDGRBQZN6C9V0",
        "id": "MDGRBQZN6C9V0",
        "orderRef": {
          "id": "S1R1BASS2RD1T"
        },
        "firstName": "Michael",
        "lastName": "Quinlan",
        "marketingAllowed": false,
        "customerSince": 1352416865000
      }
    ]
  },
  "taxRemoved": false,
  "isVat": false,
  "state": "open",
  "manualTransaction": false,
  "groupLineItems": true,
  "testMode": false,
  "createdTime": 1447274614000,
  "clientCreatedTime": 1447274614000,
  "modifiedTime": 1447274636000
}
Share
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community