WooCommerce fulfillment api - woocommerce-rest-api

I am making the order management system and try to integrate woocommerce api.
I read the document, found it quite different with the other ecommerce api.
When we need to pull order from the Woocommerce, use the /wp-json/wc/v3/orders api.
But when I done the order fulfillment and try to imform the shipment(advanced shipping notice), like send the tracking number correspones the order, which api should I use?
Thank you very much.

To update an existing order in WooCommerce you add the order id to the url like this /wp-json/wc/v3/orders/<id> and the request needs to be an PUT.
To store tracking url I would suggest you save it as a meta_field on the order. You can then easily access it in WooCommerce and display it where you want. Request can look like this:
{
"meta_data": [
{
"key": "_tracking_number",
"value": "XXXXXXXXXXXXX"
}
]
}
You can read more about it here https://woocommerce.github.io/woocommerce-rest-api-docs/#update-an-order

Related

Getting Error while creating audience of CUSTOM type through Marketing API - Facebook

I am using Facebook PHP SDK, and trying to create Audience of Custom TYPE from Marketing API, and I am getting following Error:
You'll need to agree to the Custom Audience terms before you can
create or edit an audience of CUSTOM type. To accept, go to
https://business.facebook.com/ads/manage/customaudiences/tos/?act=129260934125705.
Even though I have already accepted the term, I am still getting the error for accepting the terms.
Please find attached screenshot for Terms Acceptance.. Terms & Condition Accepted Screenshot
I would recommend checking the status of tos_accepted via Graph API explorer. You can also use it to debug your Audience Creation calls.
You can check if a Business has signed their Custom Audience terms of service, by making a GET call to an ad account owned by that Business. The ad account can’t be acting on behalf of another business, or be shared. The GET call is:
GET act_<AD_ACCOUNT_ID>?fields=tos_accepted
A sample response looks like this:
{
"tos_accepted": {
"custom_audience_tos": 1 // this means the terms were signed
},
"id": "act_<AD_ACCOUNT>"
}
Check full docs about TOS here
A bit more info on Custom Audiences
Thanks Artyom Kovalyov.. I have checked the graph API explorer, and this is what I get.
{
"tos_accepted": {
"web_custom_audience_tos": 1,
"custom_audience_tos": 1,
"value_based_custom_audience_tos": 1
},
"id": "act_129260934125705"
}
Please check and let me know if I can do something else to fix the error that I am getting..
It seems ok Vishal. Have you tried to create this same Audience via graph explorer? The ways to go from here are either filing an FB direct support case for your app, they are not usually fast to reply and not every customer is whitelisted for that.
Another assumption is if you try to do it on behalf of your customer with their account, it might be that they have to accept TOS, not you.
FB has a huge amount of setting and from the info, you provide it's pretty hard to tell what exactly fails.

Google Calendar REST API does not return title and other event fields

Google calendar REST API GET method (https://developers.google.com/calendar/v3/reference/events/get) should return this structure (https://developers.google.com/calendar/v3/reference/events#resource), unless I'm missing something.
I need to get event title and description to use in my application. I 'm getting below response instead.
I've tried to change event visibility (public/private) and availability (free/busy). Actually, API does not show events with Free availability, for which I don't have solution either.
Here is event edit screen screenshot:
https://www.screencast.com/t/X8bRS8kJDT
{
"kind":"calendar#event",
"etag":"\"3145149995624000\"",
"id":"5fnlvcl2msab46p8roqbahhb6g",
"status":"confirmed",
"htmlLink":"https://www.google.com/calendar/event?eid=NWZubHZjbDJtc2FiNDZwOHJvcWJhaGhiNmcgZWQtYWRtaW4uY29tXzMwOHNycjdzdjdiM28xazRpdjZ2cm9mb3Y0QGc",
"updated":"2019-11-01T02:23:17.812Z",
"start":{
"dateTime":"2019-11-11T09:30:00+11:00"
},
"end":{
"dateTime":"2019-11-11T10:00:00+11:00"
},
"visibility":"private",
"iCalUID":"5fnlvcl2msab46p8roqbahhb6g#google.com"
}
Are there other methods to get calendar events details with REST API, including ones with free availability?
Thanks.
04/02/2020:
I actually made it work for "ordinary" Google account - add project, add API, add service account and allocate service account email to the calendar. But I still not sure how to change access level for G Suite account. It allows only to see Free/Busy status.
I've changed default access in Admin Console as this article suggests, but it does not help:
https://www.macworld.com/article/2980005/the-mystery-of-the-unsharable-google-apps-calendar.html
You could try specifying the fields you want to retrieve like the image below:
Or you could put a " * " as the image below to retrieve all values:
fields is a standard Query parameter, which specifies what values you want to include in your response. To learn more about it, you can check Here.

Can restful POST api send back two different resources in the API response based on request body parameter?

We have a website to connect buyer and seller of goods.
We are designing POST API to capture interest of buyers on any seller product. The API Uri and request body looks like:
/api/lead/
{
"name":"xyz",
"mobile": "00984343",
"stockid":4
}
The API is POST since we will save this information in database.
Currently, if "stockid" is stock belonging to our premium customer, the API sends back seller details in API response body:
{
"sellername":"abc",
"sellermobile":"75654647",
"selleraddress": "faje street, curl"
}
If "stockid" is stock belonging to our normal customer, the API sends back complete details of that product in API response body (and DO NOT send back seller details)
{
"description": "good 2nd hand mobile",
"purchasedate": "24 july,2017",
"purchaseprice": "10000"
}
The same POST API is sending back 2 different types of resources (one is seller details, other is stock details) based on the stock id.
Is it restful to design API this way i.e. POST API sending back multiple types of responses based on some request body parameter?
This practice looks questionable. Personally I would not do that.
Suggestion 1: return details of product for normal customer, and details of product plus seller details for premium one, as form of enrichment of response. With that both responses are mostly consistent and you still have functionality you want.
EDIT: added more suggestions I thought of.
Suggestion 2: since those responses are basically different, maybe they should be returned by different resources. In that case, don't return data during POST, just use id to make calls to something like api/seller/{stockid} and api/product/{stockid} which would return responses or No content if id is invalid for specific resource. Downside, you need to make many calls and it complicates architecture.
Suggestion 3: To avoid totally different response objects, which is confusing and makes harder for the client to map them, use some wrapper object that provides some "type" property and your object inside. Something like :
{
"type" : "premium",
"data" : {
"sellername":"abc",
"sellermobile":"75654647",
"selleraddress": "faje street, curl"
}
}
Not perfect, but in my opinion better than two totally different responses.

Rest convention: Should api send details api url for listings or clients hard code them?

We have listing and details page for mobile, desktop, android and ios?
We have two apis- one for listing and other for details of those listings. So one api is assosiated with other.
listing api looks like:
/api/books/?price=100-300
details api looks like:
/api/book/{bookId}
listing api in response sends back details api link for each listing:
For example:
Request:
/api/books/?price=100-300
will have Response:
{
"books":[
{
"id": 1,
"price": 120,
"pages": 400,
"detailsUrl": "/api/book/{bookId}"
}
]
}
The problem is, should I send detailsUrl with each listing or let all the clients create this? Since they have bookId, they can create it.
What is considered to be best practise considering the url params in details api url may get added in future, api may be versioned and all other possibilities for widely used apis?
I'd put my money on creating the link.
There is a perfect explanation why putting id is not enough
DO NOT include just an entity's ID (such as 12) in a response, because
that way you're forcing clients to put together resource URIs
themselves. In order to do that, they would need to have prior
knowledge of what URIs there are, and you're losing control over the
URI space on the server side.
I recommend to read the entire, linked text (approved answer), it's very detailed and got nice resources. As the author mentioned, there is a popular convention how to make connections between resources - HAL. Consider this instead of detailsUrl.
Even if a link to the resource is obvious right now and you decided to put id alone, in other resources after some time it won't be so simple and you will be forced to specify full URL. Then your API won't be consistent. Experience has taught me it's always easier and better for maintenance to send back full link.

OpenGraph: how can i specify a filter in FB.api?

I have built a Facebook app using OpenGraph that permits the users to write reviews on concerts, so that I've defined a concert_id attribute on which the user can insert a review.
Now I would like to show all the reviews inserted for a certain concert_id but cannot find a way. If I do (in JS)
FB.api('/me/MY_APP:action', { limit: 0}, function(response) {
console.log(response);
});
I get all items. This app has to be consumed by mobile, I think it is bad to get all items and, then, filtering only the concert_id i need. What do I have to do to apply a where condition in OpenGraph to a custom action?
As far as I can tell from the API and the Facebook developer pages, it's not possible to filter a call by custom action property using the public Open Graph API.
Two options I can think of:
Option 1:
Implement the category filter by creating custom category objects:
if "review" is a custom action and
GET https://graph.facebook.com/me/[name_space]:review
returns all review actions then
GET https://graph.facebook.com/me/[name_space]:review/scifi_movie
GET https://graph.facebook.com/me/[name_space]:review/action_movie
return actions specific to movie type, where scifi_movie and action_movie are custom objects. You would need to create one object type for each category.
Option 2:
Implement a custom action for each category, e.g.
review_scifi_movie
review_action_movie
These are not particularly elegant solutions but perhaps useful as a hack if nothing else works and you really don't want to do filtering on client side.
The Facebook API will not return individual published objects for a particular action, but that's not your only problem. By the look of it, you're trying to bring in ALL the reviews given for a concert, right? (Meaning those by other users too).
The "/me/" part of the Facebook API call will only return those published actions made by the user that is currently logged in. That won't work for you, as you want those of all your users
The only suggestion I can give is to create a simple web service, where you store all the reviews given for the various concerts. Use this service to pull in reviews given for a particular concert. (I use a similar methodology for reviews in an app of my own).
I dont understand javascript or opengraph..
But when I required in JAVA to fetch reviews made by any user I have used FQL for that and It retrived me all the reviews and FQL also used to fetch all the tables related to Facebook.
I don't think that you can pull that off with the JS SDK.
You can do that in your server though, and since this is a mobile app (or has a mobile version) then that's another good reason to remove this from the client responsibility.
In the server side you can ask facebook for the published actions as you posted, filter them and then return the response.
Another thing that you can do is to save each published action in your db (on each action post you should get an id back from facebook, just persist that) and then you can easily filter the published actions according to what ever criteria you want/need (since you are no longer restricted by the facebook api).
The open graph thing is still pretty new and not tat mature, for example you can't use FQL with it, something that could have been handy for your case.
Regardless though I think that a server solution is best for calculations when mobile is concerned.
i don't know exactly but try this
if (session.authResponse) {
FB.api('/me', {
fields: 'name, picture' // here mention your fields
},
function(response) {
if (!response.error) {
//here response value
});