Tuesday, December 28, 2021

[FIXED] Format balance availablefrom facebook api

Issue

I am trying to get the balance that a facebook ad account has positive or negative, however, I am following the facebook documentation and the same says that the field is "balance", below I am putting the print taken from the facebook documentation.

enter image description here

I'm getting this value according to the documentation the problem is that I don't know how to format the value correctly, the value is coming without a decimal separator, has anyone been there? How do I know when to format the value with decimal or not?

Below is the printout of my return that I'm getting from the API.

enter image description here


Solution

You should consider the AdAccounts currency offset, as described here, as a static table:

Offset

Each currency has an offset which specifies how Facebook should handle its sub-divisions. This is to ensure that the minimum bid, such as "1", is a usable value for the currency.

Example offset 100

If a currency has an offset of 100 then the minimum allowed bid is assumed to be 1/100 of the currency base unit. For example, if you place a bid of "1" on an ad account based on USD the bid will be 0.01 USD.

Example offset 1

If a currency has an offset of 1 then the minimum allowed bid is assumed to be in the currency base unit. For example, if you place a bid of "1" on a ad account based on JPY the bid will be 1 JPY.

A sample of the table:

Name Code Offset
Algerian Dinar DZD 100
Argentine Peso ARS 100
.. .. ..
Brazilian Real BRL 100
.. .. ..
Chilean Peso CLP 1
.. .. ..

So for your currency you should consider an offset of 100.



Answered By - Matteo

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.