Legacy Dev Forum Posts

 View Only

Sign Up

Create skills using Python

  • 1.  Create skills using Python

    Posted 06-05-2025 18:18

    Chris_Carr | 2021-02-18 15:52:15 UTC | #1

    Hi,

    I would like to create skills using the API using python but I am unsure where I specify the name of the skill in the code below. Please help

    import time

    import PureCloudPlatformClientV2

    from PureCloudPlatformClientV2.rest import ApiException

    from pprint import pprint

    Configure OAuth2 access token for authorization: PureCloud OAuth

    PureCloudPlatformClientV2.configuration.accesstoken = 'YOURACCESS_TOKEN'

    create an instance of the API class

    api_instance = PureCloudPlatformClientV2.RoutingApi()

    body = PureCloudPlatformClientV2.RoutingSkill() # RoutingSkill | Skill

    try:

    Create Skill

    apiresponse = apiinstance.postroutingskills(body)

    pprint(api_response)

    except ApiException as e:

    print("Exception when calling RoutingApi->postroutingskills: %s\n" % e)


    Jerome.Saint-Marc | 2021-02-18 16:43:31 UTC | #2

    Hello Chris,

    The body variable is a RoutingSkill. So you can do the following:

    body = PureCloudPlatformClientV2.RoutingSkill() # RoutingSkill | Skill body.name = "The name of your skill"

    You'll also have to adapt the beginning of your script - related to the region of your org and the Authentication/Authorization token.

    As your org seems to be located in Ireland (.ie - eu-west-1 region), you have to set the proper environment (to point to the right region), as described here:

    Configure OAuth2 access token for authorization: PureCloud OAuth

    region = PureCloudPlatformClientV2.PureCloudRegionHosts.euwest1 PureCloudPlatformClientV2.configuration.host = region.getapihost()

    The sample you posted is based on a copy of a token you have obtained. So if this is what you are doing, you can keep the code as it is and replace the YOURACCESSTOKEN with a valid token. If you are planning to manage the authentication directly in your code, you would have to create an OAuth Client using Client Credentials Grant (make sure to assign necessary roles/permissions for this API). And then in your code, use something like it is described here or in this tutorial

    I mean:

    import time import PureCloudPlatformClientV2 from PureCloudPlatformClientV2.rest import ApiException from pprint import pprint

    Configure Region

    region = PureCloudPlatformClientV2.PureCloudRegionHosts.euwest1 PureCloudPlatformClientV2.configuration.host = region.getapihost()

    OAuth when using Client Credentials

    clientid = 'CLIENTID' clientsecret = 'CLIENTID'

    Authenticate client

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken(clientid, client_secret)

    create an instance of the API class

    apiinstance = PureCloudPlatformClientV2.RoutingApi(apiclient) body = PureCloudPlatformClientV2.RoutingSkill() # RoutingSkill | Skill body.name = "The name of your skill"

    try:

    Create Skill

    apiresponse = apiinstance.postroutingskills(body) pprint(apiresponse) except ApiException as e: print("Exception when calling RoutingApi->postrouting_skills: %s\n" % e)

    PS: I must say I haven't tried the code above. I don't code (that much) in python. But I think it should work. :slight_smile:

    Regards,


    Chris_Carr | 2021-02-18 16:46:55 UTC | #3

    Thank you very much!!!! I will give it a go now and yes sorry I know about the region issue I made a mistake when I pasted the code my full code looks like the below. I will try your suggestion and let you know. Thanks again!! :slight_smile:

    from os import name

    import time

    import PureCloudPlatformClientV2

    from PureCloudPlatformClientV2.models.routing_skill import RoutingSkill

    from PureCloudPlatformClientV2.rest import ApiException

    from pprint import pprint

    region = PureCloudPlatformClientV2.PureCloudRegionHosts.euwest1

    PureCloudPlatformClientV2.configuration.host = region.getapihost()

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken("CLIENT ID", "SECRET")

    authApi = PureCloudPlatformClientV2.AuthorizationApi(apiclient)

    print(authApi.getauthorizationpermissions())

    print("Connected")

    create an instance of the API class

    api_instance = PureCloudPlatformClientV2.RoutingApi()

    body = PureCloudPlatformClientV2.RoutingSkill() # RoutingSkill | Skill

    try:

    Create Skill

    apiresponse = apiinstance.postroutingskills(body)

    pprint(api_response)

    except ApiException as e:

    print("Exception when calling RoutingApi->postroutingskills: %s\n" % e)


    Jerome.Saint-Marc | 2021-02-18 16:53:13 UTC | #4

    api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient)


    Chris_Carr | 2021-02-18 16:54:48 UTC | #5

    :) I found that error and it is working perfectly now! thanks a lot...now the last thing I am trying to do is create a list containing names of skills then creating a for loop to create each skill


    Chris_Carr | 2021-02-18 16:58:14 UTC | #6

    This seems to do the job now. Does the code look okay? I did not copy the entire code again just a snippet

    create an instance of the API class

    api_instance = PureCloudPlatformClientV2.RoutingApi(apiclient)

    body = PureCloudPlatformClientV2.RoutingSkill() # RoutingSkill | Skill

    skill_list = ["test1", "test2", "test3"]

    for skill in skill_list:

    body.name = skill

    try:

    Create Skill

    apiresponse = apiinstance.postroutingskills(body)

    pprint(api_response)

    except ApiException as e:

    print("Exception when calling RoutingApi->postroutingskills: %s\n" % e)


    John_Carnell | 2021-02-18 17:20:12 UTC | #7

    Hi Chris,

    The code looks good. I would also recommend you take a look at our CLI. We have exposed many of the core objects (like skills). Even if you don't use it in your code, it is a good place to help to poke around on our API and understand how it works. Note: We purposely have not exposed all of the APIs in Genesys Cloud through the CLI because we really wanted to understand how people would use the CLI before expose every single part of our API.

    If you want to learn more about it, please check out the blog post here. This blog post covers the background on the CLI and also provides links to the documentation, how to download it, a quick video, etc... If you have any feedback or ideas for new features please do not hesitate to drop me a direct message.

    Thanks, John Carnell Manager, Developer Engagement


    system | 2021-03-21 17:20:17 UTC | #8

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 10033