iPhone Developer iPhone Developer - 4 days ago 6
Objective-C Question

Woo-Commerce REST API response correct on Postman not in Xcode

I am implementing a "POST" api for creating an order through woo-commerce:

POST http://www.url.in/wp-json/wc/v1/orders


I am also using external library Oauth1 for it which uses one-legged authentication for it. Now when I run the API on Postman, it gives me correct response, but in the code it gives me error:

{
"code":"woocommerce_rest_cannot_create",
"message":"Sorry, you are not allowed to create resources.",
"data":{"status":401}
}


In my code I am creating a NSDictionary , I change it to NSData through NSJSONSerialization and sending it as HTTPBody along with the request.

Check the attached screen shot of Postman and Xcode.
[Postman[1]

Xcode

Answer

The problem lied in the JSON data I was posting. Instead of posting NSDictionary , I had to post it as NSString. It worked like a charm after that.

Comments