Opportunities LINKS (organisation ID)

 

Hi I got Insigthly SDK by Brian McConnell,  who I would like to say thanks for share your knowledge about python /Insightly API very usefully!

 I am an Insightly user and starting to create python codes… very  beginner programmer, but my first task is create an internal app integrated with Insightly, where a need to get an opportunity ID, and the organization code/name that they are into  opportunities/LINKS….  I can´t do  that! D

how I can do that, somebody can help me !

 

tks in advance

Carmello

 

0

Comments

4 comments
  •  

    Hi Carmello,

    If I'm understanding your question correctly, it sounds like you're trying to create a Link between an Opportunity and Organisation. The Python library is an open source library that's intended to assist customers, so I had to spend some time looking over the source code to see how it works.

    It looks like there's a create_child(...) method that can be used to create a link.

    Here is a little example of how you could go about doing that:

    from insightly import Insightly

    api = Insightly(apikey='<YOUR API KEY>', version='2.2')

    #create some objects that will be Linked
    opportunity = api.create('opportunities',{'OPPORTUNITY_NAME':'Foo Opportunity','OPPORTUNITY_STATE':'OPEN'})
    organisation = api.create('organisations',{'ORGANISATION_NAME':'Foo Organisation'})

    #create a link for your Opportunity to your Organisation
    link = api.create_child('opportunities', opportunity['OPPORTUNITY_ID'], 'links', {'ORGANISATION_ID':organisation['ORGANISATION_ID']})
    print link

    opportunity = api.read('opportunities', opportunity['OPPORTUNITY_ID'])[0]

    print opportunity

    You also mentioned that you need the ID itself. You could get a list of Opportunities and Organisations using the read(...) method.

    opportunities = api.read('opportunities')
    organisations = api.read('organisations')
    print opportunities
    print organisations

    Also, since this is an open source library, you can also dig through the source code to see how it was implemented, to give yourself some ideas on how you could implement a more customized solution.

    Documentation for the API can be found here https://api.insight.ly/v2.2/Help#! .

    Good luck!
    Sung

     

     

     

     

     

    0
    Comment actions Permalink
  • Hi

     

    Actually I need to read an opportunity id and get the existents links and check the organization id and organization name are linked on that!!

    Following  a sample in json format, where I have an opportunity id 6800505, and two links item , one for contact and another for organization.

     

    I need to check if there is a link items, if there is, check  each one have an organization id, and them  get the organization  information .. I will get those information into my local application. (opportunity info and organization info).

     

    I hope it is clear what I need.. sorry for my poor English....

     

    [
    {
    "BID_TYPE": "Fixed Bid",
    "BID_CURRENCY": "BRL",
    "VISIBLE_TEAM_ID": 2039537,
    "BID_DURATION": null,
    "OPPORTUNITY_VALUE": 349000,
    "OPPORTUNITY_STATE_REASON_ID": null,
    "RESPONSIBLE_USER_ID": 660462,
    "PROBABILITY": 75,
    "FORECAST_CLOSE_DATE": "2016-03-31 00:00:00",
    "ACTUAL_CLOSE_DATE": null,
    "VISIBLE_TO": "TEAM",
    "PIPELINE_ID": 119092,
    "IMAGE_URL": null,
    "VISIBLE_USER_IDS": null,
    "OPPORTUNITY_ID": 6800505,
    "STAGE_ID": 361631,
    "DATE_UPDATED_UTC": "2016-03-24 15:19:38",
    "TAGS": [],
    "OPPORTUNITY_DETAILS": null,
    "OPPORTUNITY_STATE": "OPEN",
    "CUSTOMFIELDS": [
    {
    "FIELD_VALUE": "Symantec",
    "CUSTOM_FIELD_ID": "OPPORTUNITY_FIELD_1"
    },
    {
    "FIELD_VALUE": "Products",
    "CUSTOM_FIELD_ID": "OPPORTUNITY_FIELD_2"
    }
    ],
    "OPPORTUNITY_NAME": "Walmart - VERITAS - NBU Appliance",
    "LINKS": [
    {
    "ORGANISATION_ID": 56698004,
    "SECOND_PROJECT_ID": null,
    "CONTACT_ID": null,
    "LINK_ID": 73044326,
    "ROLE": null,
    "DETAILS": null,
    "SECOND_OPPORTUNITY_ID": null,
    "PROJECT_ID": null,
    "OPPORTUNITY_ID": 6800505
    },
    {
    "ORGANISATION_ID": null,
    "SECOND_PROJECT_ID": null,
    "CONTACT_ID": null,
    "LINK_ID": 73167654,
    "ROLE": "",
    "DETAILS": null,
    "SECOND_OPPORTUNITY_ID": 6813467,
    "PROJECT_ID": null,
    "OPPORTUNITY_ID": 6800505
    }
    ],
    "BID_AMOUNT": 349000,
    "DATE_CREATED_UTC": "2015-04-28 14:28:08",
    "OWNER_USER_ID": 649303,
    "CATEGORY_ID": 2780706
    }
    ]

     

     

    Tks

    Carmello

    0
    Comment actions Permalink
  • Hi Carmello,

    I'm not a Python expert by any means, so there could very well be a better way to do this; Does this code snippet help?

    from insightly import Insightly

    api = Insightly(apikey='<YOUR API KEY>', version='2.2')

    opportunity = api.read('opportunities', 6800505)[0]
    print opportunity

    if len(opportunity['LINKS']) > 0:
    print 'links exist'
    for link in opportunity["LINKS"]:
    if link['ORGANISATION_ID'] is not None:
    print str(link['LINK_ID']) + '] link has an org id (' + str(link['ORGANISATION_ID']) + ')'
    org = api.read('organisations', link['ORGANISATION_ID'])[0]
    print org
    #update your org values here
    api.update('organisations', org)
    else:
    print str(link['LINK_ID']) + '] link does not have an org id'
    else:
    print 'no links'

     

    Regards,

    Sung

    1
    Comment actions Permalink
  • Perfet!!!  it works P E R F E C T !!!!

     

    Tks so much !!!

    1
    Comment actions Permalink

Please sign in to leave a comment.