Showing results for 
Search instead for 
Did you mean: 

REST API Cart-Checkout Process flow


REST API Cart-Checkout Process flow

I'm trying to do the full workflow of adding objects to a cart, then going through the checkout and order phases.

I can manipulate the carts perfectly fine, but I'm running into issues of how to (via REST) add billing and shipping addresses, then order.  This example will all be using the logged-in stuff but I've also got a parallel guest version - they're nearly identical so I'm not worried about that part. 


Right now I'm setting the billing address by POSTing to  "/V1/carts/mine/billing-address."  That returns a successful status code and a message body of 1.


When I try to POST to  "/V1/carts/mine/shipping-information" and it returns the error of "Shipping address is not set"


Now, I've doublechecked the payload (several times in fact) and it seems to be correct, and it doesn't throw an error on the server end for a malformed payload.  Either it's malformed in some way that the server doesn't mind and it's erroring somewhere else along the line, or I have to set the shipping address some other way - but I can't determine what other way you can do it in the REST API.  I should note that the test customer does have a default shipping and billing address.


Now after that, it looks like a POST "/V1/carts/mine/order" will work to order what's currently in the cart. I would assume you need the shipping and billing address for it to work, but I'm getting "The requested Payment Method is not available."  The POST I'm using is just a test one with "free" as the method (which I have verified by GETing the payment methods from "/V1/carts/mine/payment-information")


So my questions are 

1) What am I missing in my workflow that needs to be done in order to get the billing and shipping set for ordering

2) Are there any peculiarities on payloads that might be causing this or that I need to look out for when adding things missing from (1) above.


Now I don't administer the server directly so if there's some server tweak that has to be done for something I'll pass it on, but I think it's just the default test install package so it should all be okay.  We're running 2.0.4.

Tags (1)

Re: REST API Cart-Checkout Process flow

Mostly solved - it was actually a payload error rather than a workflow error.  

Re: REST API Cart-Checkout Process flow

Can you share how you did solve it ? I'm having same problem in my production server.

Re: REST API Cart-Checkout Process flow

It turns out that the error message "Shipping address is not set" is actually a failure reply saying that the POST to set the shipping address did not do so.  I figured out (eventually) that the address information I was sending the server failed some sort of validation check.  In the swagger docs if you switch to "model" under "CheckoutShippingInformationManagementV1" you can see what's required to POST and the format you need to send it, but it doesn't tell you what the proper ranges, etc, are.  The way I solved it was to set the address via the web interface and then request it via /customer/me ("addresses" gives you an array of default address info) and cross reference it.  That let me figure out what each thing actually referred to.


The two things I specifically had wrong was the CountryId, which is a letter abbreviation, not a numeric code ("US" in this case), and regionId, which for US states (In this case Virginia) is a postal code number (in this case 51), while the regionCode is "VA".