Getting 422 Unacceptable Entity error

Highlighted
New Member
13 0 0
Getting 422 Unacceptable Entity error (mentioned in Step 3 below)

These are the steps to get the error:

1) Creating the checkout Object 
  URL     ->  POST https://harry-potter.myshopify.com/admin/checkouts.json
  HEADERS -> X-Shopify-Access-Token(xxx)
             Content-Type(application/json)
  BODY    -> {
              "checkout":{
                "email": "asdf@asdf.org",
                "line_items": [{
                  "variant_id": 31134652389,
                  "quantity": 1
                }],
              "billing_address": {
                "first_name": "Harry",
                  "last_name": "Potter",
                  "address1": "4 Privet Drive",
                  "city": "Little Whinging",
                  "province_code": "SU",
                  "country_code": "UK",
                  "phone": "8444437443",
                  "zip": "201301"
              },
              "shipping_address": {
                "first_name": "Harry",
                  "last_name": "Potter",
                  "address1": "4 Privet Drive",
                  "city": "Little Whinging",
                  "province_code": "SU",
                  "country_code": "UK",
                  "phone": "8444437443",
                  "zip": "201301"
              },
              "requires_shipping": false
              }
            }

We are getting 202 Accepted code


2) We process transactions on credit cards by relying on a separate card vaulting endpoint. Your app submits the credit card to the vault, and the vault returns a payment session_id that your app can use to create a payment for the credit card.

  URL-> POST https://elb.deposit.shopifycs.com/sessions
  HEADER->  Content-Type: application/json
            Accept: application/json
  BODY->   {
            "payment": {
              "amount": "10.0",
              "unique_token": "Harry1233",
              "credit_card": {
                "number": "4242424242424242",
                "month": "12",
                "year": "2023",
                "verification_value": "256",
                "first_name": "Harry",
                "last_name": "Potter"
              }
            }
          }

We are getting 200 Ok status code and return the session_id


3) Completing the checkout 

    URL->  POST https://harry-potter.myshopify.com/admin/checkouts/{checkout_token}/payments.json
           checkout_token-> received in first step
    HEADERS -> X-Shopify-Access-Token(xxx)
               Content-Type(application/json)
               Accept(application/json)
    BODY->
          {
            "payment": {
              "request_details": {
                "ip_address": "111.93.122.70",
                "accept_language": "en-US",
                "user_agent": "Chrome/54.0.2840.98"
              },
              "amount": "10.00",
              "session_id": {coming from 2nd step above},
              "unique_token": "Harry1233"
            },
            "requires_shipping": false
          }


We are getting following 422 Unprocessable Entity every time
    {
      "errors": {
          "session_id": [
              {
                  "code": "invalid",
                  "message": "is invalid",
                  "options": {}
              }
          ]
      }
    }


Why is this "unprocessable"?
0 Likes
Shopify Staff
Shopify Staff
141 24 28

Hi @Kevin107 ,

 

The 422 "Unacceptable/Unprocessable Entity" error could be thrown for many different reasons, such as having an incorrectly formatted input or trying to checkout products which are out of stock. In order for us to help narrow down what might be causing this, would it be possible for you to share the value of the "X-Request-ID" header from Shopify's 422 status response? With this value I can go through the Shopify platform logs and investigate why exactly this response was sent. If you can't provide this header value, providing your Shop ID and the approximate time frame when this error occurred will also help too! 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
13 0 0

@hassain please see the  X-Request-Id → 44449aa4-f846-4172-8d0e-6ce064c7aca7

0 Likes
Shopify Staff
Shopify Staff
141 24 28

Hey @Kevin107 ,

 

Thank you for providing the X-Request-ID! From looking through our platform logs, it appears to me that this 422 error is being thrown because when Shopify queries for the session_id provided from your payments.json POST request it is getting a "Resource Not Found" error.

 

One thing I have observed from our logs that may be causing this error to occur, is that I have noticed that the session_id you are passing through the POST request follows a format of "east-{hashcode}". Could you test and see what happens if you drop the "east-" component of this string and just pass along the hashcode as the session ID? This may possibly help resolve the issue.

 

Also if you could provide the value of the "X-Request-ID" header for the POST request to the https://elb.deposit.shopifycs.com/sessions endpoint, that would be helpful too. Thanks!

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
New Member
13 0 0

@hassain 
I have tried by removing "east-" from session_id still getting  422 error and below is the response and "X-Request-Id "  is  "27d70811-68fd-44ce-9998-c183fa73a7cf"

{
    "errors": {
        "session_id": [
            {
                "code": "invalid",
                "message": "is invalid",
                "options": {}
            }
        ]
    }
}


https://elb.deposit.shopifycs.com/sessions endpoint i am not getting "X-Request-ID" below are the headers we are getting

 

Server →nginx
Date →Wed, 20 Nov 2019 05:28:56 GMT
Content-Type →application/json
Transfer-Encoding →chunked
Connection →close
Vary →Accept-Encoding
Access-Control-Allow-Origin →*
Strict-Transport-Security →max-age=31536000; includeSubDomains; preload
P3P →CP="NOI DSP COR NID ADMa OPTa OUR NOR"
Content-Encoding →gzip

 

 

 

0 Likes
New Member
13 0 0
For fetching session_id I am sending card details to shopify payment end point then it will return new session_id.

Then I am sending this session_id for completing the checkout API. Everytime I am sending new session_id for checkout API still we are getting 422 error
0 Likes
New Member
13 0 0

@hassain 

 

Hi Jeff,

Today we have tried with the two options to complete the checkout flow

 
1) If we fill the shipping address and update the shipping line in the checkout api then it is working fine. If  we set "requires_shipping = false" and not fill the shipping address then it is giving 422 and if we fill the shipping address for "requires_shipping = false" then it is working fine. So in every case we have to fill the shipping address.
 
2) If I set "requires_shipping = false" in checkout then it should not ask me for the shipping address and still it is giving 422 error.

As per our requirement we don't need the shipping so we are trying with "requires_shipping = false" and according to doc we have options if we want shipping included in the checkout process or not, for it we have an extra parameter given below
 
requires_shipping
READ-ONLY
"requires_shipping": true

Whether the checkout requires shipping. If true, then shipping_line must be set before creating a payment.

can you please confirm if we set requires_shipping = false then why we need shipping line.
0 Likes
New Member
13 0 0

@hassain 

When we create order by checkout api while enabling  shopify payment then order is displaying in orders tab of store admin but if we do same thing by enabling stripe payment then the order checkout api is completed but it doesn't show in the order's tab. 

0 Likes
New Member
13 0 0

@hassain  Also when payment is completed the how we will check that payment is processed successfully 

0 Likes
Shopify Staff
Shopify Staff
141 24 28

Hi @Kevin107 ,

 

when payment is completed the how we will check that payment is processed successfully 

One possible solution is make a GET request to the Shopify Admin API endpoint of "/admin/api/2019-10/orders/#{order_id_of_completed_payment}.json", and then check the field of "fin.... If the "financial_status" is set to `authorized` or `paid`, then you would that they payment has been processed successfully. 

 

When we create order by checkout api while enabling  shopify payment then order is displaying in orders tab of store admin but if we do same thing by enabling stripe payment then the order checkout api is completed but it doesn't show in the order's tab

That is very strange behaviour - all completed orders should appear in the orders tab regardless of which payment gateway was used. Can you provide specifics which might help us investigate why this is happening? (i.e. any relevant X-Request-IDs, Order IDs, approximate timeframes, etc). Also, can you verify if those orders that do not show up in the Order's tab appear under the "Abandoned Checkouts" tab?

 

can you please confirm if we set requires_shipping = false then why we need shipping line.
This is also strange, and may possibly be a bug on our end. Once again, if you can provide any specifics which might help me investigate why this is occurring (i.e. X-Request-IDs, the JSON payload for your admin/api/checkouts POST request, approximate time frames, etc) then that would be extremely helpful. Also, can you verify if you still get a 422 error if you set requires_shipping=false and include "billing_address" information, but do not include any "shipping_address" information? 
 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes