What is the proper ionic POST request to Shopify server

#1

hello @everyone
I’m sending a post request to store order in Shopify server it works perfectly from ``postman`

post body

{
  "order": 
        {
	      "currency": "AFN",
	      "customer":
	       {
	      	 "email": "foox@example.com",
	      	 "name": "Zia",
	      	 "phone": null
	       },
	      "financial_status": "pending",
	      "line_items": [
	        {
	          "price": 6000,
	          "quantity": 2,
	          "title": "Yellow Glass",
	          "variant_title": "Yellow Glass"
	        }
	      ],
	      "name": "Glass"
        }
}

but if I send this from ionic i get the following error in my console

this is the request in provider which HttpClient is injected into it.

  postOrder(order) {
    const headers: HttpHeaders = new HttpHeaders({
      Authorization: `Basic ${this.encoded}`,
    });
    return this.http.post("/api/admin/orders.json", order, { headers });
  }

and this is my .ts file which the provider injected into it

saveOrder() {
    let order = {
      "currency": "AFN",
      "customer":
      {
        "email": "fooxy@example.com",
        "name": "Zia",
        "phone": null
      },
      "financial_status": "pending",
      "line_items": [
        {
          "price": 6000,
          "quantity": 2,
          "title": "Yellow Glass",
          "variant_title": "Yellow Glass"
        }
      ],
      "name": "Glass"
    }

    console.log('Before sending ', order)

    this.provider.postOrder(order).subscribe(res => {
      console.log('Order sent > ', res)
    });
  }

but get request is working fine I can receive all the orders which are created in shopify

#2

What is different about the request sent by Ionic that returns the error? You can see all the details in the network panel of the dev tools.

1 Like
#3

dear @Sujan12 thank you for replying
yes I got the solution,
the body format was different from postman to ionic

1 Like