Am trying to create a sales order in acumatica using rest API with more than one soline but am able to create only one soline, below see my code
I would like to create one sales order with all cart items as solines for that particular sales order in acumatica.
if (isset($_SESSION['cart'])) {
foreach($_SESSION['cart'] as $row) {
if ($row['qty'] != 0) {
$product = $row['product'];
echo $product.
"<br>";
curl_setopt_array($curl, array(
CURLOPT_URL => "https://xxxxxxx.com/myinstance/entity/PLUS/17.200.001/SalesOrder",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEFILE => $temp_data,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\r\n \"OrderType\" : {value : \"SO\" } ,\r\n \"CustomerID\" : {value : \"C000000002\" },\r\n \"webItems\" : {value : \"$product\" },\r\n\"webQty\" : {value : \"1\" },\r\n\"WebTaxCat\" : {value : \"TAXABLE\" },\r\n}",
CURLOPT_HTTPHEADER => array("cache-control: no-cache", "content-type: application/json", "postman-token: 5248821b-91e9-5800-bd9c-b4c9775c6c5a"),
));
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo "cURL Error #:".$err;
} else {
echo $response;
}
}
}
}
Looking at your code you seems to have created your own endpoint or extended the default endpoint.
Though looking at the structure of the body that you are passing through the detail information seems to be on the same level as the top level entity.
If you created your own endpoint from scratch, I would recommend that you take a look at the Sales Order entity from default endpoint and its Details sub entity.
As normally, you should have a details object inside of the Sales Order node that can contain an array of details information.
If I was using the default endpoint I could pass the following JSON body to the address :
localhost/191u03/entity/Default/18.200.001/SalesOrder
{
"CustomerID": {"value": "ABARTENDE"},
"Details":
[
{
"InventoryID": {"value": "AACOMPUT01"},
"OrderQty": {"value": 5}
},
{
"InventoryID": {"value": "AALEGO500"},
"OrderQty": {"value": 50}
}
]
}
This will create a Sales Order with 2 So Lines.
Though if you want to add more line to an existing order then you should only need to mention the key fields of the top level entity and then the details information that you would want to add.
In the case of the Sales Order, the key fields are the OrderType and the OrderNbr.
If you have the time, I would recommend that you take a look at the Acumatica help website section about working with the contract based API: https://help-2019r1.acumatica.com/(W(5))/Help?ScreenId=ShowWiki&pageid=1c767ad9-da6d-4047-bc93-6970ad469504
Related
I'm trying to get my Posts by multiple meta_keys and meta_values. How do I accomplish this? The URL should be looking like this:
"/posts?meta_key=Example&meta_value=Example2&meta_key=Example3&meta_value=Example4"
I tried to find a solution for this quite a while now, but couldn't find anything as most things were outdated.
I found a solution for my Problem. What i did is quite simple. I just setted up a new Query Params.
if (!function_exists('post_meta_rest_api_request')) :
function post_meta_rest_api_request($argu, $request)
{
$argu += array(
'meta_key' => $request['meta_key'],
'meta_value' => $request['meta_value'],
'meta_query' => $request['meta_query'] == 1 ? array(
array(
"key" => "key1",
"value" => "value1"
),
array(
"key" => "key2",
"value" => "value2"
)
) : $request['meta_query']
);
return $argu;
}
add_filter('rest_custom_query', 'post_meta_rest_api_request', 99, 2);
endif;
So if you now make an API call like: wordpress/wp-json/wp/v2/customType?meta_query=1
the API Request will take in your custom Query Params. Otherwise it will just take in the normal Meta Query Request.
For references look here: WordPress Rest-API Requests
If I have an "Automatic Billing" button setup on my site, which API can be used to set the variable billing amount and initiate the bill? Want I the API to do is described here: https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/manage-billing-plans/
I can't find this specifically anywhere but I'm not sure if it's lost in the different terminology between the PayPal API docs and the front-end - I say that because it's seems there is no such thing as Automated Billing in the API docs!
If you're wanting to use the REST API then look at Billing Plans.
If you want to use the Classic API look at Recurring Paymments.
To further the accepted answer, I could not achieve what I wanted - it seems that "Automatic Billing" cannot be triggered via an API. You need to create a billing plan, then create an agreement based on the plan, then execute the agreement.
From Andrew's answer, first I got an access token. In my cURLless environment, I did this:
//sandbox
$clientid = "AbFnq7P52jf6AUWpu.....";
$secret = "ECfJRJBDnA26VVNAq.....";
$url = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$auth = base64_encode($clientid . ":" . $secret);
$data = array(
'grant_type' => 'client_credentials'
);
$options = array(
'http' => array(
'header' => "Authorization: Basic {$auth}\r\nAccept: application/json\r\nAccept-Language: en_US\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$arr = json_decode($result, true);
echo "<pre>"; print_r($arr); echo "</pre>";
$accesstoken = $arr['access_token'];
Then followed the "Integration Steps" https://developer.paypal.com/docs/integration/direct/billing-plans-and-agreements/#integration-steps
I made my cURLless API calls like this (create plan example):
$url = 'https://api.sandbox.paypal.com/v1/payments/billing-plans/';
$options = array(
'http' => array(
'header' => "Authorization: Bearer {$accesstoken}\r\nContent-Type: application/json\r\n",
'method' => 'POST',
'content' => '{
"name": "Test Plan",
"description": "My first test plan",
"type": "INFINITE",
"payment_definitions": [
{
"name": "Regular payment definition",
"type": "REGULAR",
"type":"REGULAR",
"frequency":"Month",
"amount":{
"currency":"AUD",
"value":"100.00"
},
"cycles":"0",
"charge_models":[
{
"type":"TAX",
"amount":{
"currency":"AUD",
"value":"0.00"
}
},
{
"type":"SHIPPING",
"amount":{
"currency":"AUD",
"value":"0.00"
}
}
],
"frequency_interval":"1"
}
],
"merchant_preferences": {
"setup_fee": {
"value": "0",
"currency": "AUD"
},
"return_url": "http://www.paypal.com",
"cancel_url": "http://www.paypal.com/cancel",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE",
"max_fail_attempts": "0"
}
}'
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$arr = json_decode($result, true);
echo "<pre>"; print_r($arr); echo "</pre>";
Hopefully these snippets will save someone the hours I spent!
I'm trying to figure out how to edit an order after I requested it.
I made a custom attribute whether an order is exported or not.
I first get all orders with status not exported and after I exported them, I want to change the custom attribute to exported.
What is the REST request to edit/update an order? I keep getting error messages like:
{"message":"%fieldName is a required field.","parameters":
{"fieldName":"entity"}
This is my code:
$json = array(
"entity_id" => $id,
"extension_attributes" => array(
"custom_export_attribute" => "exported",
)
);
$webapi = new ApiClient('https://dev.local.nl', self::$username, self::$password);
$response = $webapi->getClient()->request('PUT', '/rest/V1/orders/create', [
'headers' => [
'Authorization' => "Bearer " . $webapi->getToken(),
'Content-Type' => "application/json"
],
'body' => json_encode($json)
]);
return json_decode($response->getBody(), true);
I also tried:
$webapi->getClient()->request('PUT', '/rest/V1/orders/'.$id,
To edit / update order details, the Magento 2 /V1/orders accepts POST request method. As per Magento 2 Dev Doc, it accepts the request body in below format (You can find whole JSON request in documentation page):
{
"entity": {
"entity_id": 0,
"extension_attributes": {
}
}
}
So, you just need to update the $json variable as:
$json = [
"entity"=> [
"entity_id" => $id,
"extension_attributes" => [
"custom_export_attribute" => "exported"
]
]
]
And than invoke with POST request method instead of PUT. In my suggestion prefer to use Create API for new order creation.
I always get an error when tyring to get the payment transactions of a user.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
I tried several approaches:
// approach 1
$response = $app['facebook']->api('/'.$app['user']['fbUserID'].'/payment_transactions', 'GET', [
//'request_id' => $order['requestID'],
'access_token' => $app['fb.app_id'].'|'.$app['fb.app_secret']
]);
// approach 2
$url = 'https://graph.facebook.com/'.$app['user']['fbUserID'].'/payment_transactions?fields=id&access_token='.$app['fb.app_id'].'|'.$app['fb.app_secret'];
$ch = curl_init();
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTPHEADER => array('Expect:'),
CURLOPT_CAINFO => DIR.'/vendor/facebook/php-sdk/src/fb_ca_chain_bundle.crt'
];
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
// approach 3
// like 2 but with a fresh access token
$appAccessToken = explode('=', file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$app['fb.app_id'].'&client_secret='.$app['fb.app_secret'].'&grant_type=client_credentials'))[1];
Even in the Graph API Explorer I get this error. Only if I use the commandline it works:
$ curl 'https://graph.facebook.com/........./payment_transactions?access_token=.......|.........'
The user is an test user which is also a payment tester and made successfull test-purchases. The Local Currency Payments Breaking Changes are disabled.
What am I doing wrong?
You need to use an app access token to GET from that endpoint. See https://developers.facebook.com/docs/graph-api/reference/user#payment_transactions for details.
Help, I'm trying to create a new post in my wordpress blog with custom fields using the following perl script using metaweblogAPI over XMLRPC, but there seems to be an issue with the custom fields. Only the second custom field (width) ever seems to get posted. Can't get the "height" to publish properly. When I add another field, I get the "Odd number of elements in anonymous hash" error. This has got to be something simple - would someone kindly sanity check my syntax? Thanks.
#!/usr/bin/perl -w
use strict;
use RPC::XML::Client;
use Data::Dumper;
my $cli=RPC::XML::Client->new('http://www.sitename.com/wp/xmlrpc.php');
my $appkey="perl"; # doesn't matter
my $blogid=1; # doesn't matter (except blogfarm)
my $username="Jim";
my $passwd='_____';
my $text=<<'END';
This is the post content...
You can also include html tags...
See you!
END
my $publish=0; # set to 1 to publish, 0 to put post in drafts
my $resp=$cli->send_request('metaWeblog.newPost',
$blogid,
$username,
$passwd,
{
'title' => "this is doodoo",
'description' => $text,
'custom_fields' => {
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
},
},
$publish);
exit 0;
While techically valid syntax, it's not doing what you think.
'custom_fields' => {
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
},
is roughly equivalent to something like:
'custom_fields' => {
'HASH(0x881a168)' => { "key" => "width", "value" => 750 }
},
which is certainly not what you want. (The 0x881a168 part will vary; it's actually the address where the hashref is stored.)
I'm not sure what the correct syntax for custom fields is. You can try
'custom_fields' => [
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
],
which will set custom_fields to an array of hashes. But that may not be right. It depends on what send_request expects.