Skip to main content

How to contribute

After clone repository

1.- Install dependencies

poetry install

2.- Run test

make test

3.- Run lint

make lint && make isort

How to publish new version

Once we have done a merge of our Pull request and we have the updated master branch we can generate a new version. For them we have 3 commands that change the version of our library and generate the corresponding tag so that the Bitbucket pipeline starts and publishes our library automatically.

make release-patch
make release-minor
make release-major

How works

This project provides an API for querying Salesforce opportunities data and transforming it into an easy-to-use format. The API is built upon the SalesforceQueryExecutor and Project classes, with the latter inheriting from SalesforceQueryExecutor.

Installation

Make sure you have Python 3.8+ installed. Then, install the required dependencies using poetry:

poetry install ms-salesforce-api

Testing

To run the unit tests, simply execute the following command:

make test

This will run all the tests and display the results. Make sure that all tests pass before using the API in a production environment.

Usage

First, import the necessary classes:

from ms_salesforce_api.salesforce.project import Project

Then, initialize the Project class with your Salesforce credentials:

project = Project(
    client_id="your_client_id",
    username="your_username",
    domain="your_domain",
    private_key="your_private_key",
    audience="https://login.salesforce.com", # Default value
    session_duration_hours=1, # Default value
    api_version='57.0',  # Default value
)

Now, you can call the get_all method with a query to get the opportunities data:

opportunities = project.get_all()

The opportunities variable will contain an array of opportunity objects with the transformed data. For example:

[
 {
    "account_assigment_group": None,
    "account_billing_address": "C/ XXX XXX, 8 Planta 9ª, 28020, Spain",
    "account_billing_city": None,
    "account_billing_country": "ES",
    "account_billing_postal_code": "28020",
    "account_billing_state_code": None,
    "account_billing_street": "C/ XXX XXX, 8 Planta 9ª",
    "account_business_function": "XXXX",
    "account_business_name": "XXXXXX",
    "account_cif": "ESXXXXXXX",
    "account_company_invoicing": "2411",
    "account_created_date": "2022-03-28T09:05:44.000+0000",
    "account_currency_code": "",
    "account_fax": None,
    "account_invoicing_email": None,
    "account_mail_invoicing": None,
    "account_name": "XXXXXXXX",
    "account_office": "XXXXXXXX",
    "account_payment_terms": "T030",
    "account_pec_email": None,
    "account_phone": None,
    "account_sap_id": "10001210",
    "account_tax_category": None,
    "account_tax_classification": None,
    "account_tax_id_type": "ES0",
    "account_tier": "T1",
    "account_website": None,
    "amount": 0,
    "billing_lines": [
        {
            "billing_amount": 274.33,
            "billing_date": "2022-01-31",
            "billing_period_ending_date": "2022-03-31",
            "billing_period_starting_date": "2022-01-01",
            "billing_plan_amount": "274.33",
            "billing_plan_billing_date": "2022-01-31",
            "billing_plan_item": "0",
            "billing_plan_service_end_date": "2022-03-31",
            "billing_plan_service_start_date": "2022-01-01",
            "created_date": "2022-07-08T10:07:08.000+0000",
            "currency": "EUR",
            "hourly_price": None,
            "id": "XXXXXXXXXXXX",
            "last_modified_date": "2023-05-04T12:24:25.000+0000",
            "name": "BL-XXXXXXXX",
            "project_id": "YYYYYYYYYYYYY",
            "revenue_dedication": None,
        }
    ],
    "controller_email": "employee@makingscience.com",
    "controller_sub_email": "",
    "cost_center": "0220001800",
    "created_at": "2021-10-06T14:35:18.000+0000",
    "currency": "EUR",
    "invoicing_country_code": "ES",
    "jira_task_url": "<a href=https://makingscience.atlassian.net/browse/ESMSBD0001-1080 target=_blank>View Jira Task</a>",
    "last_updated_at": "2023-06-08T11:22:55.000+0000",
    "lead_source": "Employee Referral",
    "operation_coordinator_email": "employee@makingscience.com",
    "operation_coordinator_sub_email": "",
    "opportunity_name": "Branding Campaign",
    "opportunity_percentage": 100.0,
    "profit_center": "200018",
    "project_code": "ESMSEX01652",
    "project_id": "a003X00001WS2YHQA1",
    "project_line_items": [
        {
            "country": "Spain",
            "created_date": "2022-05-05T12:28:48.000+0000",
            "effort": None,
            "ending_date": "2022-03-31",
            "id": "a0V7U000001OdiUUAS",
            "last_modified_date": "2023-06-08T11:20:42.000+0000",
            "ms_pli_name": "Omnichannel_ESMSEx01652_ES",
            "product_name": "Advertising Lead Gen Proj",
            "quantity": None,
            "starting_date": "2022-01-01",
            "total_price": 0.0,
            "unit_price": 2230.99,
        }
    ],
    "project_name": "BrandingCampaignPilotESMSEx01652",
    "project_start_date": "2021-12-01",
    "project_tier": "Unkown",
    "stage": "Closed Won",
}
]

You can customize the query as needed to retrieve different data from Salesforce.

query = "SELECT Id, Name FROM Project WHERE Project.Id = 'ESMS0000'"

opportunities = project.get_all(query=query)

Export data

This library allow to export all opportunities data to a external database such Postgres and BigQuery. Podemos importar cualquiera de las clases:

from ms_salesforce_api.salesforce.api.project.export_data.Bigquery import (
    BigQueryExporter,
)

o

from ms_salesforce_api.salesforce.api.project.export_data.CloudSQL import (
    CloudSQL
)

Both classes, when initialized, are in charge of creating the databases and the tables to export the data in case they do not exist.

BigQueryExporter

The Bigquery class provides functionalities to export data to Google BigQuery.

ℹ️ Información
The "BigqueryExporter" class needs an environment variable named "GOOGLE_SERVICE_ACCOUNT_CREDENTIALS" to exist and its value must be the JSON of the Service Account that has permissions to write to BigQuery and must be in base64
class BigqueryExporter:
    def __init__(self, project_id: str, dataset_id: str):
        """
        Initializes the Bigquery exporter with the given project ID and dataset ID.

        Args:
            project_id (str): The ID of the Google Cloud project.
            dataset_id (str): The ID of the BigQuery dataset.
        """

Methods

  • export_data(data: List[Dict[str, Any]]) -> None Exports the provided data to BigQuery.

    • data (List[Dict[str, Any]]): This variable has the value of "opportunities" returned by the "get_all" method.
  • delete_all_rows() -> None Delete all data for each table (Opportunities, Accounts, Billing line and PLIs). In this way we can have the database updated at all times.

CloudSQL

The CloudSQL class provides functionalities to interact with a Google Cloud SQL database.

Constructor

class CloudSQL:
     def __init__(self, host, user, password, dbname, debug_mode=False):
        """
        Connect with a Postgres Database with the given
        host name, database name, username, and password.

        Args:
            host (str): The host name for the Postgres database.
            user (str): The username for accessing the database.
            password (str): The password for accessing the database.
            dbname (str): The name of the database.
        """

Methods

  • export_data(data: List[Dict[str, Any]]) -> None Exports the provided data to BigQuery.

    • data (List[Dict[str, Any]]): This variable has the value of "opportunities" returned by the "get_all" method.
  • delete_all_rows() -> None Delete all data for each table (Opportunities, Accounts, Billing line and PLIs). In this way we can have the database updated at all times.

Metadata

Release files for ms-salesforce-api 3.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ms-salesforce-api 3.14.0
File Size Uploaded Provenance Actions
ms_salesforce_api-3.14.0.tar.gz 66.6 kB Without provenance Details for ms_salesforce_api-3.14.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ms-salesforce-api 3.14.0
File Interpreter ABI Platform Actions
ms_salesforce_api-3.14.0-py3-none-any.whl Python 3 none any Details for ms_salesforce_api-3.14.0-py3-none-any.whl

Total release size: 175.3 kB

Release files / ms_salesforce_api-3.14.0.tar.gz

Download URL ms_salesforce_api-3.14.0.tar.gz
Size 66.6 kB
Tags Source
SHA-256 checksum
How to use checksums
db48f3ef08dd53d359b94e4a7f4cbffc29a3b67a43e499fc21349242c772e725
BLAKE2b-256 checksum
How to use checksums
e56b55674745ddd0a01fbe2120e5df9f357b14dd741b88520f5cb4fd12b23b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.3 Linux/6.17.0-1022-azure

Release files / ms_salesforce_api-3.14.0-py3-none-any.whl

Download URL ms_salesforce_api-3.14.0-py3-none-any.whl
Size 108.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e41d66fccb527c647bc3d4d58eec11f01676b42f9518a3e1f5d7bcf475f34257
BLAKE2b-256 checksum
How to use checksums
ea4f925f3bd96e5a9a2764d013ff79b904bfbde767a86d407826916aeb0484ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.3 Linux/6.17.0-1022-azure

Security for ms-salesforce-api 3.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.14.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page