I have a problem with woocommerce rest api. I want to create a product with photos via rest api, but it works only without photos.
This snippet of code work:
{
"regular_price": "21.99",
"name": "Premium Quality",
"description": "Pellentesque habitant morbi tristique senectus et netus",
"type": "simple"
}
but this doesn't work:
{
"regular_price": "21.99",
"images": "[{\"src\":\"https://static01.nyt.com/images/2017/03/17/world/europe/oakImage-1489777706390/oakImage-1489777706390-largeHorizontal375.jpg\",\"position\":0,\"id\":0}]",
"name": "Premium Quality",
"description": "Pellentesque habitant morbi tristique senectus et netus",
"type": "simple"
}
The JSON is validate. The response from the server is:
{
"code": "woocommerce_product_invalid_image_id",
"message": "#0 is an invalid image ID.",
"data": {
"status": 400
}
}
The documentation claims:
Image ID (attachment ID). In write-mode used to attach pre-existing images.
According to that, you should send this request without the id parameter in your image object. This is because there is no pre-existing image with the id=0, I guess.
Example code taken from the docs:
{
name: 'Premium Quality',
type: 'simple',
regular_price: '21.99',
description: 'Pellentesque habitant morbi...',
short_descriptienter code hereon: 'Pellentesque ...',
categories: [
{
id: 9
},
{
id: 14
}
],
images: [
{
src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
position: 0
},
{
src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
position: 1
}
]
};
Related
I try to preprocess a JSON file and want to remove all subobjects in it.
Note that my JSON string is inline (not have \r).
In input I have:
{
"total": 2,
"result": [
{
"id":1,
"createdOn" : 123456,
"obj1": {
...:...,
...:...
},
"obj2": {
...:...,
...:...
},
"otherattribute": "..."
},
{
"id":2,
"createdOn" : 123456,
"obj1": {
...:...,
...:...
},
"obj2": {
...:...,
...:...
},
"otherattribute": "..."
}
]
}
And want to have:
{
"total": 2,
"result": [
{
"id":1,
"createdOn" : 123456,
"otherattribute": "..."
},
{
"id":2,
"createdOn" : 123456,
"otherattribute": "..."
}
]
}
I've tried to use sed command with :
sed 's/"obj1":{[^}]*//g'
It will remove the "ojb1" subobject, but let remain the endind "}," of this subobject.
I didn't find the way to also remove "},".
How?
Second question: I know the list of suboject; but is there a way to remove all theses subjects directly without knowing there name? Something like:
sed 's/".*":{[^}]*//g'
So that I will have only one sed command and not having to chain commands like :
sed 's/obj1//g' | sed 's/obj2//g' | sed 's/obj3//g' ...
I'm giving a first answer:
sed 's/"obj1":{[^}},]*//g'
It will match "obj1": until character } and then match again },, so that these last 2 chars will be also deleted (replaced with nothing).
Now I try to do something more generic to match any object name, with something like this:
sed 's/"[[:alnum:]]":{[^}},]*//g'
But it's not working...
I've already tried to escape or escape escape or escape escape escape double quote without success...
According to Forge API Reference, there is a workflowAttribute available to 'set some custom workflow information'. Its part of the misc object in the Body Structure of the POST request used to submit a job.
I am using the following request:
convertResponse = await axios({
method: "post",
url:
"https://developer.api.autodesk.com/modelderivative/v2/designdata/job",
headers: {
"Content-Type": "application/json",
Authorization: access_token
},
data: JSON.stringify({
input: { urn: url_safe_encoded_urn },
output: {
destination: { region: "us" },
formats: [
{
type: "svf",
views: ["2d", "3d"],
advanced: { generateMasterViews: true }
}
]
},
misc: {
workflow: "designgen-forge",
workflowAttribute: { projectId }
}
})
});
But when the webHook calls my callback function, I see nothing like hookAttribute available in the data:
{
"version": "1.0",
"resourceUrn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6c3VmZm9say1nZW5kZXNpZ25sb3ZlLWRldi10ZW1wLzkxZjhhNGZmLTM5NTYtNGM5Yi05NzkyLThiMWMxNDQyZGJkNyUyRnJldml0LTkxZjhhNGZmLTM5NTYtNGM5Yi05NzkyLThiMWMxNDQyZGJkNy5ydnQ",
"hook": {
"hookId": "6d770063-d5dc-4c66-8ed8-e84207ade07d",
"tenant": "designgen-forge",
"callbackUrl": "https://bigchief.ngrok.io/dev/workitemcomplete",
"createdBy": "9DqOEPqAd4ZZYQ2MAxuT2VQwMfAJrBGp",
"event": "extraction.updated",
"createdDate": "2020-10-20T20:14:31.874+0000",
"system": "derivative",
"creatorType": "Application",
"status": "active",
"scope": {
"workflow": "designgen-forge"
},
"urn": "urn:adsk.webhooks:events.hook:6d770063-d5dc-4c66-8ed8-e84207ade07d",
"__self__": "/systems/derivative/events/extraction.updated/hooks/6d770063-d5dc-4c66-8ed8-e84207ade07d"
},
"payload": {
"TimeStamp": 1603289180515,
"Env": "production",
"URN": "<my urn>",
"EventType": "UPDATED",
"Payload": {
"status": "inprogress",
"bubble": {
"guid": "<my guid>",
"owner": "<my guid>",
"hasThumbnail": "true",
"startedAt": "Wed Oct 21 14:05:39 UTC 2020",
"type": "design",
"urn": "<my urn>",
"success": "75%",
"progress": "50% complete",
"region": "US",
"status": "inprogress",
"children": []
},
"scope": "fd2d74bb-1d5a-407c-a344-20dffa327504",
"registerKey": []
}
}
}
I would imagine that is the intent of the workflowAttribute object to populate something in the callback data, otherwise, whats the point. Am I not specifying it correctly? Or is this not implemented? If not, webhooks become nearly unusable, I suppose the alternative is to make and destroy a webhook for each request, which is so ugly its not really a solution.
Thank you for bringing this to our attention. We could reproduce the issue as well - i.e. that the content of the workflowAttribute provided in the body of POST job request will not show up in the webhook callback.
It's being looked into, and I hope it will work soon, but I cannot yet provide a deadline for that.
In the meantime, the workaround could be either:
a) keep track of the extra data (in your case projectId) associated with the urn of the given file on the server or in a database (you might already be using one)
b) create separate webhooks, as you suggested, with different id for the "scope" -> "workflow" parameter and provide the data as the "hookAttribute" - that will show up in the callback
Update on 2020-12-14: it's working now - see https://forge.autodesk.com/blog/custom-data-translation-webhook
I'm new on chatfuel bot platform.
I'm using json api plugin (As by documentation https://docs.chatfuel.com/api/json-api/json-api)
In my backend, I produce below json response for the plugin , this is my backend URL: http://185.206.145.26:12223/latestnews?locale=en_US&first%20name=John
{
"messages": [
{
"text": "Hi Fety! There are the latest news"
},
{
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"image_url": "http://scd.rfi.fr/sites/filesrfi/imagecache/rfi_43_medium/sites/images.rfi.fr/files/aef_image/2019-01-11t145823z_1912744290_rc1428cade00_rtrmadp_3_sudan-protests_0.jpg",
"title": "Soudan: les manifestations se poursuivent, la répression aussi",
"subtitle": "www.rfi.fr, 2019-01-12 04:03",
"buttons": [
{
"type": "web_url",
"url": "http://www.rfi.fr/afrique/20190112-soudan-manifestations-poursuivent-repression",
"title": "VOIR L'ARTICLE"
}
]
},
{
"image_url": "http://scd.rfi.fr/sites/filesrfi/imagecache/rfi_43_medium/sites/images.rfi.fr/files/aef_image/2019-01-11t182406z_855534608_rc1a370ea010_rtrmadp_3_usa-shutdown-lawsuit_0.jpg",
"title": "[Reportage] «Shutdown»: un quotidien compliqué pour des milliers d'employés",
"subtitle": "www.rfi.fr, 2019-01-12 04:01",
"buttons": [
{
"type": "web_url",
"url": "http://www.rfi.fr/ameriques/20190112-reportage-shutdown-quotidien-complique-800000-employes",
"title": "VOIR L'ARTICLE"
}
]
}
]
}
}
}
]
}
The problem is when I call this api from blocks, Only, the text object sent and not the case for attachment.I am sure that my json structure is ok but I have to missed some tricks on chatfuel.
Thank you!
I’m sitting on the couch right now but I’m pretty sure “attachments” is a component of a message, not a message. You’ve got it as a message object itself under the messages array.
Solution is to move it into the message object above, after “text”.
During my searching, I would like advice about how to insert a comment in Jira issue via Talend Open Studio.
Here is my job :
So, I am trying to insert comment via Talend.
I use a tHttpRequest set like that :
uri is my string connection to get Jira account.
As it's a POST method, my header is Content-Type | application/json.
My post parameters are in a JSON file :
{
"fields": {
"project": {
"key": "TRL"
},
"summary": "A",
"description": "B",
"issuetype": {
"name": "Task"
},
"labels": ["Webapp"],
"reporter": {
"name": "x.x"
},
"assignee": {
"name": "x.x"
}
},
"body": "TEST1",
"visibility": {
"type": "role",
"value": "Administrators"
}}
When I launch this job, the following error appears :
As if the file of the response body was NULL, or maybe It's not the good manner to do the insert of the comment.
I clarify that with Insomnia(insomnia), the insertion of the comment works.
I try also the componant tRest but I don't succeed to link this one with tFileInputDelimited or tJIRAOutput.
Before to continue my work, I want to know if I am in the good direction ? Any clues ?
Thanks by advance,
Ale
I'd recommend using the tRest or tRestClient components. You can just send your JSON as "HTTP body" with these components.
On the JIRA side, you can get the necessary information here: https://developer.atlassian.com/jiradev/jira-apis
Assuming you're working with the on-premise JIRA, you'd use something like this:
URL: hostname + /rest/api/2/issue/{issueIdOrKey}/comment
HTTP Body:
{
"body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
"visibility": {
"type": "role",
"value": "Administrators"
}
}
Don't forget about the Authentication
I am trying to generate an access code using the script
https://raw.githubusercontent.com/fgalan/oauth2-example-orion-client/master/token_script.sh
I believe the response json has changed and the sed pattern is not working anymore.
How can I generate a valid access token?
Json response:
{
"access": {
"token": {
"issued_at": "2015-05-12T14:29:03.523315",
"expires": "2015-05-12T15:29:03Z",
"id": "?????",
"audit_ids": [
"????"
]
},
"serviceCatalog": [],
"user": {
"username": "pedro#viur.pt",
"roles_links": [],
"id": "pedro-almeida",
"roles": [],
"name": "pedro#viur.pt"
},
"metadata": {
"is_admin": 0,
"roles": []
}
}
}
line that generates the token
TOKEN=`echo $RESP | sed "s/{\"access\":{\"token\":{.*\"id\":\"\(.*\)\"},\"user.*$/\1/g"`
I have tried to use the access:token:id returned but it does not work.
The new id is also shorter then the old ones
Thanks
This problem was caused by the IdM migration at FIWARE Lab in early May 2015. After be aware of it, the PEP at orion.lag.fiware.org and token generation script have been fixed.
Please, donwload again the token_script.sh file and try again. It should work.