Changing an action’s source¶
Below is a sample function written in python showing how to change the source of an action.
import requests
AK_USERNAME = '' # Enter your username
AK_PASSWORD = '' # Enter your password
AK_DOMAIN = 'docs.actionkit.com'
def change_action_source(action_id, source):
        """ Updates the action at action_id with the new source
        """
        endpoint = 'action'
        # Get the action by its ID
        response = requests.get(
            'https://{0}:{1}@{2}/rest/v1/{3}/{4}/'.format(
                AK_USERNAME,
                AK_PASSWORD,
                AK_DOMAIN,
                endpoint,
                action_id
            )
        )
        # Get the resource_uri from the response
        resource_uri = response.json()['resource_uri']
        # Apply the source
        response = requests.patch(
            'https://{0}:{1}@{2}{3}'.format(
                AK_USERNAME,
                AK_PASSWORD,
                AK_DOMAIN,
                resource_uri
            ), {
                "source": source
            }
        )
        if response.status_code == 202:
            return "Successfully changed source to {0} on action #{1}".format(
                source,
                action_id
            )
With that function defined, you’ll be able to use change_action_source() with a given action_id and source, like: change_action_source(11111, 'ad-campaign') which will change the action that has the ID 11111 to have a source of ‘ad-campaign’.