Fixes problem with variable value persistence through multiple runs

There exists a problem within the code whereby the values of endpoint do not get reset through multiple runs, upon a second run endpoint.path is no longer /containers/${id}/start, but instead /containers/XXXXXXXXX/start. This is caused because the var endpoint is called outside of the API function definition. Each time start, stop, etc are called the API function is called. By moving the declaration of the endpoint variable inside this function ensures that each time a container action is called a cloned copy of endpointThis is created, instead of using old values.

@dweinstein found the odd behavior, I helped him troubleshoot and identify the fix.