question

maxusachev avatar image
maxusachev asked maxusachev action

Customer is not assigned on order create using REST API

Hi, team!


I'm trying to create new order and link existing customer to it.

Expected result: customer is linked to new order.

Actual result: customer is not linked to new order.


This is a Python script to test:

import click
import requests


@click.command(help='Create an order.')
@click.option('--access-token', required=True)
@click.option('--merchant-id', required=True)
@click.option('--order-type-id', required=True)
@click.option('--order-number', required=True)
@click.option('--order-notes', required=False)
@click.option('--order-title', required=True)
@click.option('--customer-id', required=True)
@click.option('--charges-total', required=True)
def create_order(
    access_token, merchant_id, order_type_id, order_number, order_notes,
    order_title, customer_id, charges_total,
):
    data = {
        'orderType': {
            'id': order_type_id,
        },
        'currency': 'USD',
        'title': order_title,
        'total': int(charges_total),
        'externalReferenceId': order_number,
        'state': 'open',
        'customers': [{
            'id': customer_id,
        }]
    }

    if order_notes:
        data['note'] = order_notes

    response = requests.post(
        'https://sandbox.dev.clover.com/v3/merchants/%s/orders' % merchant_id,
        headers={
            'authorization': 'Bearer %s' % access_token,
        },
        json=data,
    )

    click.echo('response status: %s' % response.status_code)
    click.echo('response data: %s' % response.content)


if __name__ == '__main__':
    create_order()
OrdersREST APICustomers
10 |2000

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

David Marginian avatar image
David Marginian Deactivated answered maxusachev commented

Only a few fields are recognized when creating an order:

https://docs.clover.com/reference#ordercreateorder-2

Only supports basic order creation. Valid fields are limited to taxRemoved, note, title, state, testMode, manualTransaction, groupLineItems and orderType. Adding line items must be done in separate calls

You need to update the order to set a customer. See more information on working with orders here - https://docs.clover.com/docs/working-with-orders.


10 |2000

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

maxusachev avatar image
maxusachev answered Naeem Hassan commented

Thank you for reply. Yes, I can add customer by updating an order. I think the documentation should be updated and exclude customer id.

But the same issue with modifiers for line items. I can't call bulk items create with modifiers assigned - they just skipped. And yes, I can add it by updating each line item. But this approach will cause too many requests to API. Can you suggest another way?


Thank you!

2 comments
10 |2000

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

David Marginian avatar image David Marginian ♦♦ commented ·

Agree, and this has been brought up before and we have an open issue on it. Unfortunately, the documentation is auto generated and because the endpoint accepts an Order all the fields get listed.

Per https://docs.clover.com/docs/working-with-orders that is currently the only way to add modifiers (one at a time). We have a newer order API that will released in the coming months that will allow you to create an entire order with one request.

1 Like 1 ·
maxusachev avatar image maxusachev David Marginian ♦♦ commented ·

Sounds good! Thank you!

0 Likes 0 ·

Welcome to the
Clover Developer Community