Jira cloud automated backup powershell script issue

Issue #12 resolved
Diego Gimenez created an issue

Hi all,

I've downloaded powershell script to automate Jira Cloud backups from that site. First days it worked fine. But now it is not working for any reason. I get the following error and it reapeats indefinitely.

Could you please help me?

Thanks,

Diego

Invoke-RestMethod : Error en el servidor remoto: (401) No autorizado. En C:\Users\user\Desktop\backup.ps1: 23 Carácter: 15 + ... $status = Invoke-RestMethod -Method Get -Headers @{"Accept"="applic ... + ~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc eption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Comments (11)

  1. Dario B

    Hi Diego,

    The error you are getting is 401 - Unauthorized. Try to reset the password you use to authenticate into your Cloud instance since most likely it has been blocked after either many attempts with the wrong password or multiple connections at the same time with different IPs or because your Cloud instance has been moved to Atlassian Account and you need to confirm the password or similar...

    In case this won't work, please open a support case in support.atlassian.com to have this issue further investigated.

    Cheers,

    Dario

  2. Diego Gimenez reporter

    Thanks Dario for your reply. I´ve reset the password, but I´m getting the following error now.

    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
      • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand Invoke-RestMethod : Oops, encontraste un link muerto. - JIRAcontextPath = "";document.body.className += " js-enabled";Oops, encontraste un link muerto.Navegar a la página anteriorNavegar a la Página de InicioAtlassian En C:\Users\dgimenez\Downloads\backup.ps1: 23 Carácter: 15
    • ... $status = Invoke-RestMethod -Method Get -Headers @{"Accept"="applic ...
  3. Diego Gimenez reporter

    Based on error posted previously, I changed the following line:

    $status = Invoke-RestMethod -Method Get -Headers @{"Accept"="application/json"} -Uri "https://$hostname/rest/obm/1.0/getprogress" -WebSession $sesión

    by the following:

    $status = Invoke-RestMethod -Method Get -Headers @{"Accept"="application/json"} -Uri "https://$hostname/wiki/rest/obm/1.0/getprogress" -WebSession $sesión

    Now, I'm getting error 401 again. I´ve changed password but it didn´t work.

    Invoke-RestMethod : Error en el servidor remoto: (401) No autorizado.

  4. Dario B

    Hi Diego,

    Just try one thing at the time. Use CURL to test if the problem is with the credentials used for authentication or with the code:

    curl -D- -H "content-type: application/json" -c cookie.txt -d '{"username":"USERNAME_HERE","password":"PASSWORD_HERE"}' -X POST https://INSTANCE_URL/rest/auth/1/session
    

    Then:

    curl -D- -H "content-type: application/json" -b cookie.txt -X GET https://INSTANCE_URL/rest/api/2/mypermissions
    
  5. Diego Gimenez reporter

    Hi Dario,

    From the first command I got the following output:

    HTTP/1.1 400 Bad Request Server: Atlassian Proxy/0.5.83 ATL-vTM-Backend-Time: 103 Cache-Control: no-cache, no-store, no-transform Content-Type: application/json;charset=UTF-8 Strict-Transport-Security: max-age=315360000; includeSubDomains; preload Date: Mon, 26 Jun 2017 12:50:54 GMT X-AREQUESTID: 770x477803x2 transfer-encoding: chunked ATL-vTM-Time: 267 X-AUSERNAME: anonymous X-Content-Type-Options: nosniff Connection: close Set-Cookie: atlassian.xsrf.token=B12I-NKAM-2R8L-E4UH|4df8fe46b9105b1a9648d5eb4bd29edf9743927d|lout; Path=/; Secure ATL-vTM-Queue-Time: 0

    {"errorMessages":["Unexpected character ('u' (code 117)): was expecting double-quote to start field name\n at [Source: o rg.apache.catalina.connector.CoyoteInputStream@4b889533; line: 1, column: 3]"]}

    From second command, I got the following output:

    HTTP/1.1 200 OK Server: Atlassian Proxy/0.5.83 Vary: Accept-Encoding ATL-vTM-Backend-Time: 75 Cache-Control: no-cache, no-store, no-transform Content-Type: application/json;charset=UTF-8 Strict-Transport-Security: max-age=315360000; includeSubDomains; preload Date: Mon, 26 Jun 2017 12:58:51 GMT X-AREQUESTID: 778x487558x2 transfer-encoding: chunked ATL-vTM-Time: 239 X-AUSERNAME: anonymous X-Content-Type-Options: nosniff Connection: keep-alive ATL-vTM-Queue-Time: 0

    {"permissions":{"VIEW_WORKFLOW_READONLY":{"id":"45","key":"VIEW_WORKFLOW_READONLY","name":"Visualizar Flujo de Trabajo", "type":"PROJECT","description":"admin.permissions.descriptions.VIEW_WORKFLOW_READONLY","havePermission":false,"deprecate dKey":true},"CREATE_ISSUES":{"id":"11","key":"CREATE_ISSUES","name":"Crear incidencias","type":"PROJECT","description":" Capacidad para crear incidencias.","havePermission":false},"VIEW_DEV_TOOLS":{"id":"29","key":"VIEW_DEV_TOOLS","name":"Ve r herramientas de desarrollo","type":"PROJECT","description":"Permite a los usuarios de un proyecto de software ver info rmaci├│n vinculada con el desarrollo acerca de la incidencia, como por ejemplo commits, revisiones e informaci├│n de bui lds.","havePermission":false},"BULK_CHANGE":{"id":"33","key":"BULK_CHANGE","name":"Cambiar simult├íneamente","type":"GLO BAL","description":"Capacidad para modificar una colecci├│n de incidencias a la vez. Por ejemplo, resolver varios incide ncias en un solo paso.","havePermission":false},"CREATE_ATTACHMENT":{"id":"19","key":"CREATE_ATTACHMENT","name":"Crear a rchivos adjuntos","type":"PROJECT","description":"Usuarios con este permiso pueden crear adjuntos.","havePermission":fal se,"deprecatedKey":true},"DELETE_OWN_COMMENTS":{"id":"37","key":"DELETE_OWN_COMMENTS","name":"Borrar tus comentarios","t ype":"PROJECT","description":"Capacidad para borrar tus comentarios.","havePermission":false},"WORK_ON_ISSUES":{"id":"20 ","key":"WORK_ON_ISSUES","name":"Trabajar en incidencias","type":"PROJECT","description":"Capacidad para crear informes del trabajo realizado respecto a una incidencia. S├│lo es ├║til si el control del tiempo est├í habilitado.","havePermiss ion":false},"PROJECT_ADMIN":{"id":"23","key":"PROJECT_ADMIN","name":"Administrar proyectos","type":"PROJECT","descriptio n":"Capacidad para administrar un proyecto de JIRA.","havePermission":false,"deprecatedKey":true},"COMMENT_EDIT_ALL":{"i d":"34","key":"COMMENT_EDIT_ALL","name":"Editar todos los comentarios","type":"PROJECT","description":"Capacidad para ed itar todos los comentarios.","havePermission":false,"deprecatedKey":true},"ATTACHMENT_DELETE_OWN":{"id":"39","key":"ATTA CHMENT_DELETE_OWN","name":"Borrar tus adjuntos","type":"PROJECT","description":"Los usuarios con este permiso pueden bor rar sus propios adjuntos.","havePermission":false,"deprecatedKey":true},"WORKLOG_DELETE_OWN":{"id":"42","key":"WORKLOG_D ELETE_OWN","name":"Borrar tus informes de trabajo","type":"PROJECT","description":"Capacidad para borrar tus informes de trabajo.","havePermission":false,"deprecatedKey":true},"CLOSE_ISSUE":{"id":"18","key":"CLOSE_ISSUE","name":"Cerrar Inci dencias","type":"PROJECT","description":"Capacidad de cerrar incidencias. A menudo es ├║til que tus desarrolladores resu elvan incidencias y un departamento de calidad sea el encargado de realizar el cierre.","havePermission":false,"deprecat edKey":true},"MANAGE_WATCHER_LIST":{"id":"32","key":"MANAGE_WATCHER_LIST","name":"Gestionar Observadores","type":"PROJEC T","description":"Capacidad de gestionar los observadores de una incidencia.","havePermission":false,"deprecatedKey":tru e},"VIEW_VOTERS_AND_WATCHERS":{"id":"31","key":"VIEW_VOTERS_AND_WATCHERS","name":"Ver votantes y seguimientos","type":"P ROJECT","description":"Capacidad para ver a los votantes y observadores de una incidencia.","havePermission":false},"ADD COMMENTS":{"id":"15","key":"ADD_COMMENTS","name":"A├▒adir comentario","type":"PROJECT","description":"Capacidad para co mentar incidencias.","havePermission":false},"COMMENT_DELETE_ALL":{"id":"36","key":"COMMENT_DELETE_ALL","name":"Borrar t odos los comentarios","type":"PROJECT","description":"Capacidad para borrar todos los comentarios.","havePermission":fal se,"deprecatedKey":true},"CREATE_ISSUE":{"id":"11","key":"CREATE_ISSUE","name":"Crear incidencias","type":"PROJECT","des cription":"Capacidad para crear incidencias.","havePermission":false,"deprecatedKey":true},"DELETE_OWN_ATTACHMENTS":{"id ":"39","key":"DELETE_OWN_ATTACHMENTS","name":"Borrar tus adjuntos","type":"PROJECT","description":"Los usuarios con este permiso pueden borrar sus propios adjuntos.","havePermission":false},"DELETE_ALL_ATTACHMENTS":{"id":"38","key":"DELETE ALL_ATTACHMENTS","name":"Borrar todos los ficheros adjuntos","type":"PROJECT","description":"Los usuarios con este permi so pueden borrar todos los adjuntos.","havePermission":false},"ASSIGN_ISSUE":{"id":"13","key":"ASSIGN_ISSUE","name":"Asi gnar incidencias","type":"PROJECT","description":"Capacidad para asignar incidencias a otros usuarios.","havePermission" :false,"deprecatedKey":true},"LINK_ISSUE":{"id":"21","key":"LINK_ISSUE","name":"Incidencias enlazadas","type":"PROJECT", "description":"Capacidad para enlazar las incidencias entre s├¡ y crear incidencias enlazadas. S├│lo es ├║til si est├í h abilitado elazar incidencias.","havePermission":false,"deprecatedKey":true},"EDIT_OWN_WORKLOGS":{"id":"40","key":"EDIT_O WN_WORKLOGS","name":"Editar tus informes de trabajo","type":"PROJECT","description":"Capacidad para editar sus propios r egistros de trabajo.","havePermission":false},"CREATE_ATTACHMENTS":{"id":"19","key":"CREATE_ATTACHMENTS","name":"Crear a rchivos adjuntos","type":"PROJECT","description":"Usuarios con este permiso pueden crear adjuntos.","havePermission":fal se},"EDIT_ALL_WORKLOGS":{"id":"41","key":"EDIT_ALL_WORKLOGS","name":"Editar todos los informes de trabajo","type":"PROJE CT","description":"Capacidad para editar todos los registros de trabajo.","havePermission":false},"SCHEDULE_ISSUE":{"id" :"28","key":"SCHEDULE_ISSUE","name":"Programar incidencias","type":"PROJECT","description":"La capacidad de ver o editar la fecha de entrega de una incidencia.","havePermission":false,"deprecatedKey":true},"CLOSE_ISSUES":{"id":"18","key":"C LOSE_ISSUES","name":"Cerrar Incidencias","type":"PROJECT","description":"Capacidad de cerrar incidencias. A menudo es ├║ til que tus desarrolladores resuelvan incidencias y un departamento de calidad sea el encargado de realizar el cierre.", "havePermission":false},"SET_ISSUE_SECURITY":{"id":"26","key":"SET_ISSUE_SECURITY","name":"Configurar la seguridad de la incidencia","type":"PROJECT","description":"Capacidad de asignar el nivel de seguridad de una incidencia para que s├│lo la gente con ese nivel de seguridad pueda ver la incidencia.","havePermission":false},"SCHEDULE_ISSUES":{"id":"28","key ":"SCHEDULE_ISSUES","name":"Programar incidencias","type":"PROJECT","description":"La capacidad de ver o editar la fecha de entrega de una incidencia.","havePermission":false},"WORKLOG_DELETE_ALL":{"id":"43","key":"WORKLOG_DELETE_ALL","name ":"Borrar todos los informes de trabajo","type":"PROJECT","description":"Capacidad para eliminar todos las registros de trabajo.","havePermission":false,"deprecatedKey":true},"COMMENT_DELETE_OWN":{"id":"37","key":"COMMENT_DELETE_OWN","name" :"Borrar tus comentarios","type":"PROJECT","description":"Capacidad para borrar tus comentarios.","havePermission":false ,"deprecatedKey":true},"ADMINISTER_PROJECTS":{"id":"23","key":"ADMINISTER_PROJECTS","name":"Administrar proyectos","type ":"PROJECT","description":"Capacidad para administrar un proyecto de JIRA.","havePermission":false},"DELETE_ALL_COMMENTS ":{"id":"36","key":"DELETE_ALL_COMMENTS","name":"Borrar todos los comentarios","type":"PROJECT","description":"Capacidad para borrar todos los comentarios.","havePermission":false},"RESOLVE_ISSUES":{"id":"14","key":"RESOLVE_ISSUES","name":" Resolver incidencias","type":"PROJECT","description":"Capacidad para resolver y reabrir incidencias. Esto incluye la cap acidad para asignar una versi├│n como versi├│n con la soluci├│n de la incidencia.","havePermission":false},"VIEW_READONL Y_WORKFLOW":{"id":"45","key":"VIEW_READONLY_WORKFLOW","name":"Visualizar Flujo de Trabajo","type":"PROJECT","description ":"Los usuarios con este permiso pueden ver una versi├│n de s├│lo lectura del flujo de trabajo.","havePermission":false} ,"ADMINISTER":{"id":"0","key":"ADMINISTER","name":"Administradores de JIRA","type":"GLOBAL","description":"Capacidad par a realizar la mayor├¡a de las funciones de adminiastraci├│n (excepto importar y exportar, configuraci├│n de SMTP, etc.). ","havePermission":false},"MOVE_ISSUES":{"id":"25","key":"MOVE_ISSUES","name":"Mover incidencias","type":"PROJECT","desc ription":"Capacidad de mover incidencias entre proyectos o entre flujos de trabajo dentro del mismo proyecto (si procede ). Ten en cuenta que el usuario s├│lo puede mover incidencias a un proyecto en que tenga permisos de creaci├│n de incide ncias.","havePermission":false},"TRANSITION_ISSUES":{"id":"46","key":"TRANSITION_ISSUES","name":"Transici├│n de incidenc ias","type":"PROJECT","description":"Capacidad para hacer transici├│n de incidencias.","havePermission":false},"SYSTEM_A DMIN":{"id":"44","key":"SYSTEM_ADMIN","name":"Administradores del sistema JIRA","type":"GLOBAL","description":"Capacidad para realizar todas las funciones de adminiastraci├│n. Debe haber al menos un grupo con estos permisos.","havePermissio n":false},"DELETE_OWN_WORKLOGS":{"id":"42","key":"DELETE_OWN_WORKLOGS","name":"Borrar tus informes de trabajo","type":"P ROJECT","description":"Capacidad para borrar tus informes de trabajo.","havePermission":false},"BROWSE":{"id":"10","key" :"BROWSE","name":"Buscar proyectos","type":"PROJECT","description":"Capacidad para navegar por los proyectos y las incid encias de los mismos.","havePermission":false,"deprecatedKey":true},"EDIT_ISSUE":{"id":"12","key":"EDIT_ISSUE","name":"E ditar incidencias","type":"PROJECT","description":"Capacidad para editar incidencias.","havePermission":false,"deprecate dKey":true},"MODIFY_REPORTER":{"id":"30","key":"MODIFY_REPORTER","name":"Modificar Informador","type":"PROJECT","descrip tion":"Capacidad para cambiar al creador al crear o editar una incidencia.","havePermission":false},"EDIT_ISSUES":{"id": "12","key":"EDIT_ISSUES","name":"Editar incidencias","type":"PROJECT","description":"Capacidad para editar incidencias." ,"havePermission":false},"MANAGE_WATCHERS":{"id":"32","key":"MANAGE_WATCHERS","name":"Gestionar Observadores","type":"PR OJECT","description":"Capacidad de gestionar los observadores de una incidencia.","havePermission":false},"EDIT_OWN_COMM ENTS":{"id":"35","key":"EDIT_OWN_COMMENTS","name":"Editar tus comentarios","type":"PROJECT","description":"Capacidad par a editar tus comentarios.","havePermission":false},"ASSIGN_ISSUES":{"id":"13","key":"ASSIGN_ISSUES","name":"Asignar inci dencias","type":"PROJECT","description":"Capacidad para asignar incidencias a otros usuarios.","havePermission":false}," BROWSE_PROJECTS":{"id":"10","key":"BROWSE_PROJECTS","name":"Buscar proyectos","type":"PROJECT","description":"Capacidad para navegar por los proyectos y las incidencias de los mismos.","havePermission":false},"VIEW_VERSION_CONTROL":{"id":"2 9","key":"VIEW_VERSION_CONTROL","name":"Ver Herramientas de Desarrollo","type":"PROJECT","description":"Permite a los us uarios ver informaci├│n vinculada con el desarrollo, como por ejemplo commits, revisiones e informaci├│n de compilaci├│n , en la pantalla de vista de incidencias.","havePermission":false,"deprecatedKey":true},"WORK_ISSUE":{"id":"20","key":"W ORK_ISSUE","name":"Trabajar en incidencias","type":"PROJECT","description":"Capacidad para crear informes del trabajo re alizado respecto a una incidencia. S├│lo es ├║til si el control del tiempo est├í habilitado.","havePermission":false,"de precatedKey":true},"COMMENT_ISSUE":{"id":"15","key":"COMMENT_ISSUE","name":"A├▒adir comentario","type":"PROJECT","descri ption":"Capacidad para comentar incidencias.","havePermission":false,"deprecatedKey":true},"WORKLOG_EDIT_ALL":{"id":"41" ,"key":"WORKLOG_EDIT_ALL","name":"Editar todos los informes de trabajo","type":"PROJECT","description":"Capacidad para e ditar todos los registros de trabajo.","havePermission":false,"deprecatedKey":true},"EDIT_ALL_COMMENTS":{"id":"34","key" :"EDIT_ALL_COMMENTS","name":"Editar todos los comentarios","type":"PROJECT","description":"Capacidad para editar todos l os comentarios.","havePermission":false},"DELETE_ISSUE":{"id":"16","key":"DELETE_ISSUE","name":"Borrar incidencias","typ e":"PROJECT","description":"Capacidad para borrar incidencias.","havePermission":false,"deprecatedKey":true},"MANAGE_SPR INTS_PERMISSION":{"id":"-1","key":"MANAGE_SPRINTS_PERMISSION","name":"Administrar sprints","type":"PROJECT","description ":"Capacidad para administrar sprints.","havePermission":false},"USER_PICKER":{"id":"27","key":"USER_PICKER","name":"Bus car usuarios","type":"GLOBAL","description":"Capacidad de seleccionar un usuario o grupo a partir de una ventana emergen te, as├¡ como poder usar la funcionalidad 'compartir incidencias'. Los usuarios con este permiso podr├ín ver el nombre d e todos los usuarios y grupos en JIRA.","havePermission":false},"CREATE_SHARED_OBJECTS":{"id":"22","key":"CREATE_SHARED_ OBJECTS","name":"Crear filtro compartido","type":"GLOBAL","description":"Capacidad para compartir escritorios y filtros con otros usuarios, grupos y roles.","havePermission":false},"ATTACHMENT_DELETE_ALL":{"id":"38","key":"ATTACHMENT_DELETE _ALL","name":"Borrar todos los ficheros adjuntos","type":"PROJECT","description":"Los usuarios con este permiso pueden b orrar todos los adjuntos.","havePermission":false,"deprecatedKey":true},"DELETE_ISSUES":{"id":"16","key":"DELETE_ISSUES" ,"name":"Borrar incidencias","type":"PROJECT","description":"Capacidad para borrar incidencias.","havePermission":false} ,"MANAGE_GROUP_FILTER_SUBSCRIPTIONS":{"id":"24","key":"MANAGE_GROUP_FILTER_SUBSCRIPTIONS","name":"Gestionar subscripcion es a filtros de grupo","type":"GLOBAL","description":"Capacidad de gestionar (crear y borrar) suscripciones a filtros de grupo.","havePermission":false},"RESOLVE_ISSUE":{"id":"14","key":"RESOLVE_ISSUE","name":"Resolver incidencias","type":" PROJECT","description":"Capacidad para resolver y reabrir incidencias. Esto incluye la capacidad para asignar una versi├ │n como versi├│n con la soluci├│n de la incidencia.","havePermission":false,"deprecatedKey":true},"ASSIGNABLE_USER":{"id ":"17","key":"ASSIGNABLE_USER","name":"Usuario asignable","type":"PROJECT","description":"A usuarios con este permiso se les puede asignar una incidencia.","havePermission":false},"TRANSITION_ISSUE":{"id":"46","key":"TRANSITION_ISSUE","name ":"Transici├│n de incidencias","type":"PROJECT","description":"Capacidad para hacer transici├│n de incidencias.","havePe rmission":false,"deprecatedKey":true},"COMMENT_EDIT_OWN":{"id":"35","key":"COMMENT_EDIT_OWN","name":"Editar tus comentar ios","type":"PROJECT","description":"Capacidad para editar tus comentarios.","havePermission":false,"deprecatedKey":true },"MOVE_ISSUE":{"id":"25","key":"MOVE_ISSUE","name":"Mover incidencias","type":"PROJECT","description":"Capacidad de mov er incidencias entre proyectos o entre flujos de trabajo dentro del mismo proyecto (si procede). Ten en cuenta que el us uario s├│lo puede mover incidencias a un proyecto en que tenga permisos de creaci├│n de incidencias.","havePermission":f alse,"deprecatedKey":true},"WORKLOG_EDIT_OWN":{"id":"40","key":"WORKLOG_EDIT_OWN","name":"Editar tus informes de trabajo ","type":"PROJECT","description":"Capacidad para editar sus propios registros de trabajo.","havePermission":false,"depre catedKey":true},"DELETE_ALL_WORKLOGS":{"id":"43","key":"DELETE_ALL_WORKLOGS","name":"Borrar todos los informes de trabaj o","type":"PROJECT","description":"Capacidad para eliminar todos las registros de trabajo.","havePermission":false},"LIN K_ISSUES":{"id":"21","key":"LINK_ISSUES","name":"Incidencias enlazadas","type":"PROJECT","description":"Capacidad para e nlazar las incidencias entre s├¡ y crear incidencias enlazadas. S├│lo es ├║til si est├í habilitado elazar incidencias.", "havePermission":false}}}

  6. Dario B

    Hi Diego,

    The first error is returned because you forgot to put a field name (username I believe since it is starting with 'u') among quotes as the error message says: "Unexpected character ('u' (code 117)): was expecting double-quote to start field name" .

    Then, I am not sure how you got an answer to your second call since the first one should have failed....

    However, if you manage to get both REST API calls working then the problem is with the code.

  7. Dario B

    Hi Diego,

    I am not a developer and I have no knowledge of powershell.

    However:

    1) if the REST API calls are working using Curl, then check your code and the error returned.

    2) if the REST API calls are not working using Curl please paste the returned error message

    3) Please check whether you are using the email address (atlassian id) or the username to authenticate (you should now use the email address)

    4) Be aware that this is broken for many instances at the moment: https://jira.atlassian.com/browse/JRACLOUD-67169

  8. Nick Gonzalez

    I set this script up to align with my accounts setting and information. However, when I run the script I'm getting an invoke-method error. Does anyone know what might be causing this? powershell script error resized.png

    Thanks in advance

  9. Log in to comment