Updating image using Put Request Cakephp Rest API - api

I am following Cakephp's Rest API docs to implement apis.Cakephp Rest Api Docs
Please note I am using Postman Rest Client to test the apis.
As a requirement I need to provide the users to update a certain product image.
When I use POST Request to add images for the first time, I get the Image information in $this->request->params['form'] array, which also has parameters like name, type, tmp_name, error and size.
[form] => Array
(
[barcode_image] => Array
(
[name] => sitewide%20sales.png
[type] => image/png
[tmp_name] => C:\xampp\tmp\phpFCE8.tmp
[error] => 0
[size] => 136596
)
[image] => Array
(
[name] => phone%20number.png
[type] => image/png
[tmp_name] => C:\xampp\tmp\phpFCE9.tmp
[error] => 0
[size] => 89166
)
)
This can be easily tested in Postman by setting the field type to 'File'(which then lets you upload an image).
Now, I want to let users to Update the image which they had uploaded. For Updating i am using PUT request for which the required MIME type is x-www-form-urlencoded, this then prevents from updating a file.
How can I test updating of image in this scenario.
Will I have to re-write the way i have implemented the API, so that Editing of the image(re-upload a new image) to be done using POST request?
Any help will be greatly appreciated. If I am missing out any specifics, code please ask. I'll update the question accordingly.

I googling for few minutes as per as of your problem. according to my point of you need to understand what is the purpose of PUT & POST.
Just Look at request->is('post') Vs request->is('put')

Related

Netsuite API post salesorder

I'm trying to post a salesorder to Netsuite REST API, and following what appears to be the correct format according to documentation.
I'm posting to /services/rest/record/v1/salesOrder
My payload looks like this
{"recordtype":"salesorder","entity":{"id":"20716"},"total":119.21,"createdDate":"2023-01-25T16:04:59+00:00","item":{"items":[{"item":{"id":"959"},"quantity":1,"amount":111.41}]}}
I'm having no issues connecting and authenticating and am performing other (GET) operations without any issues.
The response to the above request is
stdClass Object
(
[type] => https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1
[title] => Bad Request
[status] => 400
[o:errorDetails] => Array
(
[0] => stdClass Object
(
[detail] => Please enter a value for [entity]
[o:errorPath] => entity
[o:errorCode] => FIELD_PARAM_REQD
)
)
)
The value I have in the 'entity' node is a valid netsuite customer record ID.
For reference, the salesOrder object schema is here - https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2022.2/index.html#/definitions/salesOrder
Any idea why Netsuite is complaining about the entity?
It turns out the format I was posting is correct, but I was posting it in the 'form_data' node rather than the 'body' node.
So for anyone else with similar issue, the payload is correct.

Podio App Create not respecting Field external_id

I'm running into an issue with the Podio App Create API call:
https://developers.podio.com/doc/applications/add-new-app-22351
It does not appear to respect external_id for fields.
For example, given:
...
[fields] => Array
(
[0] => Array
(
[type] => text
[external_id] => title
[config] => Array
(
[label] => Name
...
The resulting field will have an external id of "name" and not "title".
This is a rather big issue as when trying to make exact copies of apps (into places that clone won't go), the change in field ids causes GF flows to break.
Any way around this?
Per the API documentation there is no "external_id" input in this call. The external IDs are always a standardized version of the field label though. (e.g. if you have 2 Name fields the first will be "name" and the second will be "name-2").
Alternatively, you could just run "get app" https://developers.podio.com/doc/applications/get-app-22349 to see what the external IDs ended up being.

Structure of a RESTful API

I want to build a RESTful API for my small project. There are three simple resources that I have:
- Categories (id, title)
- Posts (id, text, category_id)
- Comments (id, text, post_id)
These are the end points that I need:
GET /categories/ => list of all categories
GET /categories/:id/posts => list of riddles in specified category
GET /posts/:id => get single post
GET /posts/:id/comments => list of comments for specified post
GET /comments/:id => get single comment
POST /posts/:id/comments => create a comment (text comes from POST params)
Is this a good structure for API in this case?
Is this consider to be a RESTful API?
REST doesn't have anything to say about URI structure, so it's not really meaningful to ask if your endpoints are RESTful.
As far as the design, I would consider this instead:
GET /categories
GET /posts?categoryId=<categoryId> -- or you could use category name, if the name is not the same as the id
GET /posts/<postId>
GET /comments?postId=<postId>
GET /comments/<commentId>
POST /comments
{ "postId" : 123, ... }
According to REST, url should uniquely identify the resource which is happening in your case. As long as your url is Cacheable and you are using correct verbs and correct status codes, do not indulge in too much quabble about url structure. Additionally, you might want to look into 'Hypermedia', if you want your apis to be truly restful

How to get active listing IDs? GetMyeBaySelling returns no more than 25,000 items

So I want to get all listed items ID's for authenticated user.
To do this I use Trading API GetMyeBaySelling method
Example request:
[ActiveList] => Array
(
[Include] => true
[Pagination] => Array
(
[EntriesPerPage] => 200
[PageNumber] => 89
)
[Sort] => StartTime
)
It works well until I hit magic page 125. Every page after 126, 127, 128, ... returns me 125th page.
So I can get only 25,000 listings. I don't see it mentioned anywhere in documentation.
I also found other people have same/similar issue
Is there any other option to get selelr listing IDs?
Edit: I also asked a question on ebaydev forums
I tried to load 125 pages sorted by time ASC, then load another 125 sorted by time DESC but it doesnt work. Also I am getting this error
[Errors] => stdClass Object
(
[ShortMessage] => Data is truncated.
[LongMessage] => Partial data or invalid summary data is returned due to system limit. Please narrow your requested data and try again.
[ErrorCode] => 21366
[SeverityCode] => Warning
[ErrorClassification] => RequestError
)
I found answer already.
ActiveInventoryReport call from Large Merchant Services is perfect for my needs

Is it possible to set certain product attributes for a different store view using the Magento API?

We are currently using the Magento API for importing a bunch of products into the store.
But we now run into a problem where some product attributes should be translated into a different language.
And I was wondering if it is possible to do this using the Magento API, because I can't seem to find anything related to that problem.
We currently have 2 store views, 1 for the Dutch version of the site and one for the French version of the site.
Our current import code looks something like this:
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('nl'));
echo("store_id: $store_id");
$new_product_data = array(
'name' => 'NameInDutch',
'short_description' => 'DescriptionInDutch',
'price' => $price,
'weight' => $weight,
'websites' => array('base'),
'status' => '1'
);
$new_product_id = $soapClient->call($soapSession, 'catalog_product.create', array('simple', 4, $sku, $new_product_data)); // 4 => 'Default' attribute set
$localized_product_data = array(
'name' => 'NameInFrench',
'short_description' => 'DescriptionInFrench'
);
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('fr'));
echo("store_id: $store_id");
$soapClient->call($soapSession, 'catalog_product.update', array($sku, $localized_product_data ));
Now, the output of the echo statements differs, the first time it's 1 and the second time it's 2, so that doesn't seem to be problem. But apparently it doesn't matter for the API if we set that value.
The result is that on the 'catalog_product.update' call, the name 'NameInFrench' overwrites the default name 'NameInDutch'.
So my question is if something like this is possible using the Magento API, and how one would accomplish this?
Ok, I found the answer, apparently I overlooked a certain line in the Magento API docs, because the solution was right there.
So: you don't need to set the currentStore each time, you just need to append the store id or code to the update array:
$soapClient->call(
$soapSession,
'catalog_product.update',
array($sku, $localized_product_data, 'fr')
);
This works perfectly.