11# WordPress and WooCommerce JSON API Dart package for Flutter
22
3- [ Official WooSignal WooCommerce package] ( https://woosignal.com )
3+ [ Official WooSignal WordPress/ WooCommerce package] ( https://woosignal.com )
44
55API features:
66
@@ -15,27 +15,170 @@ API features:
1515 - Get Customers Info (Billing and Shipping)
1616 - Update Customers details
1717
18- To use this API you must have the [ WP Json API Plugin] ( https://woosignal.com/plugins/wp -json-api ) installed first on your WordPress site, you can download it via the WooSignal website.
18+ To use this API you must have the [ WP Json API Plugin] ( https://woosignal.com/plugins/wordpress/wpapp -json-api ) installed first on your WordPress site, you can download it via the WooSignal website.
1919
2020### Examples using Wp JSON API
2121
2222``` dart
2323import 'package:woosignal/wp_json_api.dart';
24+ ...
25+
26+ void main() {
27+
28+ WPJsonAPI.instance.initWith(baseUrl: "https://mysite.com");
2429
2530...
2631
27- #1 - Set the base url (e.g. https://mysite.com)
32+
33+ ##2 - Call a method from the request callback
2834``` dart
29- String base_url = "https://mywordpress-site.com";
30- WPJsonAPI.instance.initWith(baseUrl: base_url);
35+ WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
36+ .api((request) => request.wpLogin(
37+ email: email,
38+ password: password
39+ ));
3140```
3241
33- #2 - Call a method from the request api
42+ ### Available API Requests
43+
44+ ###WordPress - Get Nonce
45+ - Used for returning a valid nonce
3446``` dart
35- WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance.api((request) {
36- return request.wpLogin(email: email, password: password);
37- });
47+ WPNonceResponse wpNonceResponse = await WPJsonAPI.instance
48+ .api((request) => request.wpNonce());
3849```
50+
51+ ###WordPress - Verify Nonce
52+ - Used for verifying register and login request
53+ ``` dart
54+ WPNonceVerifiedResponse wpNonceVerifiedResponse = await WPJsonAPI.instance
55+ .api((request) => request.wpNonceVerify(
56+ nonce: nonce
57+ ));
58+ ```
59+
60+ ###WordPress - Login with email
61+ - Used to login a user
62+
63+ ``` dart
64+ WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
65+ .api((request) => request.wpLogin(
66+ email: email,
67+ password: password,
68+ authType: WPAuthType.WpEmail
69+ ));
70+ ```
71+
72+ ###WordPress - Login with username
73+ - Used to login a user
74+
75+ ``` dart
76+ WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
77+ .api((request) => request.wpLogin(
78+ email: email,
79+ password: password,
80+ authType: WPAuthType.WpUsername
81+ ));
82+ ```
83+
84+ ###WordPress - Register
85+ - Used to register a user
86+ - The username parameter is required, ensure that this is unquie
87+
88+ ``` dart
89+ WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
90+ .api((request) => request.wpRegister(
91+ email: email,
92+ password: password,
93+ username: username
94+ ));
95+ ```
96+
97+ ###WordPress - Get Users Info
98+ - Used to get a WordPress users info
99+ - The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
100+
101+ ``` dart
102+ WPUserInfoResponse wpUserInfoResponse = await WPJsonAPI.instance
103+ .api((request) => request.wpGetUserInfo(
104+ userToken
105+ ));
106+ ```
107+
108+ ###WordPress - Update Users Info
109+ - Used to update a WordPress users info
110+ - The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
111+
112+ ``` dart
113+ WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance
114+ .api((request) => request.wpUpdateUserInfo(
115+ userToken,
116+ firstName: firstName,
117+ lastName: lastName,
118+ displayName: displayName
119+ ));
120+ ```
121+
122+ ###WordPress - Update users password
123+ - Used to update a users password
124+ - The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
125+
126+ ``` dart
127+ WPUserResetPasswordResponse wpUserResetPasswordResponse = await WPJsonAPI.instance
128+ .api((request) => request.wpResetPassword(
129+ userToken,
130+ password: password
131+ ));
132+ ```
133+
134+ ###WooCommerce - Get users info in WooCommerce
135+ - Used to get WooCommerce info for a given user, pass in the userToken which you should have stored somewhere safe in shared_pref or other
136+ - The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
137+
138+ ``` dart
139+ WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
140+ .api((request) => request.wcCustomerInfo(
141+ userToken
142+ ));
143+ ```
144+
145+ ###WooCommerce - Update users info in WooCommerce
146+ - Used to update a users WooCommerce details
147+ - All the parameter are optional so if you wanted to just update the name, you could just add first_name and last_name
148+ - The first parameter is the userToken which is returned from the login/register response. You should have this saved somewhere e.g. shared_pref
149+
150+ ``` dart
151+ WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
152+ .api((request) => request.wcUpdateCustomerInfo(
153+ userToken,
154+ firstName: firstName,
155+ lastName: lastName,
156+ displayName: displayName,
157+ billingFirstName: billingFirstName,
158+ billingLastName: billingLastName,
159+ billingCompany: billingCompany,
160+ billingAddress1: billingAddress1,
161+ billingAddress2: billingAddress2,
162+ billingCity: billingCity,
163+ billingState: billingState,
164+ billingPostcode: billingPostcode,
165+ billingCountry: billingCountry,
166+ billingEmail: billingEmail,
167+ billingPhone: billingPhone,
168+ shippingFirstName: shippingFirstName,
169+ shippingLastName: shippingLastName,
170+ shippingCompany: shippingCompany,
171+ shippingAddress1: shippingAddress1,
172+ shippingAddress2: shippingAddress2,
173+ shippingCity: shippingCity,
174+ shippingState: shippingState,
175+ shippingPostcode: shippingPostcode,
176+ shippingCountry: shippingCountry,
177+ shippingEmail: shippingEmail,
178+ shippingPhone: shippingPhone
179+ ));
180+ ```
181+
39182For help getting started with WooSignal, view our
40183[ online documentation] ( https://woosignal.com/docs/wordpress-json-api-flutter/1.0/overview ) , which offers a more detailed guide.
41184
0 commit comments