Sending json data to WebAPI .Net Core

I’ve created a request as follows:

You can see the error:

“{”“:[“Unexpected character encountered while parsing value: {. Path ‘’, line 1, position 1.”]}”.

The API is not being called.

I can’t see where I am going wrong. I’ve tested a separate method using form data without a problem.

GET /api/paypal/getorder HTTP/1.1
Host: localhost:52519
Content-Type: application/json
cache-control: no-cache
Postman-Token: 2eaf198a-c69c-4146-92e3-98ddc94892c1
{
  "orderID" : "123456789"
}------WebKitFormBoundary7MA4YWxkTrZu0gW--

Hey @glenh,

Would you be able to explain a bit more about the implementation of the API?

It’s tricky to know what’s going on when you can only see one side of the problem :slight_smile:

It looks like you’re sending a JSON body with a GET request, is this how that endpoint accepts incoming requests?

Do you have any logging within the API code to see what’s happening when the request is made from Postman?

Your assumption that its Get then you are correct.

The request itself never gets to the method so logging is not called.

I will post the api method/code as soon as I can.

I really appreciate your reply and assistance.

1 Like
		[HttpGet]
	[Produces("application/json")]
	[ProducesResponseType(StatusCodes.Status200OK)]
	[ProducesResponseType(StatusCodes.Status400BadRequest)]
	public async Task<ActionResult<BraintreeHttp.HttpResponse>> GetOrder([FromBody] string orderId, bool debug = true)
	{
		siLogger.LogMessage("GetOrderDetails");
		siLogger.LogString("OrderID", orderId);

		if (orderId == null)
			return BadRequest();

		OrdersGetRequest request = new OrdersGetRequest(orderId);

		BraintreeHttp.HttpResponse response = null;
		//3. Call PayPal to get the transaction
		try
		{
			response = await PayPalClient.Client().Execute(request);
			//4. Save the transaction in your database. Implement logic to save transaction to your database for future reference.
			var result = response.Result<Order>();

			siLogger.LogMessage("Retrieved Order Status");
			siLogger.LogString("Status: {0}", result.Status);
			siLogger.LogString("Order Id: {0}", result.Id);
			siLogger.LogString("Intent: {0}", result.Intent);
			siLogger.LogMessage("Links:");
			foreach (LinkDescription link in result.Links)
			{
				siLogger.LogMessage("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
			}
			AmountWithBreakdown amount = result.PurchaseUnits[0].Amount;
			siLogger.LogMessage(string.Format("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value));
			siLogger.LogString("Response JSON: \n {0}", PayPalClient.ObjectToJSONString(result));
		}
		catch (Exception ex)
		{
			siLogger.LogException("BraintreeRequest", ex);
		}
		return response;
	}

The formatting of the request body was incorrect.