iPhone Developer iPhone Developer - 1 year ago 398
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:

"message":"Sorry, you are not allowed to create resources.",

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.


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download