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.

1 Answer

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!

10 |2000

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