Whenever I log on the azure web portal i get a notification saying $xx.xx remaining credit.
I would like to understand how I can retrieve this value using Azure API, az cli or Powershell.
I have tried using the following as advised by the support but unfortunately without luck:
accesstoken=$(curl -s --header "accept: application/json" --request POST "https://login.windows.net/$TennantID/oauth2/token" --data-urlencode "resource=https://management.core.windows.net/" --data-urlencode "client_id=$ClientID" --data-urlencode "grant_type=client_credentials" --data-urlencode "client_secret=$ClientSecret" | jq -r '.access_token')
subscriptionURI="https://management.azure.com/subscriptions/$SubscriptionID?api-version=2016-09-01"
curl -s --header "authorization: Bearer $accesstoken" --request GET $subscriptionURI | jq .
The spending limit variable says just "on"
{
"authorizationSource": "RoleBased",
"subscriptionPolicies": {
"spendingLimit": "On",
redacted (too long)
When you see "$xx credit remaining", it means your account has spending limit. There are many offerings which use spending limit mode. For example, you are given Azure Pass, or Microsoft Azure for Students Starter. Here is the list for reference (https://azure.microsoft.com/en-us/support/legal/offer-details/).
In fact, Azure provides some REST APIs to let you work with Billing and Consumption but the API is limited to spending limit offerings. Advanced billing and consumption REST API are only fully supported for CSP (Cloud Service Provider) partner and Enterprise Agreement customers. That's said, with your current subscription, you cannot retrieve the balance summary (e.g https://learn.microsoft.com/en-us/rest/api/billing/enterprise/billing-enterprise-api-balance-summary).
However, there is a workaround to get usage details then perform SUM. To do so, first you need to retrieve billing period name
https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.Billing/billingPeriods?api-version=2017-04-24-preview
Here is the sample response of my billing periods:
"value": [
{
"id": "/subscriptions/2dd8cb59-ed12-4755-a2bc-356c212fbafc/providers/Microsoft.Billing/billingPeriods/201805-1",
"type": "Microsoft.Billing/billingPeriods",
"name": "201805-1",
"properties": {
"billingPeriodStartDate": "2018-02-06",
"billingPeriodEndDate": "2018-03-05"
}
},
{
"id": "/subscriptions/2dd8cb59-ed12-4755-a2bc-356c212fbafc/providers/Microsoft.Billing/billingPeriods/201804-1",
"type": "Microsoft.Billing/billingPeriods",
"name": "201804-1",
"properties": {
"billingPeriodStartDate": "2018-01-06",
"billingPeriodEndDate": "2018-02-05"
}
},
...then get usage detail with the billing period name
https://management.azure.com/subscriptions/{Subscription}/providers/Microsoft.Billing/billingPeriods/201805-1?api-version=2017-04-24-preview
{
"id": "subscriptions/2dd8cb59-ed12-4755-a2bc-356c212fbafc/providers/Microsoft.Billing/billingPeriods/201805-1/providers/Microsoft.Consumption/usageDetails/cdd74390-374b-53cf-2260-fc8ef10a2be6",
"name": "cdd74390-374b-53cf-2260-fc8ef10a2be6",
"type": "Microsoft.Consumption/usageDetails",
"tags": null,
"properties": {
"billingPeriodId": "subscriptions/2dd8cb59-ed12-4755-a2bc-356c212fbafc/providers/Microsoft.Billing/billingPeriods/201805-1",
"usageStart": "2018-02-06T00:00:00Z",
"usageEnd": "2018-02-07T00:00:00Z",
"instanceId": "/subscriptions/2dd8cb59-ed12-4755-a2bc-356c212fbafc/resourceGroups/securitydata/providers/Microsoft.Storage/storageAccounts/2d1993southeastasia",
"instanceName": "2d1993southeastasia",
"meterId": "c1635534-1c1d-4fc4-b090-88fc2672ef87",
"usageQuantity": 0.002976,
"pretaxCost": 7.1424E-05,
"currency": "USD",
"isEstimated": false,
"subscriptionGuid": "2dd8cb59-ed12-4755-a2bc-356c212fbafc",
"meterDetails": null
}
},
This returns list of each resource's usage and cost in JSON format and you need to SUM all pretaxCost value. This way would be complicated with PowerShell because you need to initialize objects, then deserialize JSON and perform MATH. With PowerShell, it can be done technically but requires C# experience.
Related
I'm trying to update a WooCommerce order using Update an Order in the Woo API (API Doc)
I want to add the following information into an order:
tracking provider
tracking number
tracking URL
I can add/update information inside of the "meta data" array, however, I can't seem to figure out how to update the "_wc_shipment_tracking_items" "value" array that is located within the "meta data" array.
So essentially, I want to update/create an array within an array. For a visual understanding, see (highlighted is where I want to update):
I’ve tried many variations, but the following is as far as I've come... I can’t seem to figure it out:
"meta_data": [
{
"key": "_wc_shipment_tracking_items"
"value": [
{
"key": "custom_tracking_provider",
"value": "postage service"
},
{
"key": "tracking_number",
"value": "aaa123"
},
{
"key": "custom_tracking_link",
"value": "https://google.com/"
}
]
}
]
I hope someone can help me out, or point me in the right direction. Thank you :)
The answer to your question can be found on this page:
https://woocommerce.com/document/shipment-tracking/
under 'REST API Support' you will find this piece of code that you need:
curl -X POST https://example.com/wp-json/wc-shipment-tracking/v3/orders/645/shipment-trackings \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"custom_tracking_provider": "Custom",
"custom_tracking_link": "https://example.com?q=%1$s",
"tracking_number": "12345678"
}'
I want to get all the results from a full text search index in couchbase. However, the default limit is 10 results.
I am aware that I can customize the size to a specific number, but is it possible to set it such that I get all the results in one go?
Something like "size":"*" or "size":"all"
curl -u user:password -X POST -H "Content-Type: application/json" \
-d '{"query": {"query": "search_token"}, "size": 10}' \
http://1.2.3.4:8094/api/index/myindex/query
It doesn't look like there's an "all" option for size. Omitting size falls back to 10.
I tried using a really large number, and got an error message:
{
"error": "rest_index: Query, indexName: ix_myindex, err: bleve: bleveMaxResultWindow exceeded, from: 0, size: 999999999, bleveMaxResultWindow: 10000",
"request": {
"query": {
"query": "search_token"
},
"size": 999999999
},
"status": "fail"
}
So, 10000 is the max you can ask for by default.
According to Couchbase ticket MB-17539, you can increase the maximum:
curl -XPUT -H "Content-type:application/json" http://<username>:<password>#<ip>:8094/api/managerOptions -d '{"bleveMaxResultWindow": "100000"}'
I tried this, and it works. However, I don't see this endpoint in the documentation so it might change/become deprecated in the future.
But, I really have to wonder why you need this many results at once? Is paging not an option for you? (e.g. a body of {"query": {"query": "search_token"}, "size": 10, "from": 10}).
I don't know much about how to use an API, and I am just trying to get a basic understanding so I can use the Timekit.io API in a JS app I am going to build, so to start I though I should try and use postman to learn how to send a request. In the Timekit documentation for finding a time from a resource ie: a persons calendar they say to use this curl command.
curl --request POST \
--url https://api.timekit.io/v2/findtime \
--header 'Content-Type: application/json' \
--user :live_api_key_7nzvc7wsBQQISLeFSVhROys9V1bUJ1z7 \
--data '{
"resource_ids": ["78a4d873-2a68-41c6-bdd4-c0ca5b35efd3"],
"filters": { "or": [
{"specific_day_and_time":{"day":"Monday","start":9,"end":13}},
{"specific_day_and_time":{"day":"Wednesday","start":10,"end": 16}}
]},
"future": "2 days",
"length": "30 minutes"
}'
I am trying to figure out what I put into postman itself so I get the correct Json values. So far I have selected a POST request with the url https://api.timekit.io/v2/findtime and a header with the key Content-Type and value application/json I have no idea where to put the user,data,rsource_ids,filters,future & length Here is a screenshot of my post man setup.
--user sets the authentication. If an authentication type is not specified, then it will default to Basic Authentication. In Postman, click the "Authentication" tab and from the "Type" dropdown, select "Basic Auth". You can then input the username and password into the appropriate fields. With the --user flag, the value should be <username>:<password>. So your case, there is no username specified, so I guess you don't need to input it, just use the api key for the password.
--data is the JSON request body. You can input this entire value (within the single quotes ') into the "Body" tab. Select the "Body" tab, and within the tab, select the "raw" radio button, and from the dropdown to the right, select "JSON (application/json)". Now just put the entire JSON into the text area.
{
"resource_ids": ["78a4d873-2a68-41c6-bdd4-c0ca5b35efd3"],
"filters": {
"or": [
{ "specific_day_and_time":{ "day":"Monday", "start":9, "end":13 } },
{ "specific_day_and_time":{ "day":"Wednesday", "start":10, "end": 16 } }
]
},
"future": "2 days",
"length": "30 minutes"
}
You could just drop the curl request straight into Postman via the Import feature, this would populate the whole request in the application for you.
In the top left of the application UI, select the Import button and then select the 'raw' text option (it’s the last one) - paste the curl request text into the text box. Once imported, that should do the rest for you, if it’s a valid format.
The alchemy api for entities (TextGetRankedNamedEntities) seems to have a text limit around 7500 characters. I was wondering if this was a documented limitation or a defect?
I just successfully sent a text doc with >40,000 characters successfully without any issues. I've posted the API Notes, CURL Command, and Response I got below.
CURL Command:
curl -X POST \
-d "apikey=$API_KEY" \
-d "outputMode=json" \
--data-urlencode text#testing.txt \
"https://gateway-a.watsonplatform.net/calls/text/TextGetRankedNamedEntities"
Response:
{
"status": "OK",
"usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing
to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
"url": "",
"language": "english",
"entities": [
{
"type": "Company",
"relevance": "0.833922",
"count": "31",
"text": "TextGetRankedNamedEntities"
},
{
"type": "Quantity",
"relevance": "0.833922",
"count": "31",
"text": "50 kilobytes"
}
]
}
API Notes:
Calls to TextGetRankedNamedEntities should be made using HTTP POST.
HTTP POST calls should include the Content-Type header: application/x-www-form-urlencoded
Posted text documents can be a maximum of 50 kilobytes. Larger documents will result in a "content-exceeds-size-limit" error response.
Language detection is performed on the retrieved document before attempting named entity extraction. A minimum of 15 characters of text must exist within the requested HTTP document to perform language detection.
Documents containing less than 15 characters of text are assumed to be English-language content.
Disambiguation of detected entities is enabled by default. Disambiguation information will be included for each entity that is successfully resolved.
Entity extraction is currently supported for all languages listed on the language support page. Other non-supported language submissions will be rejected and an error response returned.
Enabling entity-level sentiment analysis results in one additional transaction utilized against your daily API limit. Entity-level sentiment analysis is currently provided for both English and German-language content.
Disambiguation and quotations extraction are currently available for English-language content only. Support for other languages is in development.
I need to mimic the behavior of the targeting selection screen, just make it simpler, limiting the choice to few languages and a few hundred cities, see the picture of the original screen below. I tried calling
curl -G \
-d 'targeting_spec="{"geo_locations":{"countries":["BE"],"zips":[{"key":"BE:1000"}],"locales":[{"key":"1003"}]}}' \
-d 'access_token=TOKEN' \
https://graph.facebook.com/v2.3/act_AD_ACCOUNT_ID/reachestimate
but I get the message
{
"error": {
"message": "The entity backed by id ENTITY_ID cannot be seen by the viewer with (ViewerID 0, AccountID 0): DENY_RULE:InlinePrivacyPolicy:AlwaysDenyRule:4 (EntID: ENTITY_ID)",
"type": "OAuthException",
"code": 1
}
}
Should I ask for more permissions from Facebook? And how? I am just trying to build a simple website app.
You need to have ads management scope added to your access token and as I take it you are in development mode you need to ensure that the ad account that you are sending requests for is on your account list
https://developers.facebook.com/docs/marketing-api/access#standard_accounts
Your curl command should be as follows:
- You don't need countries and zips as part of geolocations as they overlap
- locales is not part of geo_locations and is not an array of key/value pairs - it is an array of ints.
curl -G \
-d 'targeting_spec={"geo_locations":{"zips":[{"key":"BE:1000"}]},"locales":[1003]}' \
-d 'access_token=[access_token]' \
https://graph.facebook.com/v2.3/[account_id]/reachestimate